@@ -2460,14 +2460,6 @@ function trackPostpone(
24602460 segment . status = POSTPONED ;
24612461
24622462 const keyPath = task . keyPath ;
2463- if ( keyPath === null ) {
2464- // TODO: This is not really true now because if you postpone in the root component
2465- // or has a lazy root then that's the root.
2466- throw new Error (
2467- 'It should not be possible to postpone at the root. This is a bug in React.' ,
2468- ) ;
2469- }
2470-
24712463 const boundary = task . blockedBoundary ;
24722464 if ( boundary !== null && boundary . status === PENDING ) {
24732465 boundary . status = POSTPONED ;
@@ -2525,37 +2517,53 @@ function trackPostpone(
25252517
25262518 if ( task . childIndex === - 1 ) {
25272519 // Resume starting from directly inside the previous parent element.
2528- const resumableElement : ReplayNode = [
2529- keyPath [ 1 ] ,
2530- keyPath [ 2 ] ,
2531- ( [ ] : Array < ReplayNode > ) ,
2532- segment . id ,
2533- ] ;
2534- addToReplayParent ( resumableElement , keyPath [ 0 ] , trackedPostpones ) ;
2535- } else {
2536- const workingMap = trackedPostpones . workingMap ;
2537- let resumableNode = workingMap . get ( keyPath ) ;
2538- let slots ;
2539- if ( resumableNode === undefined ) {
2540- slots = ( { } : { [ index : number ] : number } ) ;
2541- resumableNode = ( [
2520+ if ( keyPath === null ) {
2521+ trackedPostpones . rootSlots = segment . id ;
2522+ } else {
2523+ const resumableElement : ReplayNode = [
25422524 keyPath [ 1 ] ,
25432525 keyPath [ 2 ] ,
25442526 ( [ ] : Array < ReplayNode > ) ,
2545- slots ,
2546- ] : ReplayNode ) ;
2547- workingMap . set ( keyPath , resumableNode ) ;
2548- addToReplayParent ( resumableNode , keyPath [ 0 ] , trackedPostpones ) ;
2549- } else {
2550- slots = resumableNode [ 3 ] ;
2527+ segment . id ,
2528+ ] ;
2529+ addToReplayParent ( resumableElement , keyPath [ 0 ] , trackedPostpones ) ;
2530+ }
2531+ } else {
2532+ let slots ;
2533+ if ( keyPath === null ) {
2534+ slots = trackedPostpones . rootSlots ;
25512535 if ( slots === null ) {
2552- slots = resumableNode [ 3 ] = ( { } : { [ index : number ] : number } ) ;
2536+ slots = trackedPostpones . rootSlots = ( { } : { [ index : number ] : number } ) ;
25532537 } else if ( typeof slots === 'number' ) {
25542538 throw new Error (
25552539 'It should not be possible to postpone both at the root of an element ' +
25562540 'as well as a slot below. This is a bug in React.' ,
25572541 ) ;
25582542 }
2543+ } else {
2544+ const workingMap = trackedPostpones . workingMap ;
2545+ let resumableNode = workingMap . get ( keyPath ) ;
2546+ if ( resumableNode === undefined ) {
2547+ slots = ( { } : { [ index : number ] : number } ) ;
2548+ resumableNode = ( [
2549+ keyPath [ 1 ] ,
2550+ keyPath [ 2 ] ,
2551+ ( [ ] : Array < ReplayNode > ) ,
2552+ slots ,
2553+ ] : ReplayNode ) ;
2554+ workingMap . set ( keyPath , resumableNode ) ;
2555+ addToReplayParent ( resumableNode , keyPath [ 0 ] , trackedPostpones ) ;
2556+ } else {
2557+ slots = resumableNode [ 3 ] ;
2558+ if ( slots === null ) {
2559+ slots = resumableNode [ 3 ] = ( { } : { [ index : number ] : number } ) ;
2560+ } else if ( typeof slots === 'number' ) {
2561+ throw new Error (
2562+ 'It should not be possible to postpone both at the root of an element ' +
2563+ 'as well as a slot below. This is a bug in React.' ,
2564+ ) ;
2565+ }
2566+ }
25592567 }
25602568 slots [ task . childIndex ] = segment . id ;
25612569 }
0 commit comments