-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
70 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const LazyLoaded = () => ( | ||
<span>I have been lazily loaded using Streaming SSR!</span> | ||
); | ||
|
||
export default LazyLoaded; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Components | ||
|
||
You can place your own components in this folder or just delete it. It only exists for demonstrating purposes only. |
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,4 @@ | ||
import { hydrate } from 'react-dom'; | ||
import { hydrateRoot } from 'react-dom/client'; | ||
import { RemixBrowser } from '@remix-run/react'; | ||
|
||
hydrate(<RemixBrowser />, document); | ||
hydrateRoot(document, <RemixBrowser />); |
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,42 @@ | ||
import { renderToString } from 'react-dom/server'; | ||
import { renderToReadableStream } from 'react-dom/server'; | ||
import type { EntryContext } from '@remix-run/cloudflare'; | ||
import { RemixServer } from '@remix-run/react'; | ||
import isbot from 'isbot'; | ||
|
||
export default function handleRequest( | ||
export default async function handleRequest( | ||
request: Request, | ||
responseStatusCode: number, | ||
responseHeaders: Headers, | ||
remixContext: EntryContext | ||
) { | ||
const markup = renderToString( | ||
<RemixServer context={remixContext} url={request.url} /> | ||
); | ||
const controller = new AbortController(); | ||
|
||
responseHeaders.set('Content-Type', 'text/html'); | ||
try { | ||
const stream = await renderToReadableStream( | ||
<RemixServer context={remixContext} url={request.url} />, | ||
{ | ||
signal: controller.signal, | ||
onError: error => { | ||
responseStatusCode = 500; | ||
console.error(error); | ||
}, | ||
} | ||
); | ||
|
||
return new Response('<!DOCTYPE html>' + markup, { | ||
status: responseStatusCode, | ||
headers: responseHeaders, | ||
}); | ||
if (isbot(request.headers.get('user-agent'))) { | ||
await stream.allReady; | ||
} | ||
|
||
responseHeaders.set('Content-Type', 'text/html'); | ||
|
||
return new Response(stream, { | ||
status: responseStatusCode, | ||
headers: responseHeaders, | ||
}); | ||
} catch (e) { | ||
return new Response('<!doctype html><p>Loading...</p>', { | ||
status: 500, | ||
headers: { 'Content-Type': 'text/html' }, | ||
}); | ||
} | ||
} |
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
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