@@ -226,7 +226,7 @@ import {
226
226
markSkippedUpdateLanes ,
227
227
getWorkInProgressRoot ,
228
228
pushRenderLanes ,
229
- getWorkInProgressTransitions ,
229
+ generateNewSuspenseOffscreenID ,
230
230
} from './ReactFiberWorkLoop.old' ;
231
231
import { setWorkInProgressVersion } from './ReactMutableSource.old' ;
232
232
import { pushCacheProvider , CacheContext } from './ReactFiberCacheComponent.old' ;
@@ -246,7 +246,9 @@ import {
246
246
getSuspendedCache ,
247
247
pushTransition ,
248
248
getOffscreenDeferredCache ,
249
+ getSuspendedTransitions ,
249
250
} from './ReactFiberTransition.old' ;
251
+ import { pushRootPendingSuspenseBoundaries } from './ReactFiberTracingMarkerComponent.old' ;
250
252
251
253
const ReactCurrentOwner = ReactSharedInternals . ReactCurrentOwner ;
252
254
@@ -645,13 +647,14 @@ function updateOffscreenComponent(
645
647
const nextState : OffscreenState = {
646
648
baseLanes : NoLanes ,
647
649
cachePool : null ,
650
+ transitions : null ,
648
651
} ;
649
652
workInProgress . memoizedState = nextState ;
650
653
if ( enableCache ) {
651
654
// push the cache pool even though we're going to bail out
652
655
// because otherwise there'd be a context mismatch
653
656
if ( current !== null ) {
654
- pushTransition ( workInProgress , null ) ;
657
+ pushTransition ( workInProgress , null , null ) ;
655
658
}
656
659
}
657
660
pushRenderLanes ( workInProgress , renderLanes ) ;
@@ -678,14 +681,15 @@ function updateOffscreenComponent(
678
681
const nextState : OffscreenState = {
679
682
baseLanes : nextBaseLanes ,
680
683
cachePool : spawnedCachePool ,
684
+ transitions : null ,
681
685
} ;
682
686
workInProgress . memoizedState = nextState ;
683
687
workInProgress . updateQueue = null ;
684
688
if ( enableCache ) {
685
689
// push the cache pool even though we're going to bail out
686
690
// because otherwise there'd be a context mismatch
687
691
if ( current !== null ) {
688
- pushTransition ( workInProgress , null ) ;
692
+ pushTransition ( workInProgress , null , null ) ;
689
693
}
690
694
}
691
695
@@ -713,6 +717,7 @@ function updateOffscreenComponent(
713
717
const nextState : OffscreenState = {
714
718
baseLanes : NoLanes ,
715
719
cachePool : null ,
720
+ transitions : null ,
716
721
} ;
717
722
workInProgress . memoizedState = nextState ;
718
723
// Push the lanes that were skipped when we bailed out.
@@ -723,7 +728,7 @@ function updateOffscreenComponent(
723
728
// using the same cache. Unless the parent changed, since that means
724
729
// there was a refresh.
725
730
const prevCachePool = prevState !== null ? prevState . cachePool : null ;
726
- pushTransition ( workInProgress , prevCachePool ) ;
731
+ pushTransition ( workInProgress , prevCachePool , null ) ;
727
732
}
728
733
729
734
pushRenderLanes ( workInProgress , subtreeRenderLanes ) ;
@@ -736,14 +741,14 @@ function updateOffscreenComponent(
736
741
737
742
subtreeRenderLanes = mergeLanes ( prevState . baseLanes , renderLanes ) ;
738
743
739
- if ( enableCache ) {
744
+ if ( enableCache || enableTransitionTracing ) {
740
745
// If the render that spawned this one accessed the cache pool, resume
741
746
// using the same cache. Unless the parent changed, since that means
742
747
// there was a refresh.
743
748
const prevCachePool = prevState . cachePool ;
744
- pushTransition ( workInProgress , prevCachePool ) ;
749
+ const transitions = prevState . transitions ;
750
+ pushTransition ( workInProgress , prevCachePool , transitions ) ;
745
751
}
746
-
747
752
// Since we're not hidden anymore, reset the state
748
753
workInProgress . memoizedState = null ;
749
754
} else {
@@ -757,7 +762,7 @@ function updateOffscreenComponent(
757
762
// using the same cache. Unless the parent changed, since that means
758
763
// there was a refresh.
759
764
if ( current !== null ) {
760
- pushTransition ( workInProgress , null ) ;
765
+ pushTransition ( workInProgress , null , null ) ;
761
766
}
762
767
}
763
768
}
@@ -1326,9 +1331,12 @@ function updateHostRoot(current, workInProgress, renderLanes) {
1326
1331
1327
1332
const root : FiberRoot = workInProgress . stateNode ;
1328
1333
1334
+ if ( enableCache || enableTransitionTracing ) {
1335
+ pushRootTransition ( root , renderLanes ) ;
1336
+ }
1337
+
1329
1338
if ( enableCache ) {
1330
1339
const nextCache : Cache = nextState . cache ;
1331
- pushRootTransition ( root ) ;
1332
1340
pushCacheProvider ( workInProgress , nextCache ) ;
1333
1341
if ( nextCache !== prevState . cache ) {
1334
1342
// The root cache refreshed.
@@ -1337,7 +1345,28 @@ function updateHostRoot(current, workInProgress, renderLanes) {
1337
1345
}
1338
1346
1339
1347
if ( enableTransitionTracing ) {
1340
- workInProgress . memoizedState . transitions = getWorkInProgressTransitions ( ) ;
1348
+ const transitions = getSuspendedTransitions ( ) ;
1349
+ const nextTransitions = [ ] ;
1350
+ if ( transitions !== null ) {
1351
+ transitions . forEach ( transition => {
1352
+ nextTransitions . push ( transition ) ;
1353
+ } ) ;
1354
+ }
1355
+ const rootTransitions = prevState . transitions ;
1356
+ if ( rootTransitions != null ) {
1357
+ rootTransitions . forEach ( transition => {
1358
+ nextTransitions . push ( transition ) ;
1359
+ } ) ;
1360
+ }
1361
+
1362
+ let pendingSuspenseBoundaries = prevState . pendingSuspenseBoundaries ;
1363
+ if ( pendingSuspenseBoundaries === null ) {
1364
+ pendingSuspenseBoundaries = new Map ( ) ;
1365
+ }
1366
+ // probably have to actually copy this
1367
+ workInProgress . memoizedState . transitions = nextTransitions ;
1368
+ workInProgress . memoizedState . pendingSuspenseBoundaries = pendingSuspenseBoundaries ;
1369
+ pushRootPendingSuspenseBoundaries ( workInProgress ) ;
1341
1370
}
1342
1371
1343
1372
// Caution: React DevTools currently depends on this property
@@ -1910,6 +1939,7 @@ function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState {
1910
1939
return {
1911
1940
baseLanes : renderLanes ,
1912
1941
cachePool : getSuspendedCache ( ) ,
1942
+ transitions : getSuspendedTransitions ( ) ,
1913
1943
} ;
1914
1944
}
1915
1945
@@ -1941,9 +1971,29 @@ function updateSuspenseOffscreenState(
1941
1971
cachePool = getSuspendedCache ( ) ;
1942
1972
}
1943
1973
}
1974
+
1975
+ const transitions = [ ] ;
1976
+ if ( enableTransitionTracing ) {
1977
+ const prevTransitions = prevOffscreenState . transitions ;
1978
+ const newTransitions = getSuspendedTransitions ( ) ;
1979
+ if ( prevTransitions !== null ) {
1980
+ prevTransitions . forEach ( transition => {
1981
+ transitions . push ( transition ) ;
1982
+ } ) ;
1983
+ }
1984
+ if ( newTransitions !== null ) {
1985
+ newTransitions . forEach ( transition => {
1986
+ if ( ! transitions . includes ( transition ) ) {
1987
+ transitions . push ( transition ) ;
1988
+ }
1989
+ } ) ;
1990
+ }
1991
+ }
1992
+
1944
1993
return {
1945
1994
baseLanes : mergeLanes ( prevOffscreenState . baseLanes , renderLanes ) ,
1946
1995
cachePool,
1996
+ transitions : transitions . length > 0 ? transitions : null ,
1947
1997
} ;
1948
1998
}
1949
1999
@@ -2274,9 +2324,17 @@ function mountSuspensePrimaryChildren(
2274
2324
renderLanes ,
2275
2325
) {
2276
2326
const mode = workInProgress . mode ;
2327
+ const props = workInProgress . memoizedProps ;
2328
+ let name = null ;
2329
+ if ( props !== null ) {
2330
+ name = props . name ;
2331
+ }
2332
+
2277
2333
const primaryChildProps : OffscreenProps = {
2278
2334
mode : 'visible' ,
2279
2335
children : primaryChildren ,
2336
+ name,
2337
+ id : generateNewSuspenseOffscreenID ( ) ,
2280
2338
} ;
2281
2339
const primaryChildFragment = mountWorkInProgressOffscreenFiber (
2282
2340
primaryChildProps ,
@@ -2296,10 +2354,16 @@ function mountSuspenseFallbackChildren(
2296
2354
) {
2297
2355
const mode = workInProgress . mode ;
2298
2356
const progressedPrimaryFragment : Fiber | null = workInProgress . child ;
2299
-
2357
+ const props = workInProgress . memoizedProps ;
2358
+ let name = null ;
2359
+ if ( props !== null ) {
2360
+ name = props . name ;
2361
+ }
2300
2362
const primaryChildProps : OffscreenProps = {
2301
2363
mode : 'hidden' ,
2302
2364
children : primaryChildren ,
2365
+ name,
2366
+ id : generateNewSuspenseOffscreenID ( ) ,
2303
2367
} ;
2304
2368
2305
2369
let primaryChildFragment ;
@@ -2377,15 +2441,22 @@ function updateSuspensePrimaryChildren(
2377
2441
primaryChildren ,
2378
2442
renderLanes ,
2379
2443
) {
2444
+ const name = workInProgress . pendingProps . name ;
2380
2445
const currentPrimaryChildFragment : Fiber = ( current . child : any ) ;
2381
2446
const currentFallbackChildFragment : Fiber | null =
2382
2447
currentPrimaryChildFragment . sibling ;
2448
+ const props =
2449
+ currentPrimaryChildFragment . memoizedProps !== null
2450
+ ? currentPrimaryChildFragment . memoizedProps
2451
+ : currentPrimaryChildFragment . pendingProps ;
2383
2452
2384
2453
const primaryChildFragment = updateWorkInProgressOffscreenFiber (
2385
2454
currentPrimaryChildFragment ,
2386
2455
{
2387
2456
mode : 'visible' ,
2388
2457
children : primaryChildren ,
2458
+ name,
2459
+ id : props . id ,
2389
2460
} ,
2390
2461
) ;
2391
2462
if ( ( workInProgress . mode & ConcurrentMode ) === NoMode ) {
@@ -2415,14 +2486,21 @@ function updateSuspenseFallbackChildren(
2415
2486
fallbackChildren ,
2416
2487
renderLanes ,
2417
2488
) {
2489
+ const name = workInProgress . pendingProps . name ;
2418
2490
const mode = workInProgress . mode ;
2419
2491
const currentPrimaryChildFragment : Fiber = ( current . child : any ) ;
2420
2492
const currentFallbackChildFragment : Fiber | null =
2421
2493
currentPrimaryChildFragment . sibling ;
2494
+ const props =
2495
+ currentPrimaryChildFragment . memoizedProps !== null
2496
+ ? currentPrimaryChildFragment . memoizedProps
2497
+ : currentPrimaryChildFragment . pendingProps ;
2422
2498
2423
2499
const primaryChildProps : OffscreenProps = {
2424
2500
mode : 'hidden' ,
2425
2501
children : primaryChildren ,
2502
+ name,
2503
+ id : props . id ,
2426
2504
} ;
2427
2505
2428
2506
let primaryChildFragment ;
@@ -2581,10 +2659,13 @@ function mountSuspenseFallbackAfterRetryWithoutHydrating(
2581
2659
fallbackChildren ,
2582
2660
renderLanes ,
2583
2661
) {
2662
+ const name = workInProgress . pendingProps . name ;
2584
2663
const fiberMode = workInProgress . mode ;
2585
2664
const primaryChildProps : OffscreenProps = {
2586
2665
mode : 'visible' ,
2587
2666
children : primaryChildren ,
2667
+ name,
2668
+ id : generateNewSuspenseOffscreenID ( ) ,
2588
2669
} ;
2589
2670
const primaryChildFragment = mountWorkInProgressOffscreenFiber (
2590
2671
primaryChildProps ,
@@ -3500,13 +3581,41 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
3500
3581
case HostRoot :
3501
3582
pushHostRootContext ( workInProgress ) ;
3502
3583
const root : FiberRoot = workInProgress . stateNode ;
3584
+ if ( enableCache || enableTransitionTracing ) {
3585
+ pushRootTransition ( root , renderLanes ) ;
3586
+ }
3587
+
3503
3588
if ( enableCache ) {
3504
3589
const cache : Cache = current . memoizedState . cache ;
3505
3590
pushCacheProvider ( workInProgress , cache ) ;
3506
- pushRootTransition ( root ) ;
3507
3591
}
3508
3592
if ( enableTransitionTracing ) {
3509
- workInProgress . memoizedState . transitions = getWorkInProgressTransitions ( ) ;
3593
+ const prevState = current . memoizedState ;
3594
+
3595
+ const nextTransitions = [ ] ;
3596
+ const transitions = getSuspendedTransitions ( ) ;
3597
+ if ( transitions !== null ) {
3598
+ transitions . forEach ( transition => {
3599
+ nextTransitions . push ( transition ) ;
3600
+ } ) ;
3601
+ }
3602
+ const rootTransitions = prevState . transitions ;
3603
+ if ( rootTransitions != null ) {
3604
+ rootTransitions . forEach ( transition => {
3605
+ if ( ! nextTransitions . includes ( transition ) )
3606
+ nextTransitions . push ( transition ) ;
3607
+ } ) ;
3608
+ }
3609
+
3610
+ let pendingSuspenseBoundaries = prevState . pendingSuspenseBoundaries ;
3611
+ if ( pendingSuspenseBoundaries == null ) {
3612
+ pendingSuspenseBoundaries = new Map ( ) ;
3613
+ }
3614
+ // probably have to actually copy this
3615
+ workInProgress . memoizedState . transitions = nextTransitions ;
3616
+ workInProgress . memoizedState . pendingSuspenseBoundaries = pendingSuspenseBoundaries ;
3617
+
3618
+ pushRootPendingSuspenseBoundaries ( workInProgress ) ;
3510
3619
}
3511
3620
resetHydrationState ( ) ;
3512
3621
break ;
0 commit comments