@@ -245,6 +245,13 @@ export type ResumableState = {
245245 nextFormID : number ,
246246 streamingFormat : StreamingFormat ,
247247
248+ // We carry the bootstrap intializers in resumable state in case we postpone in the shell
249+ // of a prerender. On resume we will reinitialize the bootstrap scripts if necessary.
250+ // If we end up flushing the bootstrap scripts we void these on the resumable state
251+ bootstrapScriptContent ?: string | void ,
252+ bootstrapScripts ?: $ReadOnlyArray < string | BootstrapScriptDescriptor > | void ,
253+ bootstrapModules ?: $ReadOnlyArray < string | BootstrapScriptDescriptor > | void ,
254+
248255 // state for script streaming format, unused if using external runtime / data
249256 instructions : InstructionState ,
250257
@@ -349,9 +356,6 @@ const DEFAULT_HEADERS_CAPACITY_IN_UTF16_CODE_UNITS = 2000;
349356export function createRenderState (
350357 resumableState : ResumableState ,
351358 nonce : string | void ,
352- bootstrapScriptContent : string | void ,
353- bootstrapScripts : $ReadOnlyArray < string | BootstrapScriptDescriptor > | void ,
354- bootstrapModules : $ReadOnlyArray < string | BootstrapScriptDescriptor > | void ,
355359 externalRuntimeConfig : string | BootstrapScriptDescriptor | void ,
356360 importMap : ImportMap | void ,
357361 onHeaders : void | ( ( headers : HeadersDescriptor ) => void ) ,
@@ -367,6 +371,8 @@ export function createRenderState(
367371
368372 const bootstrapChunks : Array < Chunk | PrecomputedChunk > = [ ] ;
369373 let externalRuntimeScript : null | ExternalRuntimeScript = null ;
374+ const { bootstrapScriptContent , bootstrapScripts, bootstrapModules} =
375+ resumableState ;
370376 if ( bootstrapScriptContent !== undefined ) {
371377 bootstrapChunks . push (
372378 inlineScriptWithNonce ,
@@ -612,9 +618,6 @@ export function resumeRenderState(
612618 return createRenderState (
613619 resumableState ,
614620 nonce ,
615- // These should have already been flushed in the prerender.
616- undefined ,
617- undefined ,
618621 undefined ,
619622 undefined ,
620623 undefined ,
@@ -625,6 +628,9 @@ export function resumeRenderState(
625628export function createResumableState (
626629 identifierPrefix : string | void ,
627630 externalRuntimeConfig : string | BootstrapScriptDescriptor | void ,
631+ bootstrapScriptContent : string | void ,
632+ bootstrapScripts : $ReadOnlyArray < string | BootstrapScriptDescriptor > | void ,
633+ bootstrapModules : $ReadOnlyArray < string | BootstrapScriptDescriptor > | void ,
628634) : ResumableState {
629635 const idPrefix = identifierPrefix === undefined ? '' : identifierPrefix ;
630636
@@ -638,6 +644,9 @@ export function createResumableState(
638644 idPrefix : idPrefix ,
639645 nextFormID : 0 ,
640646 streamingFormat,
647+ bootstrapScriptContent,
648+ bootstrapScripts,
649+ bootstrapModules,
641650 instructions : NothingSent ,
642651 hasBody : false ,
643652 hasHtml : false ,
@@ -3714,7 +3723,11 @@ export function pushEndInstance(
37143723function writeBootstrap (
37153724 destination : Destination ,
37163725 renderState : RenderState ,
3726+ resumableState : ResumableState ,
37173727) : boolean {
3728+ resumableState . bootstrapScriptContent = undefined ;
3729+ resumableState . bootstrapScripts = undefined ;
3730+ resumableState . bootstrapModules = undefined ;
37183731 const bootstrapChunks = renderState . bootstrapChunks ;
37193732 let i = 0 ;
37203733 for ( ; i < bootstrapChunks . length - 1 ; i ++ ) {
@@ -3731,8 +3744,9 @@ function writeBootstrap(
37313744export function writeCompletedRoot (
37323745 destination : Destination ,
37333746 renderState : RenderState ,
3747+ resumableState : ResumableState ,
37343748) : boolean {
3735- return writeBootstrap ( destination , renderState ) ;
3749+ return writeBootstrap ( destination , renderState , resumableState ) ;
37363750}
37373751
37383752// Structural Nodes
@@ -4197,7 +4211,7 @@ export function writeCompletedBoundaryInstruction(
41974211 } else {
41984212 writeMore = writeChunkAndReturn ( destination , completeBoundaryDataEnd ) ;
41994213 }
4200- return writeBootstrap ( destination , renderState ) && writeMore ;
4214+ return writeBootstrap ( destination , renderState , resumableState ) && writeMore ;
42014215}
42024216
42034217const clientRenderScript1Full = stringToPrecomputedChunk (
0 commit comments