Skip to content

Commit f560514

Browse files
committed
old
1 parent b6dcc6f commit f560514

12 files changed

+493
-146
lines changed

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

+63-21
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ import {
237237
markSkippedUpdateLanes,
238238
getWorkInProgressRoot,
239239
pushRenderLanes,
240-
getWorkInProgressTransitions,
241240
} from './ReactFiberWorkLoop.old';
242241
import {setWorkInProgressVersion} from './ReactMutableSource.old';
243242
import {pushCacheProvider, CacheContext} from './ReactFiberCacheComponent.old';
@@ -257,6 +256,7 @@ import {
257256
getSuspendedCache,
258257
pushTransition,
259258
getOffscreenDeferredCache,
259+
getSuspendedTransitions,
260260
} from './ReactFiberTransition.old';
261261

262262
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
@@ -653,16 +653,18 @@ function updateOffscreenComponent(
653653
// Rendering a hidden tree.
654654
if ((workInProgress.mode & ConcurrentMode) === NoMode) {
655655
// In legacy sync mode, don't defer the subtree. Render it now.
656+
// TODO: Consider how Offscreen should work with transitions in the future
656657
const nextState: OffscreenState = {
657658
baseLanes: NoLanes,
658659
cachePool: null,
660+
transitions: null,
659661
};
660662
workInProgress.memoizedState = nextState;
661663
if (enableCache) {
662664
// push the cache pool even though we're going to bail out
663665
// because otherwise there'd be a context mismatch
664666
if (current !== null) {
665-
pushTransition(workInProgress, null);
667+
pushTransition(workInProgress, null, null);
666668
}
667669
}
668670
pushRenderLanes(workInProgress, renderLanes);
@@ -689,14 +691,15 @@ function updateOffscreenComponent(
689691
const nextState: OffscreenState = {
690692
baseLanes: nextBaseLanes,
691693
cachePool: spawnedCachePool,
694+
transitions: null,
692695
};
693696
workInProgress.memoizedState = nextState;
694697
workInProgress.updateQueue = null;
695698
if (enableCache) {
696699
// push the cache pool even though we're going to bail out
697700
// because otherwise there'd be a context mismatch
698701
if (current !== null) {
699-
pushTransition(workInProgress, null);
702+
pushTransition(workInProgress, null, null);
700703
}
701704
}
702705

@@ -724,6 +727,7 @@ function updateOffscreenComponent(
724727
const nextState: OffscreenState = {
725728
baseLanes: NoLanes,
726729
cachePool: null,
730+
transitions: null,
727731
};
728732
workInProgress.memoizedState = nextState;
729733
// Push the lanes that were skipped when we bailed out.
@@ -734,7 +738,7 @@ function updateOffscreenComponent(
734738
// using the same cache. Unless the parent changed, since that means
735739
// there was a refresh.
736740
const prevCachePool = prevState !== null ? prevState.cachePool : null;
737-
pushTransition(workInProgress, prevCachePool);
741+
pushTransition(workInProgress, prevCachePool, null);
738742
}
739743

740744
pushRenderLanes(workInProgress, subtreeRenderLanes);
@@ -747,14 +751,21 @@ function updateOffscreenComponent(
747751

748752
subtreeRenderLanes = mergeLanes(prevState.baseLanes, renderLanes);
749753

754+
let prevCachePool = null;
750755
if (enableCache) {
751756
// If the render that spawned this one accessed the cache pool, resume
752757
// using the same cache. Unless the parent changed, since that means
753758
// there was a refresh.
754-
const prevCachePool = prevState.cachePool;
755-
pushTransition(workInProgress, prevCachePool);
759+
prevCachePool = prevState.cachePool;
756760
}
757761

762+
let transitions = null;
763+
if (enableTransitionTracing) {
764+
transitions = prevState.transitions;
765+
}
766+
767+
pushTransition(workInProgress, prevCachePool, transitions);
768+
758769
// Since we're not hidden anymore, reset the state
759770
workInProgress.memoizedState = null;
760771
} else {
@@ -768,7 +779,7 @@ function updateOffscreenComponent(
768779
// using the same cache. Unless the parent changed, since that means
769780
// there was a refresh.
770781
if (current !== null) {
771-
pushTransition(workInProgress, null);
782+
pushTransition(workInProgress, null, null);
772783
}
773784
}
774785
}
@@ -1326,28 +1337,25 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13261337
const nextProps = workInProgress.pendingProps;
13271338
const prevState = workInProgress.memoizedState;
13281339
const prevChildren = prevState.element;
1340+
13291341
cloneUpdateQueue(current, workInProgress);
13301342
processUpdateQueue(workInProgress, nextProps, null, renderLanes);
13311343

13321344
const nextState: RootState = workInProgress.memoizedState;
13331345
const root: FiberRoot = workInProgress.stateNode;
13341346

1347+
pushRootTransition(workInProgress, root, renderLanes);
1348+
13351349
if (enableCache) {
1336-
const nextCache: Cache = nextState.cache;
1337-
pushRootTransition(root);
1350+
const nextCache: Cache = workInProgress.memoizedState.cache;
13381351
pushCacheProvider(workInProgress, nextCache);
13391352
if (nextCache !== prevState.cache) {
13401353
// The root cache refreshed.
13411354
propagateContextChange(workInProgress, CacheContext, renderLanes);
13421355
}
13431356
}
13441357

1345-
if (enableTransitionTracing) {
1346-
// FIXME: Slipped past code review. This is not a safe mutation:
1347-
// workInProgress.memoizedState is a shared object. Need to fix before
1348-
// rolling out the Transition Tracing experiment.
1349-
workInProgress.memoizedState.transitions = getWorkInProgressTransitions();
1350-
}
1358+
const pendingSuspenseBoundaries = nextState.pendingSuspenseBoundaries || null;
13511359

13521360
// Caution: React DevTools currently depends on this property
13531361
// being called "element".
@@ -1362,6 +1370,7 @@ function updateHostRoot(current, workInProgress, renderLanes) {
13621370
element: nextChildren,
13631371
isDehydrated: false,
13641372
cache: nextState.cache,
1373+
pendingSuspenseBoundaries,
13651374
transitions: nextState.transitions,
13661375
};
13671376
const updateQueue: UpdateQueue<RootState> = (workInProgress.updateQueue: any);
@@ -1435,6 +1444,20 @@ function updateHostRoot(current, workInProgress, renderLanes) {
14351444
}
14361445
}
14371446
} else {
1447+
if (enableTransitionTracing) {
1448+
if (pendingSuspenseBoundaries !== nextState.pendingSuspenseBoundaries) {
1449+
const overrideState: RootState = {
1450+
element: nextChildren,
1451+
isDehydrated: nextState.isDehydrated,
1452+
cache: nextState.cache,
1453+
pendingSuspenseBoundaries,
1454+
transitions: nextState.transitions,
1455+
};
1456+
1457+
workInProgress.memoizedState = overrideState;
1458+
}
1459+
}
1460+
14381461
// Root is not dehydrated. Either this is a client-only root, or it
14391462
// already hydrated.
14401463
resetHydrationState();
@@ -1979,6 +2002,7 @@ function mountSuspenseOffscreenState(renderLanes: Lanes): OffscreenState {
19792002
return {
19802003
baseLanes: renderLanes,
19812004
cachePool: getSuspendedCache(),
2005+
transitions: getSuspendedTransitions(),
19822006
};
19832007
}
19842008

@@ -2010,9 +2034,11 @@ function updateSuspenseOffscreenState(
20102034
cachePool = getSuspendedCache();
20112035
}
20122036
}
2037+
20132038
return {
20142039
baseLanes: mergeLanes(prevOffscreenState.baseLanes, renderLanes),
20152040
cachePool,
2041+
transitions: prevOffscreenState.transitions,
20162042
};
20172043
}
20182044

@@ -2103,6 +2129,8 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21032129

21042130
pushSuspenseContext(workInProgress, suspenseContext);
21052131

2132+
const root = getWorkInProgressRoot();
2133+
21062134
// OK, the next part is confusing. We're about to reconcile the Suspense
21072135
// boundary's children. This involves some custom reconciliation logic. Two
21082136
// main reasons this is so complicated.
@@ -2143,7 +2171,6 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21432171
}
21442172
}
21452173
}
2146-
21472174
const nextPrimaryChildren = nextProps.children;
21482175
const nextFallbackChildren = nextProps.fallback;
21492176

