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

update template client entry to match remix #604

Merged
merged 2 commits into from
Mar 3, 2023
Merged
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
20 changes: 19 additions & 1 deletion templates/demo-store/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import {RemixBrowser} from '@remix-run/react';
import {startTransition, StrictMode} from 'react';
import {hydrateRoot} from 'react-dom/client';

hydrateRoot(document, <RemixBrowser />);
function hydrate() {
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>,
);
});
}

if (typeof requestIdleCallback === 'function') {
requestIdleCallback(hydrate);
} else {
// Safari doesn't support requestIdleCallback
// https://caniuse.com/requestidlecallback
setTimeout(hydrate, 1);
}
15 changes: 11 additions & 4 deletions templates/demo-store/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {EntryContext} from '@shopify/remix-oxygen';
import {RemixServer} from '@remix-run/react';
import {renderToReadableStream} from 'react-dom/server';
import isbot from 'isbot';
import {renderToReadableStream} from 'react-dom/server';

export default async function handleRequest(
request: Request,
Expand All @@ -11,16 +11,23 @@ export default async function handleRequest(
) {
const body = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
signal: request.signal,
onError(error) {
// eslint-disable-next-line no-console
console.error(error);
responseStatusCode = 500;
},
},
);

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

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

return new Response(body, {
status: responseStatusCode,
headers: responseHeaders,
status: responseStatusCode,
});
}
20 changes: 19 additions & 1 deletion templates/hello-world/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import {RemixBrowser} from '@remix-run/react';
import {startTransition, StrictMode} from 'react';
import {hydrateRoot} from 'react-dom/client';

hydrateRoot(document, <RemixBrowser />);
function hydrate() {
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>,
);
});
}

if (typeof requestIdleCallback === 'function') {
requestIdleCallback(hydrate);
} else {
// Safari doesn't support requestIdleCallback
// https://caniuse.com/requestidlecallback
setTimeout(hydrate, 1);
}
16 changes: 14 additions & 2 deletions templates/hello-world/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {EntryContext} from '@shopify/remix-oxygen';
import {RemixServer} from '@remix-run/react';
import isbot from 'isbot';
import {renderToReadableStream} from 'react-dom/server';

export default async function handleRequest(
Expand All @@ -10,12 +11,23 @@ export default async function handleRequest(
) {
const body = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
signal: request.signal,
onError(error) {
// eslint-disable-next-line no-console
console.error(error);
responseStatusCode = 500;
},
},
);

responseHeaders.set('Content-Type', 'text/html');
if (isbot(request.headers.get('user-agent'))) {
await body.allReady;
}

responseHeaders.set('Content-Type', 'text/html');
return new Response(body, {
status: responseStatusCode,
headers: responseHeaders,
status: responseStatusCode,
});
}
20 changes: 19 additions & 1 deletion templates/skeleton/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import {RemixBrowser} from '@remix-run/react';
import {startTransition, StrictMode} from 'react';
import {hydrateRoot} from 'react-dom/client';

hydrateRoot(document, <RemixBrowser />);
function hydrate() {
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>,
);
});
}

if (typeof requestIdleCallback === 'function') {
requestIdleCallback(hydrate);
} else {
// Safari doesn't support requestIdleCallback
// https://caniuse.com/requestidlecallback
setTimeout(hydrate, 1);
}
24 changes: 18 additions & 6 deletions templates/skeleton/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import type {EntryContext} from '@shopify/remix-oxygen';
import {RemixServer} from '@remix-run/react';
import {renderToString} from 'react-dom/server';
import isbot from 'isbot';
import {renderToReadableStream} from 'react-dom/server';

export default function handleRequest(
export default async function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext,
) {
const markup = renderToString(
const body = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
signal: request.signal,
onError(error) {
// eslint-disable-next-line no-console
console.error(error);
responseStatusCode = 500;
},
},
);

responseHeaders.set('Content-Type', 'text/html');
if (isbot(request.headers.get('user-agent'))) {
await body.allReady;
}

return new Response('<!DOCTYPE html>' + markup, {
status: responseStatusCode,
responseHeaders.set('Content-Type', 'text/html');
return new Response(body, {
headers: responseHeaders,
status: responseStatusCode,
});
}