Skip to content

Commit

Permalink
move must have template changes to example
Browse files Browse the repository at this point in the history
  • Loading branch information
michenly committed May 28, 2024
1 parent b26dc33 commit 4051c89
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/single-fetch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
.shopify
45 changes: 45 additions & 0 deletions examples/single-fetch/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 1,45 @@
import type {EntryContext} from '@shopify/remix-oxygen';
import {RemixServer} from '@remix-run/react';
import isbot from 'isbot';
import {renderToReadableStream} from 'react-dom/server';
import {createContentSecurityPolicy} from '@shopify/hydrogen';

export default async function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext,
) {
const {nonce, header, NonceProvider} = createContentSecurityPolicy();

const body = await renderToReadableStream(
<NonceProvider>
{/***********************************************/
/********** EXAMPLE UPDATE STARTS ************/}
<RemixServer context={remixContext} url={request.url} nonce={nonce} />
{/********** EXAMPLE UPDATE END ************/
/***********************************************/}
</NonceProvider>,
{
nonce,
signal: request.signal,
onError(error) {
// eslint-disable-next-line no-console
console.error(error);
responseStatusCode = 500;
},
},
);

if (isbot(request.headers.get('user-agent'))) {
await body.allReady;
}

responseHeaders.set('Content-Type', 'text/html');
responseHeaders.set('Content-Security-Policy', header);

return new Response(body, {
headers: responseHeaders,
status: responseStatusCode,
});
}
16 changes: 16 additions & 0 deletions examples/single-fetch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 1,16 @@
{
"name": "example-single-fetch",
"private": true,
"prettier": "@shopify/prettier-config",
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
},
"dependencies": {
"@shopify/cli-hydrogen": "*"
}
}
30 changes: 30 additions & 0 deletions examples/single-fetch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 1,30 @@
{
"include": ["./**/*.d.ts", "./**/*.ts", "./**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"module": "ES2022",
"target": "ES2022",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"baseUrl": ".",
"types": [
"@shopify/oxygen-workers-types",
/***********************************************/
/********** EXAMPLE UPDATE STARTS ************/
"@remix-run/react/future/single-fetch.d.ts"
/********** EXAMPLE UPDATE END ************/
/***********************************************/
],
"paths": {
"~/*": ["app/*"]
},
"noEmit": true
}
}
46 changes: 46 additions & 0 deletions examples/single-fetch/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,46 @@
import {defineConfig} from 'vite';
import {hydrogen} from '@shopify/hydrogen/vite';
import {oxygen} from '@shopify/mini-oxygen/vite';
import {vitePlugin as remix} from '@remix-run/dev';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
plugins: [
hydrogen(),
oxygen(),
remix({
presets: [hydrogen.preset()],
future: {
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true,
/***********************************************/
/********** EXAMPLE UPDATE STARTS ************/
unstable_singleFetch: true,
/********** EXAMPLE UPDATE END ************/
/***********************************************/
},
}),
tsconfigPaths(),
],
build: {
// Allow a strict Content-Security-Policy
// withtout inlining assets as base64:
assetsInlineLimit: 0,
},
ssr: {
optimizeDeps: {
/**
* Include dependencies here if they throw CJS<>ESM errors.
* For example, for the following error:
*
* > ReferenceError: module is not defined
* > at /Users/.../node_modules/example-dep/index.js:1:1
*
* Include 'example-dep' in the array below.
* @see https://vitejs.dev/config/dep-optimization-options
*/
include: [],
},
},
});
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 41,7 @@
"examples/multipass",
"examples/optimistic-cart-ui",
"examples/partytown",
"examples/single-fetch",
"examples/subscriptions",
"examples/third-party-queries-caching",
"examples/analytics",
Expand Down
2 changes: 1 addition & 1 deletion templates/skeleton/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@ export default async function handleRequest(

const body = await renderToReadableStream(
<NonceProvider>
<RemixServer context={remixContext} url={request.url} nonce={nonce} />
<RemixServer context={remixContext} url={request.url} />
</NonceProvider>,
{
nonce,
Expand Down
5 changes: 1 addition & 4 deletions templates/skeleton/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 14,7 @@
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"baseUrl": ".",
"types": [
"@shopify/oxygen-workers-types",
"@remix-run/react/future/single-fetch.d.ts"
],
"types": ["@shopify/oxygen-workers-types"],
"paths": {
"~/*": ["app/*"]
},
Expand Down
2 changes: 0 additions & 2 deletions templates/skeleton/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,6 @@ import {defineConfig} from 'vite';
import {hydrogen} from '@shopify/hydrogen/vite';
import {oxygen} from '@shopify/mini-oxygen/vite';
import {vitePlugin as remix} from '@remix-run/dev';
import {installGlobals} from '@remix-run/node';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
Expand All @@ -15,7 14,6 @@ export default defineConfig({
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true,
unstable_singleFetch: true,
},
}),
tsconfigPaths(),
Expand Down

0 comments on commit 4051c89

Please sign in to comment.