@@ -2159,6 +2186,18 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21592186
renderLanes,
21602187
);
21612188
workInProgress.memoizedState = SUSPENDED_MARKER;
2189+
if (enableTransitionTracing) {
2190+
const currentTransitions = getSuspendedTransitions();
2191+
if (currentTransitions !== null) {
2192+
const primaryChildUpdateQueue: OffscreenQueue = {
2193+
transitions: currentTransitions,
2194+
rootMemoizedState:
2195+
root === null ? null : root.current.memoizedState,
2196+
};
2197+
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
2198+
}
2199+
}
2200+
21622201
return fallbackFragment;
21632202
} else if (
21642203
enableCPUSuspense &&
@@ -2285,6 +2324,8 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
22852324
if (currentTransitions !== null) {
22862325
const primaryChildUpdateQueue: OffscreenQueue = {
22872326
transitions: currentTransitions,
2327+
rootMemoizedState:
2328+
root === null ? null : root.current.memoizedState,
22882329
};
22892330
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
22902331
}
@@ -2336,6 +2377,8 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
23362377
if (currentTransitions !== null) {
23372378
const primaryChildUpdateQueue: OffscreenQueue = {
23382379
transitions: currentTransitions,
2380+
rootMemoizedState:
2381+
root === null ? null : root.current.memoizedState,
23392382
};
23402383
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
23412384
}
@@ -2368,6 +2411,7 @@ function mountSuspensePrimaryChildren(
23682411
renderLanes,
23692412
) {
23702413
const mode = workInProgress.mode;
2414+
23712415
const primaryChildProps: OffscreenProps = {
23722416
mode: 'visible',
23732417
children: primaryChildren,
@@ -2390,7 +2434,6 @@ function mountSuspenseFallbackChildren(
23902434
) {
23912435
const mode = workInProgress.mode;
23922436
const progressedPrimaryFragment: Fiber | null = workInProgress.child;
2393-
23942437
const primaryChildProps: OffscreenProps = {
23952438
mode: 'hidden',
23962439
children: primaryChildren,
@@ -3594,14 +3637,13 @@ function attemptEarlyBailoutIfNoScheduledUpdate(
35943637
case HostRoot:
35953638
pushHostRootContext(workInProgress);
35963639
const root: FiberRoot = workInProgress.stateNode;
3640+
pushRootTransition(workInProgress, root, renderLanes);
3641+
35973642
if (enableCache) {
35983643
const cache: Cache = current.memoizedState.cache;
35993644
pushCacheProvider(workInProgress, cache);
3600-
pushRootTransition(root);
3601-
}
3602-
if (enableTransitionTracing) {
3603-
workInProgress.memoizedState.transitions = getWorkInProgressTransitions();
36043645
}
3646+
36053647
resetHydrationState();
36063648
break;
36073649
case HostComponent:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {enableCache} from 'shared/ReactFeatureFlags';
1313
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
1414

1515
import {pushProvider, popProvider} from './ReactFiberNewContext.old';
16-
import * as Scheduler from 'scheduler';
1716

17+
import * as Scheduler from 'scheduler';
1818
export type Cache = {|
1919
controller: AbortController,
2020
data: Map<() => mixed, mixed>,

0 commit comments

Comments
 (0)