-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update template client entry to match remix (#604)
* update template client entry to match remix * update entry.server.tsx based on new remix template
- Loading branch information
1 parent
4443a2b
commit 4514286
Showing
6 changed files
with
100 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |