Skip to content

Commit d730263

Browse files
committed
reconcile fork
1 parent 198efc4 commit d730263

11 files changed

+542
-230
lines changed

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

Lines changed: 131 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,10 @@ import {
226226
markSkippedUpdateLanes,
227227
getWorkInProgressRoot,
228228
pushRenderLanes,
229-
getWorkInProgressTransitions,
229+
generateNewSuspenseOffscreenID,
230230
} from './ReactFiberWorkLoop.old';
231231
import {setWorkInProgressVersion} from './ReactMutableSource.old';
232-
import {
233-
requestCacheFromPool,
234-
pushCacheProvider,
235-
pushRootCachePool,
236-
CacheContext,
237-
getSuspendedCachePool,
238-
pushSpawnedCachePool,
239-
getOffscreenDeferredCachePool,
240-
} from './ReactFiberCacheComponent.old';
232+
import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.old';
241233
import {createCapturedValue} from './ReactCapturedValue';
242234
import {createClassErrorUpdate} from './ReactFiberThrow.old';
243235
import {completeSuspendedOffscreenHostContainer} from './ReactFiberCompleteWork.old';
@@ -248,6 +240,15 @@ import {
248240
pushTreeId,
249241
pushMaterializedTreeId,
250242
} from './ReactFiberTreeContext.old';
243+
import {pushRootPendingSuspenseBoundaries} from './ReactFiberTracingMarkerComponent.old';
244+
import {
245+
pushRootTransitionPool,
246+
getSuspendedCachePool,
247+
getSuspendedTransitionPool,
248+
pushTransitionPool,
249+
getOffscreenDeferredCachePool,
250+
requestCacheFromPool,
251+
} from './ReactFiberTransitionPool.old';
251252

252253
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
253254

@@ -646,13 +647,14 @@ function updateOffscreenComponent(
646647
const nextState: OffscreenState = {
647648
baseLanes: NoLanes,
648649
cachePool: null,
650+
transitions: null,
649651
};
650652
workInProgress.memoizedState = nextState;
651653
if (enableCache) {
652654
// push the cache pool even though we're going to bail out
653655
// because otherwise there'd be a context mismatch
654656
if (current !== null) {
655-
pushSpawnedCachePool(workInProgress, null);
657+
pushTransitionPool(workInProgress, null, null);
656658
}
657659
}
658660
pushRenderLanes(workInProgress, renderLanes);
@@ -679,14 +681,15 @@ function updateOffscreenComponent(
679681
const nextState: OffscreenState = {
680682
baseLanes: nextBaseLanes,
681683
cachePool: spawnedCachePool,
684+
transitions: null,
682685
};
683686
workInProgress.memoizedState = nextState;
684687
workInProgress.updateQueue = null;
685688
if (enableCache) {
686689
// push the cache pool even though we're going to bail out
687690
// because otherwise there'd be a context mismatch
688691
if (current !== null) {
689-
pushSpawnedCachePool(workInProgress, null);
692+
pushTransitionPool(workInProgress, null, null);
690693
}
691694
}
692695

@@ -714,6 +717,7 @@ function updateOffscreenComponent(
714717
const nextState: OffscreenState = {
715718
baseLanes: NoLanes,
716719
cachePool: null,
720+
transitions: null,
717721
};
718722
workInProgress.memoizedState = nextState;
719723
// Push the lanes that were skipped when we bailed out.
@@ -724,7 +728,7 @@ function updateOffscreenComponent(
724728
// using the same cache. Unless the parent changed, since that means
725729
// there was a refresh.
726730
const prevCachePool = prevState !== null ? prevState.cachePool : null;
727-
pushSpawnedCachePool(workInProgress, prevCachePool);
731+
pushTransitionPool(workInProgress, prevCachePool, null);
728732
}
729733

730734
pushRenderLanes(workInProgress, subtreeRenderLanes);
@@ -737,12 +741,14 @@ function updateOffscreenComponent(
737741

738742
subtreeRenderLanes = mergeLanes(prevState.baseLanes, renderLanes);
739743

740-
if (enableCache) {
744+
if (enableCache || enableTransitionTracing) {
741745
// If the render that spawned this one accessed the cache pool, resume
742746
// using the same cache. Unless the parent changed, since that means
743747
// there was a refresh.
744748
const prevCachePool = prevState.cachePool;
745-
pushSpawnedCachePool(workInProgress, prevCachePool);
749+
const transitions = prevState.transitions;
750+
751+
pushTransitionPool(workInProgress, prevCachePool, transitions);
746752
}
747753

748754
// Since we're not hidden anymore, reset the state
@@ -758,7 +764,7 @@ function updateOffscreenComponent(
758764
// using the same cache. Unless the parent changed, since that means
759765
// there was a refresh.
760766
if (current !== null) {
761-
pushSpawnedCachePool(workInProgress, null);
767+
pushTransitionPool(workInProgress, null, null);
762768
}
763769
}
764770
}
@@ -1327,9 +1333,12 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13271333

13281334
const root: FiberRoot = workInProgress.stateNode;
13291335

1336+
if (enableCache || enableTransitionTracing) {
1337+
pushRootTransitionPool(root, renderLanes);
1338+
}
1339+
13301340
if (enableCache) {
13311341
const nextCache: Cache = nextState.cache;
1332-
pushRootCachePool(root);
13331342
pushCacheProvider(workInProgress, nextCache);
13341343
if (nextCache !== prevState.cache) {
13351344
// The root cache refreshed.
@@ -1338,7 +1347,28 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13381347
}
13391348

13401349
if (enableTransitionTracing) {
1341-
workInProgress.memoizedState.transitions = getWorkInProgressTransitions();
1350+
const transitions = getSuspendedTransitionPool();
1351+
const nextTransitions = [];
1352+
if (transitions !== null) {
1353+
transitions.forEach(transition => {
1354+
nextTransitions.push(transition);
1355+
});
1356+
}
1357+
const rootTransitions = prevState.transitions;
1358+
if (rootTransitions != null) {
1359+
rootTransitions.forEach(transition => {
1360+
nextTransitions.push(transition);
1361+
});
1362+
}
1363+
1364+
let pendingSuspenseBoundaries = prevState.pendingSuspenseBoundaries;
1365+
if (pendingSuspenseBoundaries === null) {
1366+
pendingSuspenseBoundaries = new Map();
1367+
}
1368+
// probably have to actually copy this
1369+
workInProgress.memoizedState.transitions = nextTransitions;
1370+
workInProgress.memoizedState.pendingSuspenseBoundaries = pendingSuspenseBoundaries;
1371+
pushRootPendingSuspenseBoundaries(workInProgress);
13421372
}
13431373

13441374
// Caution: React DevTools currently depends on this property
@@ -1911,6 +1941,7 @@ function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState {
19111941
return {
19121942
baseLanes: renderLanes,
19131943
cachePool: getSuspendedCachePool(),
1944+
transitions: getSuspendedTransitionPool(),
19141945
};
19151946
}
19161947

@@ -1942,9 +1973,29 @@ function updateSuspenseOffscreenState(
19421973
cachePool = getSuspendedCachePool();
19431974
}
19441975
}
1976+
1977+
const transitions = [];
1978+
if (enableTransitionTracing) {
1979+
const prevTransitions = prevOffscreenState.transitions;
1980+
const newTransitions = getSuspendedTransitionPool();
1981+
if (prevTransitions !== null) {
1982+
prevTransitions.forEach(transition => {
1983+
transitions.push(transition);
1984+
});
1985+
}
1986+
if (newTransitions !== null) {
1987+
newTransitions.forEach(transition => {
1988+
if (!transitions.includes(transition)) {
1989+
transitions.push(transition);
1990+
}
1991+
});
1992+
}
1993+
}
1994+
19451995
return {
19461996
baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes),
19471997
cachePool,
1998+
transitions: transitions.length > 0 ? transitions : null,
19481999
};
19492000
}
19502001

@@ -2275,9 +2326,17 @@ function mountSuspensePrimaryChildren(
22752326
renderLanes,
22762327
) {
22772328
const mode = workInProgress.mode;
2329+
const props = workInProgress.memoizedProps;
2330+
let name = null;
2331+
if (props !== null) {
2332+
name = props.name;
2333+
}
2334+
22782335
const primaryChildProps: OffscreenProps = {
22792336
mode: 'visible',
22802337
children: primaryChildren,
2338+
name,
2339+
id: generateNewSuspenseOffscreenID(),
22812340
};
22822341
const primaryChildFragment = mountWorkInProgressOffscreenFiber(
22832342
primaryChildProps,
@@ -2297,10 +2356,16 @@ function mountSuspenseFallbackChildren(
22972356
) {
22982357
const mode = workInProgress.mode;
22992358
const progressedPrimaryFragment: Fiber | null = workInProgress.child;
2300-
2359+
const props = workInProgress.memoizedProps;
2360+
let name = null;
2361+
if (props !== null) {
2362+
name = props.name;
2363+
}
23012364
const primaryChildProps: OffscreenProps = {
23022365
mode: 'hidden',
23032366
children: primaryChildren,
2367+
name,
2368+
id: generateNewSuspenseOffscreenID(),
23042369
};
23052370

23062371
let primaryChildFragment;
@@ -2378,15 +2443,22 @@ function updateSuspensePrimaryChildren(
23782443
primaryChildren,
23792444
renderLanes,
23802445
) {
2446+
const name = workInProgress.pendingProps.name;
23812447
const currentPrimaryChildFragment: Fiber = (current.child: any);
23822448
const currentFallbackChildFragment: Fiber | null =
23832449
currentPrimaryChildFragment.sibling;
2450+
const props =
2451+
currentPrimaryChildFragment.memoizedProps !== null
2452+
? currentPrimaryChildFragment.memoizedProps
2453+
: currentPrimaryChildFragment.pendingProps;
23842454

23852455
const primaryChildFragment = updateWorkInProgressOffscreenFiber(
23862456
currentPrimaryChildFragment,
23872457
{
23882458
mode: 'visible',
23892459
children: primaryChildren,
2460+
name,
2461+
id: props.id,
23902462
},
23912463
);
23922464
if ((workInProgress.mode & ConcurrentMode) === NoMode) {
@@ -2416,14 +2488,21 @@ function updateSuspenseFallbackChildren(
24162488
fallbackChildren,
24172489
renderLanes,
24182490
) {
2491+
const name = workInProgress.pendingProps.name;
24192492
const mode = workInProgress.mode;
24202493
const currentPrimaryChildFragment: Fiber = (current.child: any);
24212494
const currentFallbackChildFragment: Fiber | null =
24222495
currentPrimaryChildFragment.sibling;
2496+
const props =
2497+
currentPrimaryChildFragment.memoizedProps !== null
2498+
? currentPrimaryChildFragment.memoizedProps
2499+
: currentPrimaryChildFragment.pendingProps;
24232500

24242501
const primaryChildProps: OffscreenProps = {
24252502
mode: 'hidden',
24262503
children: primaryChildren,
2504+
name,
2505+
id: props.id,
24272506
};
24282507

24292508
let primaryChildFragment;
@@ -2582,10 +2661,13 @@ function mountSuspenseFallbackAfterRetryWithoutHydrating(
25822661
fallbackChildren,
25832662
renderLanes,
25842663
) {
2664+
const name = workInProgress.pendingProps.name;
25852665
const fiberMode = workInProgress.mode;
25862666
const primaryChildProps: OffscreenProps = {
25872667
mode: 'visible',
25882668
children: primaryChildren,
2669+
name,
2670+
id: generateNewSuspenseOffscreenID(),
25892671
};
25902672
const primaryChildFragment = mountWorkInProgressOffscreenFiber(
25912673
primaryChildProps,
@@ -3501,13 +3583,41 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
35013583
case HostRoot:
35023584
pushHostRootContext(workInProgress);
35033585
const root: FiberRoot = workInProgress.stateNode;
3586+
if (enableCache || enableTransitionTracing) {
3587+
pushRootTransitionPool(root, renderLanes);
3588+
}
3589+
35043590
if (enableCache) {
35053591
const cache: Cache = current.memoizedState.cache;
35063592
pushCacheProvider(workInProgress, cache);
3507-
pushRootCachePool(root);
35083593
}
35093594
if (enableTransitionTracing) {
3510-
workInProgress.memoizedState.transitions = getWorkInProgressTransitions();
3595+
const prevState = current.memoizedState;
3596+
3597+
const nextTransitions = [];
3598+
const transitions = getSuspendedTransitionPool();
3599+
if (transitions !== null) {
3600+
transitions.forEach(transition => {
3601+
nextTransitions.push(transition);
3602+
});
3603+
}
3604+
const rootTransitions = prevState.transitions;
3605+
if (rootTransitions != null) {
3606+
rootTransitions.forEach(transition => {
3607+
if (!nextTransitions.includes(transition))
3608+
nextTransitions.push(transition);
3609+
});
3610+
}
3611+
3612+
let pendingSuspenseBoundaries = prevState.pendingSuspenseBoundaries;
3613+
if (pendingSuspenseBoundaries == null) {
3614+
pendingSuspenseBoundaries = new Map();
3615+
}
3616+
// probably have to actually copy this
3617+
workInProgress.memoizedState.transitions = nextTransitions;
3618+
workInProgress.memoizedState.pendingSuspenseBoundaries = pendingSuspenseBoundaries;
3619+
3620+
pushRootPendingSuspenseBoundaries(workInProgress);
35113621
}
35123622
resetHydrationState();
35133623
break;

0 commit comments

Comments
 (0)