Skip to content

Commit f7cf077

Browse files
authored
[Transition Tracing] Add Offscreen Queue (#24341)
Adds an Offscreen Queue. We use the offscreen queue to store not yet processed transitions. During the commit phase, we will add these transitions to the transitions field in memoizedState (in the subsequent PR) and clear the transitions field in the updateQueue
1 parent 4fc394b commit f7cf077

5 files changed

+79
-0
lines changed

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

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {SuspenseContext} from './ReactFiberSuspenseContext.new';
2626
import type {
2727
OffscreenProps,
2828
OffscreenState,
29+
OffscreenQueue,
2930
} from './ReactFiberOffscreenComponent';
3031
import type {
3132
Cache,
@@ -255,6 +256,7 @@ import {
255256
getSuspendedCache,
256257
pushTransition,
257258
getOffscreenDeferredCache,
259+
getSuspendedTransitions,
258260
} from './ReactFiberTransition.new';
259261

260262
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
@@ -2161,6 +2163,16 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21612163
renderLanes,
21622164
);
21632165
workInProgress.memoizedState = SUSPENDED_MARKER;
2166+
if (enableTransitionTracing) {
2167+
const currentTransitions = getSuspendedTransitions();
2168+
if (currentTransitions !== null) {
2169+
const primaryChildUpdateQueue: OffscreenQueue = {
2170+
transitions: currentTransitions,
2171+
};
2172+
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
2173+
}
2174+
}
2175+
21642176
return fallbackFragment;
21652177
} else if (
21662178
enableCPUSuspense &&
@@ -2281,6 +2293,15 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
22812293
prevOffscreenState === null
22822294
? mountSuspenseOffscreenState(renderLanes)
22832295
: updateSuspenseOffscreenState(prevOffscreenState, renderLanes);
2296+
if (enableTransitionTracing) {
2297+
const currentTransitions = getSuspendedTransitions();
2298+
if (currentTransitions !== null) {
2299+
const primaryChildUpdateQueue: OffscreenQueue = {
2300+
transitions: currentTransitions,
2301+
};
2302+
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
2303+
}
2304+
}
22842305
primaryChildFragment.childLanes = getRemainingWorkInPrimaryTree(
22852306
current,
22862307
renderLanes,
@@ -2322,6 +2343,17 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
23222343
current,
23232344
renderLanes,
23242345
);
2346+
2347+
if (enableTransitionTracing) {
2348+
const currentTransitions = getSuspendedTransitions();
2349+
if (currentTransitions !== null) {
2350+
const primaryChildUpdateQueue: OffscreenQueue = {
2351+
transitions: currentTransitions,
2352+
};
2353+
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
2354+
}
2355+
}
2356+
23252357
// Skip the primary children, and continue working on the
23262358
// fallback children.
23272359
workInProgress.memoizedState = SUSPENDED_MARKER;

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

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {SuspenseContext} from './ReactFiberSuspenseContext.old';
2626
import type {
2727
OffscreenProps,
2828
OffscreenState,
29+
OffscreenQueue,
2930
} from './ReactFiberOffscreenComponent';
3031
import type {
3132
Cache,
@@ -255,6 +256,7 @@ import {
255256
getSuspendedCache,
256257
pushTransition,
257258
getOffscreenDeferredCache,
259+
getSuspendedTransitions,
258260
} from './ReactFiberTransition.old';
259261

260262
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
@@ -2161,6 +2163,16 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
21612163
renderLanes,
21622164
);
21632165
workInProgress.memoizedState = SUSPENDED_MARKER;
2166+
if (enableTransitionTracing) {
2167+
const currentTransitions = getSuspendedTransitions();
2168+
if (currentTransitions !== null) {
2169+
const primaryChildUpdateQueue: OffscreenQueue = {
2170+
transitions: currentTransitions,
2171+
};
2172+
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
2173+
}
2174+
}
2175+
21642176
return fallbackFragment;
21652177
} else if (
21662178
enableCPUSuspense &&
@@ -2281,6 +2293,15 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
22812293
prevOffscreenState === null
22822294
? mountSuspenseOffscreenState(renderLanes)
22832295
: updateSuspenseOffscreenState(prevOffscreenState, renderLanes);
2296+
if (enableTransitionTracing) {
2297+
const currentTransitions = getSuspendedTransitions();
2298+
if (currentTransitions !== null) {
2299+
const primaryChildUpdateQueue: OffscreenQueue = {
2300+
transitions: currentTransitions,
2301+
};
2302+
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
2303+
}
2304+
}
22842305
primaryChildFragment.childLanes = getRemainingWorkInPrimaryTree(
22852306
current,
22862307
renderLanes,
@@ -2322,6 +2343,17 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
23222343
current,
23232344
renderLanes,
23242345
);
2346+
2347+
if (enableTransitionTracing) {
2348+
const currentTransitions = getSuspendedTransitions();
2349+
if (currentTransitions !== null) {
2350+
const primaryChildUpdateQueue: OffscreenQueue = {
2351+
transitions: currentTransitions,
2352+
};
2353+
primaryChildFragment.updateQueue = primaryChildUpdateQueue;
2354+
}
2355+
}
2356+
23252357
// Skip the primary children, and continue working on the
23262358
// fallback children.
23272359
workInProgress.memoizedState = SUSPENDED_MARKER;

packages/react-reconciler/src/ReactFiberCommitWork.new.js

+5
Original file line numberDiff line numberDiff line change
@@ -2781,6 +2781,11 @@ function commitPassiveMountOnFiber(
27812781
}
27822782
}
27832783
}
2784+
2785+
if (enableTransitionTracing) {
2786+
// TODO: Add code to actually process the update queue
2787+
finishedWork.updateQueue = null;
2788+
}
27842789
break;
27852790
}
27862791
case CacheComponent: {

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

+5
Original file line numberDiff line numberDiff line change
@@ -2781,6 +2781,11 @@ function commitPassiveMountOnFiber(
27812781
}
27822782
}
27832783
}
2784+
2785+
if (enableTransitionTracing) {
2786+
// TODO: Add code to actually process the update queue
2787+
finishedWork.updateQueue = null;
2788+
}
27842789
break;
27852790
}
27862791
case CacheComponent: {

packages/react-reconciler/src/ReactFiberOffscreenComponent.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {ReactNodeList, OffscreenMode} from 'shared/ReactTypes';
1111
import type {Lanes} from './ReactFiberLane.old';
1212
import type {SpawnedCachePool} from './ReactFiberCacheComponent.new';
1313
import type {Transition} from './ReactFiberTracingMarkerComponent.new';
14+
1415
export type OffscreenProps = {|
1516
// TODO: Pick an API before exposing the Offscreen type. I've chosen an enum
1617
// for now, since we might have multiple variants. For example, hiding the
@@ -33,4 +34,8 @@ export type OffscreenState = {|
3334
transitions: Set<Transition> | null,
3435
|};
3536

37+
export type OffscreenQueue = {|
38+
transitions: Array<Transition> | null,
39+
|} | null;
40+
3641
export type OffscreenInstance = {};

0 commit comments

Comments
 (0)