Skip to content

Commit c7dd02c

Browse files
committed
old
1 parent e0f0a19 commit c7dd02c

11 files changed

+373
-79
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.old.js

Lines changed: 122 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ import {
226226
markSkippedUpdateLanes,
227227
getWorkInProgressRoot,
228228
pushRenderLanes,
229-
getWorkInProgressTransitions,
229+
generateNewSuspenseOffscreenID,
230230
} from './ReactFiberWorkLoop.old';
231231
import {setWorkInProgressVersion} from './ReactMutableSource.old';
232232
import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.old';
@@ -246,7 +246,9 @@ import {
246246
getSuspendedCache,
247247
pushTransition,
248248
getOffscreenDeferredCache,
249+
getSuspendedTransitions,
249250
} from './ReactFiberTransition.old';
251+
import {pushRootPendingSuspenseBoundaries} from './ReactFiberTracingMarkerComponent.old';
250252

251253
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
252254

@@ -645,13 +647,14 @@ function updateOffscreenComponent(
645647
const nextState: OffscreenState = {
646648
baseLanes: NoLanes,
647649
cachePool: null,
650+
transitions: null,
648651
};
649652
workInProgress.memoizedState = nextState;
650653
if (enableCache) {
651654
// push the cache pool even though we're going to bail out
652655
// because otherwise there'd be a context mismatch
653656
if (current !== null) {
654-
pushTransition(workInProgress, null);
657+
pushTransition(workInProgress, null, null);
655658
}
656659
}
657660
pushRenderLanes(workInProgress, renderLanes);
@@ -678,14 +681,15 @@ function updateOffscreenComponent(
678681
const nextState: OffscreenState = {
679682
baseLanes: nextBaseLanes,
680683
cachePool: spawnedCachePool,
684+
transitions: null,
681685
};
682686
workInProgress.memoizedState = nextState;
683687
workInProgress.updateQueue = null;
684688
if (enableCache) {
685689
// push the cache pool even though we're going to bail out
686690
// because otherwise there'd be a context mismatch
687691
if (current !== null) {
688-
pushTransition(workInProgress, null);
692+
pushTransition(workInProgress, null, null);
689693
}
690694
}
691695

@@ -713,6 +717,7 @@ function updateOffscreenComponent(
713717
const nextState: OffscreenState = {
714718
baseLanes: NoLanes,
715719
cachePool: null,
720+
transitions: null,
716721
};
717722
workInProgress.memoizedState = nextState;
718723
// Push the lanes that were skipped when we bailed out.
@@ -723,7 +728,7 @@ function updateOffscreenComponent(
723728
// using the same cache. Unless the parent changed, since that means
724729
// there was a refresh.
725730
const prevCachePool = prevState !== null ? prevState.cachePool : null;
726-
pushTransition(workInProgress, prevCachePool);
731+
pushTransition(workInProgress, prevCachePool, null);
727732
}
728733

729734
pushRenderLanes(workInProgress, subtreeRenderLanes);
@@ -736,14 +741,14 @@ function updateOffscreenComponent(
736741

737742
subtreeRenderLanes = mergeLanes(prevState.baseLanes, renderLanes);
738743

739-
if (enableCache) {
744+
if (enableCache || enableTransitionTracing) {
740745
// If the render that spawned this one accessed the cache pool, resume
741746
// using the same cache. Unless the parent changed, since that means
742747
// there was a refresh.
743748
const prevCachePool = prevState.cachePool;
744-
pushTransition(workInProgress, prevCachePool);
749+
const transitions = prevState.transitions;
750+
pushTransition(workInProgress, prevCachePool, transitions);
745751
}
746-
747752
// Since we're not hidden anymore, reset the state
748753
workInProgress.memoizedState = null;
749754
} else {
@@ -757,7 +762,7 @@ function updateOffscreenComponent(
757762
// using the same cache. Unless the parent changed, since that means
758763
// there was a refresh.
759764
if (current !== null) {
760-
pushTransition(workInProgress, null);
765+
pushTransition(workInProgress, null, null);
761766
}
762767
}
763768
}
@@ -1326,9 +1331,12 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13261331

13271332
const root: FiberRoot = workInProgress.stateNode;
13281333

1334+
if (enableCache || enableTransitionTracing) {
1335+
pushRootTransition(root, renderLanes);
1336+
}
1337+
13291338
if (enableCache) {
13301339
const nextCache: Cache = nextState.cache;
1331-
pushRootTransition(root);
13321340
pushCacheProvider(workInProgress, nextCache);
13331341
if (nextCache !== prevState.cache) {
13341342
// The root cache refreshed.
@@ -1337,7 +1345,28 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13371345
}
13381346

13391347
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);
13411370
}
13421371

13431372
// Caution: React DevTools currently depends on this property
@@ -1910,6 +1939,7 @@ function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState {
19101939
return {
19111940
baseLanes: renderLanes,
19121941
cachePool: getSuspendedCache(),
1942+
transitions: getSuspendedTransitions(),
19131943
};
19141944
}
19151945

@@ -1941,9 +1971,29 @@ function updateSuspenseOffscreenState(
19411971
cachePool = getSuspendedCache();
19421972
}
19431973
}
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+
19441993
return {
19451994
baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes),
19461995
cachePool,
1996+
transitions: transitions.length > 0 ? transitions : null,
19471997
};
19481998
}
19491999

