Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #2678

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Test #2678

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/gtm/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export default async function handleRequest(
scriptSrc: [
"'self'",
'https://cdn.shopify.com',
'https://*.googletagmanager.com'
'https://*.googletagmanager.com',
],
imgSrc: [
"'self'",
'https://cdn.shopify.com',
'https://*.google-analytics.com',
'https://*.googletagmanager.com'
'https://*.googletagmanager.com',
],
connectSrc: [
"'self'",
Expand All @@ -32,7 +32,7 @@ export default async function handleRequest(
shop: {
checkoutDomain: context.env.PUBLIC_CHECKOUT_DOMAIN,
storeDomain: context.env.PUBLIC_STORE_DOMAIN,
}
},
});

const body = await renderToReadableStream(
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

24 changes: 23 additions & 1 deletion templates/skeleton/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,36 @@ export default async function handleRequest(
},
);

const [reader, reader2] = body.tee();

const stream = reader2.getReader();

// read() returns a promise that resolves when a value has been received
stream
.read()
.then(function pump({done, value}: {done: boolean; value: Uint8Array}) {
if (done) {
// Do something with last chunk of data then exit reader
return;
}
// Otherwise do something here to process current chunk

console.log(new TextDecoder().decode(value));

// Read some more, and call this function again
return reader.read().then(pump);
});

console.log('here a');
if (isbot(request.headers.get('user-agent'))) {
console.log('here b');
await body.allReady;
}

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

return new Response(body, {
return new Response(reader, {
headers: responseHeaders,
status: responseStatusCode,
});
Expand Down
63 changes: 25 additions & 38 deletions templates/skeleton/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,30 @@ export function links() {
];
}

export async function loader(args: LoaderFunctionArgs) {
// Start fetching non-critical data without blocking time to first byte
const deferredData = loadDeferredData(args);

// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);

const {storefront, env} = args.context;

return defer({
...deferredData,
...criticalData,
publicStoreDomain: env.PUBLIC_STORE_DOMAIN,
shop: getShopAnalytics({
storefront,
publicStorefrontId: env.PUBLIC_STOREFRONT_ID,
}),
consent: {
checkoutDomain: env.PUBLIC_CHECKOUT_DOMAIN,
storefrontAccessToken: env.PUBLIC_STOREFRONT_API_TOKEN,
withPrivacyBanner: false,
// localize the privacy banner
country: args.context.storefront.i18n.country,
language: args.context.storefront.i18n.language,
},
});
}
// export async function loader(args: LoaderFunctionArgs) {
// Start fetching non-critical data without blocking time to first byte
// const deferredData = loadDeferredData(args);
// // Await the critical data required to render initial state of the page
// const criticalData = await loadCriticalData(args);
// const {storefront, env} = args.context;
// return defer({
// ...deferredData,
// ...criticalData,
// publicStoreDomain: env.PUBLIC_STORE_DOMAIN,
// shop: getShopAnalytics({
// storefront,
// publicStorefrontId: env.PUBLIC_STOREFRONT_ID,
// }),
// consent: {
// checkoutDomain: env.PUBLIC_CHECKOUT_DOMAIN,
// storefrontAccessToken: env.PUBLIC_STOREFRONT_API_TOKEN,
// withPrivacyBanner: false,
// // localize the privacy banner
// country: args.context.storefront.i18n.country,
// language: args.context.storefront.i18n.language,
// },
// });
// }

/**
* Load data necessary for rendering content above the fold. This is the critical data
Expand Down Expand Up @@ -142,17 +139,7 @@ export function Layout({children}: {children?: React.ReactNode}) {
<Links />
</head>
<body>
{data ? (
<Analytics.Provider
cart={data.cart}
shop={data.shop}
consent={data.consent}
>
<PageLayout {...data}>{children}</PageLayout>
</Analytics.Provider>
) : (
children
)}
{children}
<ScrollRestoration nonce={nonce} />
<Scripts nonce={nonce} />
</body>
Expand Down
19 changes: 19 additions & 0 deletions templates/skeleton/app/routes/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Await, useLoaderData} from '@remix-run/react';
import {defer} from '@remix-run/server-runtime';
import {Suspense} from 'react';

export async function loader() {
return defer({
promise: new Promise((resolve) => setTimeout(() => resolve('stuff'), 5000)),
});
}
export default function Test() {
const {promise} = useLoaderData<typeof loader>();
promise.then(() => console.log('hi'));

return (
<Suspense fallback={<div>Loading...</div>}>
<Await resolve={promise}>{() => <div>Test</div>}</Await>
</Suspense>
);
}
Loading