Unverified Commit 236e0014 authored by Josh Story's avatar Josh Story Committed by GitHub

[dynamicIO] Update prerender to use Fizz prerender (#71580)

Previously the `prerender` function for Fizz was gated to experimental
but in our latest React sync we now have access to it in the canary
channel. This updates the prerender pathway for non-experimental react
to use `prerender` rather than `renderToReadableStream`.

`prerender` has a few benefits in that it does breadth first rendering
at Suspense boundaries so you can ensure fallback UIs are fully rendered
wherever possible if you end up abortint the render.

currently stacked on #71579
parent 3205aedf
...@@ -2028,8 +2028,8 @@ async function spawnDynamicValidationInDev( ...@@ -2028,8 +2028,8 @@ async function spawnDynamicValidationInDev(
const { ServerInsertedHTMLProvider } = createServerInsertedHTML() const { ServerInsertedHTMLProvider } = createServerInsertedHTML()
const nonce = '1' const nonce = '1'
const renderToReadableStream = require('react-dom/server.edge') const prerender = require('react-dom/static.edge')
.renderToReadableStream as (typeof import('react-dom/server.edge'))['renderToReadableStream'] .prerender as (typeof import('react-dom/static.edge'))['prerender']
let clientDynamicTracking = createDynamicTrackingState(false) let clientDynamicTracking = createDynamicTrackingState(false)
let dynamicValidation = createDynamicValidationState() let dynamicValidation = createDynamicValidationState()
...@@ -2081,29 +2081,30 @@ async function spawnDynamicValidationInDev( ...@@ -2081,29 +2081,30 @@ async function spawnDynamicValidationInDev(
let hadException = false let hadException = false
try { try {
await prerenderAndAbortInSequentialTasks( await prerenderAndAbortInSequentialTasks(
() => { async () => {
const pendingHTMLStream = workUnitAsyncStorage.run( workUnitAsyncStorage
firstAttemptClientPrerenderStore, .run(
renderToReadableStream, firstAttemptClientPrerenderStore,
<App prerender,
reactServerStream={firstAttemptReactServerStream} <App
preinitScripts={() => {}} reactServerStream={firstAttemptReactServerStream}
clientReferenceManifest={clientReferenceManifest} preinitScripts={() => {}}
ServerInsertedHTMLProvider={ServerInsertedHTMLProvider} clientReferenceManifest={clientReferenceManifest}
nonce={nonce} ServerInsertedHTMLProvider={ServerInsertedHTMLProvider}
/>, nonce={nonce}
{ />,
signal: firstAttemptClientController.signal, {
onError: SSROnError, signal: firstAttemptClientController.signal,
} onError: SSROnError,
) }
pendingHTMLStream.catch(() => {}) )
return pendingHTMLStream .catch(() => {})
return null
}, },
() => { () => {
firstAttemptClientController.abort() firstAttemptClientController.abort()
} }
) ).catch(() => {})
} catch (err: unknown) { } catch (err: unknown) {
if (firstAttemptClientController.signal.aborted) { if (firstAttemptClientController.signal.aborted) {
// We aborted the render normally and can ignore this error // We aborted the render normally and can ignore this error
...@@ -2153,7 +2154,7 @@ async function spawnDynamicValidationInDev( ...@@ -2153,7 +2154,7 @@ async function spawnDynamicValidationInDev(
workUnitAsyncStorage workUnitAsyncStorage
.run( .run(
secondAttemptClientPrerenderStore, secondAttemptClientPrerenderStore,
renderToReadableStream, prerender,
<App <App
reactServerStream={secondAttemptReactServerStream} reactServerStream={secondAttemptReactServerStream}
preinitScripts={() => {}} preinitScripts={() => {}}
...@@ -2167,6 +2168,7 @@ async function spawnDynamicValidationInDev( ...@@ -2167,6 +2168,7 @@ async function spawnDynamicValidationInDev(
} }
) )
.catch(() => {}) .catch(() => {})
return null
}, },
() => { () => {
secondAttemptClientController.abort() secondAttemptClientController.abort()
...@@ -3009,7 +3011,7 @@ async function prerenderToStream( ...@@ -3009,7 +3011,7 @@ async function prerenderToStream(
let htmlStream let htmlStream
try { try {
htmlStream = await prerenderAndAbortInSequentialTasks( htmlStream = await prerenderAndAbortInSequentialTasks(
() => { async () => {
const teedStream = ( const teedStream = (
workUnitAsyncStorage.run( workUnitAsyncStorage.run(
// The store to scope // The store to scope
...@@ -3029,11 +3031,11 @@ async function prerenderToStream( ...@@ -3029,11 +3031,11 @@ async function prerenderToStream(
reactServerStream = teedStream[0] reactServerStream = teedStream[0]
const rscForSSRStream = teedStream[1] const rscForSSRStream = teedStream[1]
const renderToReadableStream = require('react-dom/server.edge') const prerender = require('react-dom/static.edge')
.renderToReadableStream as (typeof import('react-dom/server.edge'))['renderToReadableStream'] .prerender as (typeof import('react-dom/static.edge'))['prerender']
const pendingHTMLStream = workUnitAsyncStorage.run( const { prelude } = await workUnitAsyncStorage.run(
ssrPrerenderStore, ssrPrerenderStore,
renderToReadableStream, prerender,
<App <App
reactServerStream={rscForSSRStream} reactServerStream={rscForSSRStream}
preinitScripts={preinitScripts} preinitScripts={preinitScripts}
...@@ -3051,8 +3053,7 @@ async function prerenderToStream( ...@@ -3051,8 +3053,7 @@ async function prerenderToStream(
: [bootstrapScript], : [bootstrapScript],
} }
) )
pendingHTMLStream.catch(() => {}) return prelude
return pendingHTMLStream
}, },
() => { () => {
SSRController.abort(abortReason) SSRController.abort(abortReason)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment