@@ -255,8 +255,7 @@ type SuspenseBoundary = {
255255fallbackAbortableTasks : Set < Task > , // used to cancel task on the fallback if the boundary completes or gets canceled.
256256contentState : HoistableState ,
257257fallbackState : HoistableState ,
258- contentPreamble : null | Preamble ,
259- fallbackPreamble : null | Preamble ,
258+ preamble : null | Preamble ,
260259tracked : null | {
261260contentKeyPath : null | KeyNode , // used to track the path for replay nodes
262261fallbackNode : null | ReplayNode , // used to track the fallback for replay nodes
@@ -275,7 +274,7 @@ type RenderTask = {
275274ping : ( ) => void ,
276275blockedBoundary : Root | SuspenseBoundary ,
277276blockedSegment : Segment , // the segment we'll write to
278- blockedPreamble : null | Preamble ,
277+ blockedPreamble : null | PreambleState ,
279278hoistableState : null | HoistableState , // Boundary state we'll mutate while rendering. This may not equal the state of the blockedBoundary
280279abortSet : Set < Task > , // the abortable set that this task belongs to
281280keyPath : Root | KeyNode , // the path of all parent keys currently rendering
@@ -398,7 +397,17 @@ export opaque type Request = {
398397didWarnForKey ?: null | WeakSet < ComponentStackNode > ,
399398} ;
400399
401- type Preamble = PreambleState ;
400+ type Preamble = {
401+ content : PreambleState ,
402+ fallback : PreambleState ,
403+ } ;
404+
405+ function createPreamble ( ) : Preamble {
406+ return {
407+ content : createPreambleState ( ) ,
408+ fallback : createPreambleState ( ) ,
409+ } ;
410+ }
402411
403412// This is a default heuristic for how to split up the HTML content into progressive
404413// loading. Our goal is to be able to display additional new content about every 500ms.
@@ -466,7 +475,7 @@ function isEligibleForOutlining(
466475// For boundaries that can possibly contribute to the preamble we don't want to outline
467476// them regardless of their size since the fallbacks should only be emitted if we've
468477// errored the boundary.
469- boundary . contentPreamble === null
478+ boundary . preamble === null
470479) ;
471480}
472481
@@ -786,8 +795,7 @@ function createSuspenseBoundary(
786795request : Request ,
787796row : null | SuspenseListRow ,
788797fallbackAbortableTasks : Set < Task > ,
789- contentPreamble: null | Preamble,
790- fallbackPreamble: null | Preamble,
798+ preamble: null | Preamble,
791799 defer: boolean,
792800): SuspenseBoundary {
793801const boundary : SuspenseBoundary = {
@@ -803,8 +811,7 @@ function createSuspenseBoundary(
803811errorDigest : null ,
804812contentState : createHoistableState ( ) ,
805813fallbackState : createHoistableState ( ) ,
806- contentPreamble,
807- fallbackPreamble,
814+ preamble,
808815tracked : null ,
809816} ;
810817if ( __DEV__ ) {
@@ -838,7 +845,7 @@ function createRenderTask(
838845childIndex : number ,
839846blockedBoundary : Root | SuspenseBoundary ,
840847blockedSegment : Segment ,
841- blockedPreamble : null | Preamble ,
848+ blockedPreamble : null | PreambleState ,
842849hoistableState : null | HoistableState ,
843850abortSet : Set < Task > ,
844851 keyPath: Root | KeyNode,
@@ -1290,8 +1297,7 @@ function renderSuspenseBoundary(
12901297request ,
12911298task . row ,
12921299fallbackAbortSet ,
1293- createPreambleState ( ) ,
1294- createPreambleState ( ) ,
1300+ createPreamble ( ) ,
12951301defer ,
12961302) ;
12971303} else {
@@ -1300,7 +1306,6 @@ function renderSuspenseBoundary(
13001306task . row ,
13011307fallbackAbortSet ,
13021308null ,
1303- null ,
13041309defer ,
13051310) ;
13061311}
@@ -1365,7 +1370,8 @@ function renderSuspenseBoundary(
13651370}
13661371
13671372task . blockedSegment = boundarySegment ;
1368- task . blockedPreamble = newBoundary . fallbackPreamble ;
1373+ task . blockedPreamble =
1374+ newBoundary . preamble === null ? null : newBoundary . preamble . fallback ;
13691375task . keyPath = fallbackKeyPath ;
13701376task . formatContext = getSuspenseFallbackFormatContext (
13711377request . resumableState ,
@@ -1409,7 +1415,7 @@ function renderSuspenseBoundary(
14091415- 1 ,
14101416newBoundary ,
14111417contentRootSegment ,
1412- newBoundary . contentPreamble ,
1418+ newBoundary . preamble === null ? null : newBoundary . preamble . content ,
14131419newBoundary . contentState ,
14141420task . abortSet ,
14151421keyPath ,
@@ -1440,7 +1446,8 @@ function renderSuspenseBoundary(
14401446// context switching. We just need to temporarily switch which boundary and which segment
14411447// we're writing to. If something suspends, it'll spawn new suspended task with that context.
14421448task . blockedBoundary = newBoundary ;
1443- task . blockedPreamble = newBoundary . contentPreamble ;
1449+ task . blockedPreamble =
1450+ newBoundary . preamble === null ? null : newBoundary . preamble . content ;
14441451task . hoistableState = newBoundary . contentState ;
14451452task . blockedSegment = contentRootSegment ;
14461453task . keyPath = keyPath ;
@@ -1548,7 +1555,7 @@ function renderSuspenseBoundary(
15481555- 1 ,
15491556parentBoundary ,
15501557boundarySegment ,
1551- newBoundary . fallbackPreamble ,
1558+ newBoundary . preamble === null ? null : newBoundary . preamble . fallback ,
15521559newBoundary . fallbackState ,
15531560fallbackAbortSet ,
15541561fallbackKeyPath ,
@@ -1602,8 +1609,7 @@ function replaySuspenseBoundary(
16021609request ,
16031610task . row ,
16041611fallbackAbortSet ,
1605- createPreambleState ( ) ,
1606- createPreambleState ( ) ,
1612+ createPreamble ( ) ,
16071613defer ,
16081614) ;
16091615} else {
@@ -1612,7 +1618,6 @@ function replaySuspenseBoundary(
16121618task . row ,
16131619fallbackAbortSet ,
16141620null ,
1615- null ,
16161621defer ,
16171622) ;
16181623}
@@ -4372,7 +4377,7 @@ function erroredTask(
43724377if (
43734378request . pendingRootTasks === 0 &&
43744379request . trackedPostpones === null &&
4375- boundary . contentPreamble !== null
4380+ boundary . preamble !== null
43764381) {
43774382// The root is complete and this boundary may contribute part of the preamble.
43784383// We eagerly attempt to prepare the preamble here because we expect most requests
@@ -4414,7 +4419,6 @@ function abortRemainingSuspenseBoundary(
44144419null ,
44154420new Set ( ) ,
44164421null ,
4417- null ,
44184422false ,
44194423) ;
44204424resumedBoundary . parentFlushed = true ;
@@ -4894,7 +4898,7 @@ function finishedTask(
48944898if (
48954899request . pendingRootTasks === 0 &&
48964900request . trackedPostpones === null &&
4897- boundary . contentPreamble !== null
4901+ boundary . preamble !== null
48984902) {
48994903// The root is complete and this boundary may contribute part of the preamble.
49004904// We eagerly attempt to prepare the preamble here because we expect most requests
@@ -5271,10 +5275,8 @@ function preparePreambleFromSegment(
52715275) ;
52725276}
52735277
5274- const preamble = boundary . contentPreamble ;
5275- const fallbackPreamble = boundary . fallbackPreamble ;
5276-
5277- if ( preamble === null || fallbackPreamble === null ) {
5278+ const preamble = boundary . preamble ;
5279+ if ( preamble === null ) {
52785280// This boundary cannot have a preamble so it can't block the flushing of
52795281// the preamble.
52805282 return false ;
@@ -5286,7 +5288,7 @@ function preparePreambleFromSegment(
52865288case COMPLETED : {
52875289// This boundary is complete. It might have inner boundaries which are pending
52885290// and able to provide a preamble so we have to check it's children
5289- hoistPreambleState ( request . renderState , preamble ) ;
5291+ hoistPreambleState ( request . renderState , preamble . content ) ;
52905292// We track this boundary's byteSize on the request since it will always flush with
52915293// the request since it may contribute to the preamble
52925294 request. byteSize += boundary . byteSize ;
@@ -5315,7 +5317,7 @@ function preparePreambleFromSegment(
53155317case CLIENT_RENDERED : {
53165318if ( segment . status === COMPLETED ) {
53175319// This boundary is errored so if it contains a preamble we should include it
5318- hoistPreambleState ( request . renderState , fallbackPreamble ) ;
5320+ hoistPreambleState ( request . renderState , preamble . fallback ) ;
53195321return preparePreambleFromSubtree (
53205322request ,
53215323segment ,
0 commit comments