@@ -2274,9 +2324,17 @@ function mountSuspensePrimaryChildren(
22742324
renderLanes,
22752325
) {
22762326
const mode = workInProgress.mode;
2327+
const props = workInProgress.memoizedProps;
2328+
let name = null;
2329+
if (props !== null) {
2330+
name = props.name;
2331+
}
2332+
22772333
const primaryChildProps: OffscreenProps = {
22782334
mode: 'visible',
22792335
children: primaryChildren,
2336+
name,
2337+
id: generateNewSuspenseOffscreenID(),
22802338
};
22812339
const primaryChildFragment = mountWorkInProgressOffscreenFiber(
22822340
primaryChildProps,
@@ -2296,10 +2354,16 @@ function mountSuspenseFallbackChildren(
22962354
) {
22972355
const mode = workInProgress.mode;
22982356
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+
}
23002362
const primaryChildProps: OffscreenProps = {
23012363
mode: 'hidden',
23022364
children: primaryChildren,
2365+
name,
2366+
id: generateNewSuspenseOffscreenID(),
23032367
};
23042368

23052369
let primaryChildFragment;
@@ -2377,15 +2441,22 @@ function updateSuspensePrimaryChildren(
23772441
primaryChildren,
23782442
renderLanes,
23792443
) {
2444+
const name = workInProgress.pendingProps.name;
23802445
const currentPrimaryChildFragment: Fiber = (current.child: any);
23812446
const currentFallbackChildFragment: Fiber | null =
23822447
currentPrimaryChildFragment.sibling;
2448+
const props =
2449+
currentPrimaryChildFragment.memoizedProps !== null
2450+
? currentPrimaryChildFragment.memoizedProps
2451+
: currentPrimaryChildFragment.pendingProps;
23832452

23842453
const primaryChildFragment = updateWorkInProgressOffscreenFiber(
23852454
currentPrimaryChildFragment,
23862455
{
23872456
mode: 'visible',
23882457
children: primaryChildren,
2458+
name,
2459+
id: props.id,
23892460
},
23902461
);
23912462
if ((workInProgress.mode & ConcurrentMode) === NoMode) {
@@ -2415,14 +2486,21 @@ function updateSuspenseFallbackChildren(
24152486
fallbackChildren,
24162487
renderLanes,
24172488
) {
2489+
const name = workInProgress.pendingProps.name;
24182490
const mode = workInProgress.mode;
24192491
const currentPrimaryChildFragment: Fiber = (current.child: any);
24202492
const currentFallbackChildFragment: Fiber | null =
24212493
currentPrimaryChildFragment.sibling;
2494+
const props =
2495+
currentPrimaryChildFragment.memoizedProps !== null
2496+
? currentPrimaryChildFragment.memoizedProps
2497+
: currentPrimaryChildFragment.pendingProps;
24222498

24232499
const primaryChildProps: OffscreenProps = {
24242500
mode: 'hidden',
24252501
children: primaryChildren,
2502+
name,
2503+
id: props.id,
24262504
};
24272505

24282506
let primaryChildFragment;
@@ -2581,10 +2659,13 @@ function mountSuspenseFallbackAfterRetryWithoutHydrating(
25812659
fallbackChildren,
25822660
renderLanes,
25832661
) {
2662+
const name = workInProgress.pendingProps.name;
25842663
const fiberMode = workInProgress.mode;
25852664
const primaryChildProps: OffscreenProps = {
25862665
mode: 'visible',
25872666
children: primaryChildren,
2667+
name,
2668+
id: generateNewSuspenseOffscreenID(),
25882669
};
25892670
const primaryChildFragment = mountWorkInProgressOffscreenFiber(
25902671
primaryChildProps,
@@ -3500,13 +3581,41 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
35003581
case HostRoot:
35013582
pushHostRootContext(workInProgress);
35023583
const root: FiberRoot = workInProgress.stateNode;
3584+
if (enableCache || enableTransitionTracing) {
3585+
pushRootTransition(root, renderLanes);
3586+
}
3587+
35033588
if (enableCache) {
35043589
const cache: Cache = current.memoizedState.cache;
35053590
pushCacheProvider(workInProgress, cache);
3506-
pushRootTransition(root);
35073591
}
35083592
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);
35103619
}
35113620
resetHydrationState();
35123621
break;

packages/react-reconciler/src/ReactFiberCacheComponent.old.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
1414

1515
import {pushProvider, popProvider} from './ReactFiberNewContext.old';
1616
import * as Scheduler from 'scheduler';
17-
17+
export type CacheComponentState = {|
18+
+parent: Cache,
19+
+cache: Cache,
20+
|};
1821
export type Cache = {|
1922
controller: AbortController,
2023
data: Map<() => mixed, mixed>,
2124
refCount: number,
2225
|};
2326

24-
export type CacheComponentState = {|
25-
+parent: Cache,
26-
+cache: Cache,
27-
|};
28-
2927
export type SpawnedCachePool = {|
3028
+parent: Cache,
3129
+pool: Cache,

0 commit comments

Comments
 (0)