-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: updated demo site to renderReadableStream
- Loading branch information
1 parent
008f627
commit 1c36659
Showing
3 changed files
with
32 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,19 +1,28 @@ | ||
import type { EntryContext } from '@remix-run/node' | ||
import type { EntryContext } from '@remix-run/server-runtime' | ||
import { RemixServer } from '@remix-run/react' | ||
import { renderToString } from 'react-dom/server' | ||
import { renderToReadableStream } from 'react-dom/server' | ||
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 body = await renderToReadableStream(<RemixServer context={remixContext} url={request.url} />, { | ||
onError() { | ||
responseStatusCode = 500 | ||
}, | ||
}) | ||
|
||
if (isbot(request.headers.get('user-agent'))) { | ||
await body.allReady | ||
} | ||
|
||
responseHeaders.set('Content-Type', 'text/html') | ||
|
||
return new Response('<!DOCTYPE html>' + markup, { | ||
headers: responseHeaders, | ||
return new Response(body, { | ||
status: responseStatusCode, | ||
headers: responseHeaders, | ||
}) | ||
} |