@@ -149,11 +149,7 @@ export type RenderState = {
149
149
bootstrapChunks : Array < Chunk | PrecomputedChunk > ,
150
150
151
151
// Hoistable chunks
152
- charsetChunks : Array < Chunk | PrecomputedChunk > ,
153
- preconnectChunks : Array < Chunk | PrecomputedChunk > ,
154
152
importMapChunks : Array < Chunk | PrecomputedChunk > ,
155
- preloadChunks : Array < Chunk | PrecomputedChunk > ,
156
- hoistableChunks : Array < Chunk | PrecomputedChunk > ,
157
153
158
154
// Headers queues for Resources that can flush early
159
155
onHeaders : void | ( ( headers : HeadersDescriptor ) => void ) ,
@@ -201,9 +197,6 @@ export type RenderState = {
201
197
moduleScripts : Map < string , Resource> ,
202
198
} ,
203
199
204
- // Module-global-like reference for current boundary resources
205
- boundaryResources : ?BoundaryResources ,
206
-
207
200
// Module-global-like reference for flushing/hoisting state of style resources
208
201
// We need to track whether the current request has flushed any style resources
209
202
// without sending an instruction to hoist them. we do that here
@@ -457,6 +450,7 @@ export function createRenderState(
457
450
458
451
externalRuntimeScript : externalRuntimeScript ,
459
452
bootstrapChunks : bootstrapChunks ,
453
+ importMapChunks,
460
454
461
455
onHeaders,
462
456
headers,
@@ -472,12 +466,6 @@ export function createRenderState(
472
466
style : { } ,
473
467
} ,
474
468
475
- charsetChunks : [ ] ,
476
- preconnectChunks : [ ] ,
477
- importMapChunks,
478
- preloadChunks : [ ] ,
479
- hoistableChunks : [ ] ,
480
-
481
469
// cleared on flush
482
470
preconnects : new Set ( ) ,
483
471
fontPreloads : new Set ( ) ,
@@ -497,7 +485,6 @@ export function createRenderState(
497
485
498
486
nonce,
499
487
// like a module global for currently rendering boundary
500
- boundaryResources : null ,
501
488
stylesToHoist : false ,
502
489
} ;
503
490
@@ -2226,7 +2213,7 @@ function pushStartTextArea(
2226
2213
function pushMeta (
2227
2214
target : Array < Chunk | PrecomputedChunk > ,
2228
2215
props : Object ,
2229
- renderState : RenderState ,
2216
+ hoistableState : HoistableState ,
2230
2217
textEmbedded : boolean ,
2231
2218
insertionMode : InsertionMode ,
2232
2219
noscriptTagInScope : boolean ,
@@ -2246,12 +2233,12 @@ function pushMeta(
2246
2233
}
2247
2234
2248
2235
if ( typeof props . charSet === 'string' ) {
2249
- return pushSelfClosing ( renderState . charsetChunks , props , 'meta' ) ;
2236
+ return pushSelfClosing ( hoistableState . charset , props , 'meta' ) ;
2250
2237
} else if ( props . name === 'viewport' ) {
2251
2238
// "viewport" isn't related to preconnect but it has the right priority
2252
- return pushSelfClosing ( renderState . preconnectChunks , props , 'meta' ) ;
2239
+ return pushSelfClosing ( hoistableState . viewport , props , 'meta' ) ;
2253
2240
} else {
2254
- return pushSelfClosing ( renderState . hoistableChunks , props , 'meta' ) ;
2241
+ return pushSelfClosing ( hoistableState . chunks , props , 'meta' ) ;
2255
2242
}
2256
2243
}
2257
2244
} else {
@@ -2264,6 +2251,8 @@ function pushLink(
2264
2251
props : Object ,
2265
2252
resumableState : ResumableState ,
2266
2253
renderState : RenderState ,
2254
+ boundaryResources : null | BoundaryResources ,
2255
+ hoistableState : HoistableState ,
2267
2256
textEmbedded : boolean ,
2268
2257
insertionMode : InsertionMode ,
2269
2258
noscriptTagInScope : boolean ,
@@ -2384,8 +2373,8 @@ function pushLink(
2384
2373
// We add the newly created resource to our StyleQueue and if necessary
2385
2374
// track the resource with the currently rendering boundary
2386
2375
styleQueue . sheets . set ( key , resource ) ;
2387
- if ( renderState . boundaryResources ) {
2388
- renderState . boundaryResources . stylesheets . add ( resource ) ;
2376
+ if ( boundaryResources ) {
2377
+ boundaryResources . stylesheets . add ( resource ) ;
2389
2378
}
2390
2379
} else {
2391
2380
// We need to track whether this boundary should wait on this resource or not.
@@ -2396,8 +2385,8 @@ function pushLink(
2396
2385
if ( styleQueue ) {
2397
2386
const resource = styleQueue . sheets . get ( key ) ;
2398
2387
if ( resource ) {
2399
- if ( renderState . boundaryResources ) {
2400
- renderState . boundaryResources . stylesheets . add ( resource ) ;
2388
+ if ( boundaryResources ) {
2389
+ boundaryResources . stylesheets . add ( resource ) ;
2401
2390
}
2402
2391
}
2403
2392
}
@@ -2422,15 +2411,7 @@ function pushLink(
2422
2411
target . push ( textSeparator ) ;
2423
2412
}
2424
2413
2425
- switch ( props . rel ) {
2426
- case 'preconnect ':
2427
- case 'dns - prefetch ':
2428
- return pushLinkImpl ( renderState . preconnectChunks , props ) ;
2429
- case 'preload ':
2430
- return pushLinkImpl ( renderState . preloadChunks , props ) ;
2431
- default :
2432
- return pushLinkImpl ( renderState . hoistableChunks , props ) ;
2433
- }
2414
+ return pushLinkImpl ( hoistableState . chunks , props ) ;
2434
2415
}
2435
2416
} else {
2436
2417
return pushLinkImpl ( target , props ) ;
@@ -2472,6 +2453,7 @@ function pushStyle(
2472
2453
props : Object ,
2473
2454
resumableState : ResumableState ,
2474
2455
renderState : RenderState ,
2456
+ boundaryResources : null | BoundaryResources ,
2475
2457
textEmbedded : boolean ,
2476
2458
insertionMode : InsertionMode ,
2477
2459
noscriptTagInScope : boolean ,
@@ -2571,8 +2553,8 @@ function pushStyle(
2571
2553
// it. However, it's possible when you resume that the style has already been emitted
2572
2554
// and then it wouldn't be recreated in the RenderState and there's no need to track
2573
2555
// it again since we should've hoisted it to the shell already.
2574
- if ( renderState . boundaryResources ) {
2575
- renderState . boundaryResources . styles . add ( styleQueue ) ;
2556
+ if ( boundaryResources ) {
2557
+ boundaryResources . styles . add ( styleQueue ) ;
2576
2558
}
2577
2559
}
2578
2560
@@ -2882,7 +2864,7 @@ function pushStartMenuItem(
2882
2864
function pushTitle (
2883
2865
target : Array < Chunk | PrecomputedChunk > ,
2884
2866
props : Object ,
2885
- renderState : RenderState ,
2867
+ hoistableState : HoistableState ,
2886
2868
insertionMode : InsertionMode ,
2887
2869
noscriptTagInScope : boolean ,
2888
2870
) : ReactNodeList {
@@ -2940,7 +2922,7 @@ function pushTitle(
2940
2922
! noscriptTagInScope &&
2941
2923
props . itemProp == null
2942
2924
) {
2943
- pushTitleImpl ( renderState . hoistableChunks , props ) ;
2925
+ pushTitleImpl ( hoistableState . chunks , props ) ;
2944
2926
return null ;
2945
2927
} else {
2946
2928
return pushTitleImpl ( target , props ) ;
@@ -3472,6 +3454,8 @@ export function pushStartInstance(
3472
3454
props : Object ,
3473
3455
resumableState : ResumableState ,
3474
3456
renderState : RenderState ,
3457
+ boundaryResources : null | BoundaryResources ,
3458
+ hoistableState : HoistableState ,
3475
3459
formatContext : FormatContext ,
3476
3460
textEmbedded : boolean ,
3477
3461
) : ReactNodeList {
@@ -3539,7 +3523,7 @@ export function pushStartInstance(
3539
3523
? pushTitle (
3540
3524
target ,
3541
3525
props ,
3542
- renderState ,
3526
+ hoistableState ,
3543
3527
formatContext . insertionMode ,
3544
3528
! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
3545
3529
)
@@ -3550,6 +3534,8 @@ export function pushStartInstance(
3550
3534
props ,
3551
3535
resumableState ,
3552
3536
renderState ,
3537
+ boundaryResources ,
3538
+ hoistableState ,
3553
3539
textEmbedded ,
3554
3540
formatContext . insertionMode ,
3555
3541
! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
@@ -3572,6 +3558,7 @@ export function pushStartInstance(
3572
3558
props ,
3573
3559
resumableState ,
3574
3560
renderState ,
3561
+ boundaryResources ,
3575
3562
textEmbedded ,
3576
3563
formatContext . insertionMode ,
3577
3564
! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
@@ -3580,7 +3567,7 @@ export function pushStartInstance(
3580
3567
return pushMeta (
3581
3568
target ,
3582
3569
props ,
3583
- renderState ,
3570
+ hoistableState ,
3584
3571
textEmbedded ,
3585
3572
formatContext . insertionMode ,
3586
3573
! ! ( formatContext . tagScope & NOSCRIPT_SCOPE ) ,
@@ -4574,6 +4561,7 @@ export function writePreamble(
4574
4561
destination : Destination ,
4575
4562
resumableState : ResumableState ,
4576
4563
renderState : RenderState ,
4564
+ hoistableState : HoistableState ,
4577
4565
willFlushAllSegments : boolean ,
4578
4566
) : void {
4579
4567
// This function must be called exactly once on every request
@@ -4619,7 +4607,7 @@ export function writePreamble(
4619
4607
}
4620
4608
4621
4609
// Emit high priority Hoistables
4622
- const charsetChunks = renderState . charsetChunks ;
4610
+ const charsetChunks = hoistableState . charset ;
4623
4611
for ( i = 0 ; i < charsetChunks . length ; i ++ ) {
4624
4612
writeChunk ( destination , charsetChunks [ i ] ) ;
4625
4613
}
@@ -4629,11 +4617,11 @@ export function writePreamble(
4629
4617
renderState . preconnects . forEach ( flushResource , destination ) ;
4630
4618
renderState . preconnects . clear ( ) ;
4631
4619
4632
- const preconnectChunks = renderState . preconnectChunks ;
4633
- for ( i = 0 ; i < preconnectChunks . length ; i ++ ) {
4634
- writeChunk ( destination , preconnectChunks [ i ] ) ;
4620
+ const viewportChunks = hoistableState . viewport ;
4621
+ for ( i = 0 ; i < viewportChunks . length ; i ++ ) {
4622
+ writeChunk ( destination , viewportChunks [ i ] ) ;
4635
4623
}
4636
- preconnectChunks . length = 0 ;
4624
+ viewportChunks . length = 0 ;
4637
4625
4638
4626
renderState . fontPreloads . forEach ( flushResource , destination ) ;
4639
4627
renderState . fontPreloads . clear ( ) ;
@@ -4658,15 +4646,8 @@ export function writePreamble(
4658
4646
renderState . bulkPreloads . forEach ( flushResource , destination ) ;
4659
4647
renderState . bulkPreloads . clear ( ) ;
4660
4648
4661
- // Write embedding preloadChunks
4662
- const preloadChunks = renderState . preloadChunks ;
4663
- for ( i = 0 ; i < preloadChunks . length ; i ++ ) {
4664
- writeChunk ( destination , preloadChunks [ i ] ) ;
4665
- }
4666
- preloadChunks . length = 0 ;
4667
-
4668
- // Write embedding hoistableChunks
4669
- const hoistableChunks = renderState . hoistableChunks ;
4649
+ // Write hoistableState chunks
4650
+ const hoistableChunks = hoistableState . chunks ;
4670
4651
for ( i = 0 ; i < hoistableChunks . length ; i ++ ) {
4671
4652
writeChunk ( destination , hoistableChunks [ i ] ) ;
4672
4653
}
@@ -4691,6 +4672,7 @@ export function writeHoistables(
4691
4672
destination : Destination ,
4692
4673
resumableState : ResumableState ,
4693
4674
renderState : RenderState ,
4675
+ hoistableState : HoistableState ,
4694
4676
) : void {
4695
4677
let i = 0 ;
4696
4678
@@ -4702,12 +4684,6 @@ export function writeHoistables(
4702
4684
renderState . preconnects . forEach ( flushResource , destination ) ;
4703
4685
renderState . preconnects . clear ( ) ;
4704
4686
4705
- const preconnectChunks = renderState . preconnectChunks ;
4706
- for ( i = 0 ; i < preconnectChunks . length ; i ++ ) {
4707
- writeChunk ( destination , preconnectChunks [ i ] ) ;
4708
- }
4709
- preconnectChunks . length = 0 ;
4710
-
4711
4687
renderState . fontPreloads . forEach ( flushResource , destination ) ;
4712
4688
renderState . fontPreloads . clear ( ) ;
4713
4689
@@ -4732,15 +4708,8 @@ export function writeHoistables(
4732
4708
renderState . bulkPreloads . forEach ( flushResource , destination ) ;
4733
4709
renderState . bulkPreloads . clear ( ) ;
4734
4710
4735
- // Write embedding preloadChunks
4736
- const preloadChunks = renderState . preloadChunks ;
4737
- for ( i = 0 ; i < preloadChunks . length ; i ++ ) {
4738
- writeChunk ( destination , preloadChunks [ i ] ) ;
4739
- }
4740
- preloadChunks . length = 0 ;
4741
-
4742
- // Write embedding hoistableChunks
4743
- const hoistableChunks = renderState . hoistableChunks ;
4711
+ // Write hoistableState chunks
4712
+ const hoistableChunks = hoistableState . chunks ;
4744
4713
for ( i = 0 ; i < hoistableChunks . length ; i ++ ) {
4745
4714
writeChunk ( destination , hoistableChunks [ i ] ) ;
4746
4715
}
@@ -5214,7 +5183,22 @@ type StylesheetResource = {
5214
5183
state : StylesheetState ,
5215
5184
} ;
5216
5185
5186
+ export type HoistableState = {
5187
+ charset : Array < Chunk | PrecomputedChunk > ,
5188
+ viewport : Array < Chunk | PrecomputedChunk > ,
5189
+ chunks : Array < Chunk | PrecomputedChunk > ,
5190
+ } ;
5191
+
5192
+ export function createHoistableState ( ) : HoistableState {
5193
+ return {
5194
+ charset : [ ] ,
5195
+ viewport : [ ] ,
5196
+ chunks : [ ] ,
5197
+ } ;
5198
+ }
5199
+
5217
5200
export type BoundaryResources = {
5201
+ // style dependencies
5218
5202
styles : Set < StyleQueue > ,
5219
5203
stylesheets : Set < StylesheetResource > ,
5220
5204
} ;
@@ -5233,13 +5217,6 @@ export function createBoundaryResources(): BoundaryResources {
5233
5217
} ;
5234
5218
}
5235
5219
5236
- export function setCurrentlyRenderingBoundaryResourcesTarget (
5237
- renderState : RenderState ,
5238
- boundaryResources : null | BoundaryResources ,
5239
- ) {
5240
- renderState . boundaryResources = boundaryResources ;
5241
- }
5242
-
5243
5220
function getResourceKey ( href : string ) : string {
5244
5221
return href ;
5245
5222
}
@@ -6086,6 +6063,15 @@ function escapeStringForLinkHeaderQuotedParamValueContextReplacer(
6086
6063
}
6087
6064
}
6088
6065
6066
+ export function hoistHoistables (
6067
+ target : HoistableState ,
6068
+ source : HoistableState ,
6069
+ ) {
6070
+ target . charset . push ( ...source . charset ) ;
6071
+ target . viewport . push ( ...source . viewport ) ;
6072
+ target . chunks . push ( ...source . chunks ) ;
6073
+ }
6074
+
6089
6075
function hoistStyleQueueDependency (
6090
6076
this : BoundaryResources ,
6091
6077
styleQueue : StyleQueue ,
@@ -6100,18 +6086,12 @@ function hoistStylesheetDependency(
6100
6086
this . stylesheets . add ( stylesheet ) ;
6101
6087
}
6102
6088
6103
- export function hoistResources (
6104
- renderState : RenderState ,
6089
+ export function hoistBoundaryResources (
6090
+ target : BoundaryResources ,
6105
6091
source : BoundaryResources ,
6106
6092
) : void {
6107
- const currentBoundaryResources = renderState . boundaryResources ;
6108
- if ( currentBoundaryResources ) {
6109
- source . styles . forEach ( hoistStyleQueueDependency , currentBoundaryResources ) ;
6110
- source . stylesheets . forEach (
6111
- hoistStylesheetDependency ,
6112
- currentBoundaryResources ,
6113
- ) ;
6114
- }
6093
+ source . styles . forEach ( hoistStyleQueueDependency , target ) ;
6094
+ source . stylesheets . forEach ( hoistStylesheetDependency , target ) ;
6115
6095
}
6116
6096
6117
6097
// This function is called at various times depending on whether we are rendering
0 commit comments