@@ -169,36 +169,40 @@ const REPLAY_SUSPENSE_BOUNDARY = 1;
169169const RESUME_ELEMENT = 2 ;
170170const RESUME_SLOT = 3 ;
171171
172- type ResumableParentNode =
172+ type ReplaySuspenseBoundary = [
173+ 1 , // REPLAY_SUSPENSE_BOUNDARY
174+ string | null /* name */ ,
175+ string | number /* key */ ,
176+ Array < ResumableNode > /* children */ ,
177+ SuspenseBoundaryID /* id */ ,
178+ ] ;
179+
180+ type ReplayNode =
173181 | [
174182 0 , // REPLAY_NODE
175183 string | null /* name */ ,
176184 string | number /* key */ ,
177185 Array < ResumableNode > /* children */ ,
178186 ]
179- | [
180- 1 , // REPLAY_SUSPENSE_BOUNDARY
181- string | null /* name */ ,
182- string | number /* key */ ,
183- Array < ResumableNode > /* children */ ,
184- SuspenseBoundaryID ,
185- ] ;
186- type ResumableNode =
187- | ResumableParentNode
188- | [
189- 2 , // RESUME_ELEMENT
190- string | null /* name */ ,
191- string | number /* key */ ,
192- number /* segment id */ ,
193- ]
194- | [
195- 3 , // RESUME_SLOT
196- number /* index */ ,
197- number /* segment id */ ,
198- ] ;
187+ | ReplaySuspenseBoundary ;
188+
189+ type ResumeElement = [
190+ 2 , // RESUME_ELEMENT
191+ string | null /* name */ ,
192+ string | number /* key */ ,
193+ number /* segment id */ ,
194+ ] ;
195+
196+ type ResumeSlot = [
197+ 3 , // RESUME_SLOT
198+ number /* index */ ,
199+ number /* segment id */ ,
200+ ] ;
201+
202+ type ResumableNode = ReplayNode | ResumeElement | ResumeSlot ;
199203
200204type PostponedHoles = {
201- workingMap : Map < KeyNode , ResumableParentNode > ,
205+ workingMap : Map < KeyNode , ReplayNode > ,
202206 root : Array < ResumableNode > ,
203207} ;
204208
@@ -394,6 +398,7 @@ export function createRequest(
394398 request ,
395399 null ,
396400 children ,
401+ - 1 ,
397402 null ,
398403 rootSegment ,
399404 abortSet ,
@@ -494,6 +499,7 @@ export function resumeRequest(
494499 request ,
495500 null ,
496501 children ,
502+ - 1 ,
497503 null ,
498504 rootSegment ,
499505 abortSet ,
@@ -551,6 +557,7 @@ function createTask(
551557 request : Request ,
552558 thenableState : ThenableState | null ,
553559 node : ReactNodeList ,
560+ childIndex : number ,
554561 blockedBoundary : Root | SuspenseBoundary ,
555562 blockedSegment : Segment ,
556563 abortSet : Set < Task > ,
@@ -568,6 +575,7 @@ function createTask(
568575 }
569576 const task : Task = ( {
570577 node,
578+ childIndex,
571579 ping : ( ) => pingTask ( request , task ) ,
572580 blockedBoundary,
573581 blockedSegment,
@@ -578,7 +586,6 @@ function createTask(
578586 context,
579587 treeContext,
580588 thenableState,
581- childIndex : - 1 ,
582589 } : any ) ;
583590 if ( __DEV__ ) {
584591 task . componentStack = null ;
@@ -730,6 +737,8 @@ function renderSuspenseBoundary(
730737 props : Object ,
731738) : void {
732739 pushBuiltInComponentStackInDEV ( task , 'Suspense' ) ;
740+
741+ const prevKeyPath = task . keyPath ;
733742 const parentBoundary = task . blockedBoundary ;
734743 const parentSegment = task . blockedSegment ;
735744
@@ -791,6 +800,7 @@ function renderSuspenseBoundary(
791800 newBoundary . resources ,
792801 ) ;
793802 }
803+ task . keyPath = keyPath ;
794804 try {
795805 // We use the safe form because we don't handle suspending here. Only error handling.
796806 renderNode ( request , task , content , - 1 ) ;
@@ -844,6 +854,7 @@ function renderSuspenseBoundary(
844854 }
845855 task . blockedBoundary = parentBoundary ;
846856 task . blockedSegment = parentSegment ;
857+ task . keyPath = prevKeyPath ;
847858 }
848859
849860 // We create suspended task for the fallback because we don't want to actually work
@@ -852,6 +863,7 @@ function renderSuspenseBoundary(
852863 request ,
853864 null ,
854865 fallback ,
866+ - 1 ,
855867 parentBoundary ,
856868 boundarySegment ,
857869 fallbackAbortSet ,
@@ -1938,15 +1950,15 @@ function trackPostpone(
19381950 ) ;
19391951 }
19401952 const children : Array < ResumableNode > = [ ] ;
1941- const boundaryNode : ResumableParentNode = [
1953+ const boundaryNode : ReplaySuspenseBoundary = [
19421954 REPLAY_SUSPENSE_BOUNDARY ,
19431955 boundaryKeyPath [ 1 ] ,
19441956 boundaryKeyPath [ 2 ] ,
19451957 children ,
19461958 boundary . id ,
19471959 ] ;
19481960 trackedPostpones . workingMap . set ( boundaryKeyPath , boundaryNode ) ;
1949- addToResumableParent ( boundaryNode , boundaryKeyPath [ 0 ] , trackedPostpones ) ;
1961+ addToReplayParent ( boundaryNode , boundaryKeyPath [ 0 ] , trackedPostpones ) ;
19501962 }
19511963
19521964 const keyPath = task . keyPath ;
@@ -1964,11 +1976,11 @@ function trackPostpone(
19641976 keyPath [ 2 ] ,
19651977 segment . id ,
19661978 ] ;
1967- addToResumableParent ( resumableElement , keyPath [ 0 ] , trackedPostpones ) ;
1979+ addToReplayParent ( resumableElement , keyPath [ 0 ] , trackedPostpones ) ;
19681980 } else {
19691981 // Resume at the slot within the array
19701982 const resumableNode = [ RESUME_SLOT , task . childIndex , segment . id ] ;
1971- addToResumableParent ( resumableNode , keyPath , trackedPostpones ) ;
1983+ addToReplayParent ( resumableNode , keyPath , trackedPostpones ) ;
19721984 }
19731985}
19741986
@@ -2023,6 +2035,7 @@ function spawnNewSuspendedTask(
20232035 request ,
20242036 thenableState ,
20252037 task . node ,
2038+ task . childIndex ,
20262039 task . blockedBoundary ,
20272040 newSegment ,
20282041 task . abortSet ,
@@ -2032,7 +2045,6 @@ function spawnNewSuspendedTask(
20322045 task . context ,
20332046 task . treeContext ,
20342047 ) ;
2035- newTask . childIndex = task . childIndex ;
20362048
20372049 if ( __DEV__ ) {
20382050 if ( task . componentStack !== null ) {
@@ -3072,7 +3084,7 @@ export function getResumableState(request: Request): ResumableState {
30723084 return request . resumableState ;
30733085}
30743086
3075- function addToResumableParent (
3087+ function addToReplayParent (
30763088 node : ResumableNode ,
30773089 parentKeyPath : Root | KeyNode ,
30783090 trackedPostpones : PostponedHoles ,
@@ -3088,9 +3100,9 @@ function addToResumableParent(
30883100 parentKeyPath [ 1 ] ,
30893101 parentKeyPath [ 2 ] ,
30903102 ( [ ] : Array < ResumableNode > ) ,
3091- ] : ResumableParentNode ) ;
3103+ ] : ReplayNode ) ;
30923104 workingMap . set ( parentKeyPath , parentNode ) ;
3093- addToResumableParent ( parentNode , parentKeyPath [ 0 ] , trackedPostpones ) ;
3105+ addToReplayParent ( parentNode , parentKeyPath [ 0 ] , trackedPostpones ) ;
30943106 }
30953107 parentNode [ 3 ] . push ( node ) ;
30963108 }
0 commit comments