@@ -3774,6 +3774,49 @@ function renderChildrenArray(
37743774 }
37753775}
37763776
3777+ function trackPostponedBoundary (
3778+ request : Request ,
3779+ trackedPostpones : PostponedHoles ,
3780+ boundary : SuspenseBoundary ,
3781+ ) : ReplaySuspenseBoundary {
3782+ boundary . status = POSTPONED ;
3783+ // We need to eagerly assign it an ID because we'll need to refer to
3784+ // it before flushing and we know that we can't inline it.
3785+ boundary . rootSegmentID = request . nextSegmentId ++ ;
3786+
3787+ const boundaryKeyPath = boundary . trackedContentKeyPath ;
3788+ if ( boundaryKeyPath === null ) {
3789+ throw new Error (
3790+ 'It should not be possible to postpone at the root. This is a bug in React.' ,
3791+ ) ;
3792+ }
3793+
3794+ const fallbackReplayNode = boundary . trackedFallbackNode ;
3795+
3796+ const children : Array < ReplayNode > = [];
3797+ const boundaryNode: void | ReplayNode =
3798+ trackedPostpones.workingMap.get(boundaryKeyPath);
3799+ if (boundaryNode === undefined) {
3800+ const suspenseBoundary : ReplaySuspenseBoundary = [
3801+ boundaryKeyPath [ 1 ] ,
3802+ boundaryKeyPath [ 2 ] ,
3803+ children ,
3804+ null ,
3805+ fallbackReplayNode ,
3806+ boundary . rootSegmentID ,
3807+ ] ;
3808+ trackedPostpones . workingMap . set ( boundaryKeyPath , suspenseBoundary ) ;
3809+ addToReplayParent ( suspenseBoundary , boundaryKeyPath [ 0 ] , trackedPostpones ) ;
3810+ return suspenseBoundary ;
3811+ } else {
3812+ // Upgrade to ReplaySuspenseBoundary.
3813+ const suspenseBoundary : ReplaySuspenseBoundary = ( boundaryNode : any ) ;
3814+ suspenseBoundary [ 4 ] = fallbackReplayNode ;
3815+ suspenseBoundary [ 5 ] = boundary . rootSegmentID ;
3816+ return suspenseBoundary ;
3817+ }
3818+ }
3819+
37773820function trackPostpone (
37783821 request : Request ,
37793822 trackedPostpones : PostponedHoles ,
@@ -3796,22 +3839,12 @@ function trackPostpone(
37963839 }
37973840
37983841 if ( boundary !== null && boundary . status === PENDING ) {
3799- boundary . status = POSTPONED ;
3800- // We need to eagerly assign it an ID because we'll need to refer to
3801- // it before flushing and we know that we can't inline it.
3802- boundary . rootSegmentID = request . nextSegmentId ++ ;
3803-
3804- const boundaryKeyPath = boundary . trackedContentKeyPath ;
3805- if ( boundaryKeyPath === null ) {
3806- throw new Error (
3807- 'It should not be possible to postpone at the root. This is a bug in React.' ,
3808- ) ;
3809- }
3810-
3811- const fallbackReplayNode = boundary . trackedFallbackNode ;
3812-
3813- const children : Array < ReplayNode > = [];
3814- if (boundaryKeyPath === keyPath && task . childIndex === - 1 ) {
3842+ const boundaryNode = trackPostponedBoundary (
3843+ request ,
3844+ trackedPostpones ,
3845+ boundary ,
3846+ ) ;
3847+ if ( boundary . trackedContentKeyPath === keyPath && task . childIndex === - 1 ) {
38153848 // Assign ID
38163849 if ( segment . id === - 1 ) {
38173850 if ( segment . parentFlushed ) {
@@ -3823,39 +3856,10 @@ function trackPostpone(
38233856 }
38243857 }
38253858 // We postponed directly inside the Suspense boundary so we mark this for resuming.
3826- const boundaryNode : ReplaySuspenseBoundary = [
3827- boundaryKeyPath [ 1 ] ,
3828- boundaryKeyPath [ 2 ] ,
3829- children ,
3830- segment . id ,
3831- fallbackReplayNode ,
3832- boundary . rootSegmentID ,
3833- ] ;
3834- trackedPostpones . workingMap . set ( boundaryKeyPath , boundaryNode ) ;
3835- addToReplayParent ( boundaryNode , boundaryKeyPath [ 0 ] , trackedPostpones ) ;
3859+ boundaryNode [ 3 ] = segment . id ;
38363860 return ;
3837- } else {
3838- let boundaryNode : void | ReplayNode =
3839- trackedPostpones . workingMap . get ( boundaryKeyPath ) ;
3840- if ( boundaryNode === undefined ) {
3841- boundaryNode = [
3842- boundaryKeyPath [ 1 ] ,
3843- boundaryKeyPath [ 2 ] ,
3844- children ,
3845- null ,
3846- fallbackReplayNode ,
3847- boundary . rootSegmentID ,
3848- ] ;
3849- trackedPostpones . workingMap . set ( boundaryKeyPath , boundaryNode ) ;
3850- addToReplayParent ( boundaryNode , boundaryKeyPath [ 0 ] , trackedPostpones ) ;
3851- } else {
3852- // Upgrade to ReplaySuspenseBoundary.
3853- const suspenseBoundary : ReplaySuspenseBoundary = ( boundaryNode : any ) ;
3854- suspenseBoundary [ 4 ] = fallbackReplayNode ;
3855- suspenseBoundary [ 5 ] = boundary . rootSegmentID ;
3856- }
3857- // Fall through to add the child node.
38583861 }
3862+ // Otherwise, fall through to add the child node.
38593863 }
38603864
38613865 // We know that this will leave a hole so we might as well assign an ID now.
0 commit comments