Skip to content

Commit b252275

Browse files
committed
Store transition types per root
We store them on all roots that have been scheduled as part of the startTransition call. We shouldn't just let the first root that commits steal them all. Each root gets its own set.
1 parent 415c80a commit b252275

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

packages/react-reconciler/src/ReactFiberRoot.js

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
enableUpdaterTracking,
3434
enableTransitionTracing,
3535
disableLegacyMode,
36+
enableViewTransition,
3637
enableGestureTransition,
3738
} from 'shared/ReactFeatureFlags';
3839
import {initializeUpdateQueue} from './ReactFiberClassUpdateQueue';
@@ -98,6 +99,10 @@ function FiberRootNode(
9899

99100
this.formState = formState;
100101

102+
if (enableViewTransition) {
103+
this.transitionTypes = null;
104+
}
105+
101106
if (enableGestureTransition) {
102107
this.pendingGestures = null;
103108
this.stoppingGestures = null;

packages/react-reconciler/src/ReactFiberTransition.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {ScheduledGesture} from './ReactFiberGestureScheduler';
2020

2121
import {
2222
enableTransitionTracing,
23+
enableViewTransition,
2324
enableGestureTransition,
2425
} from 'shared/ReactFeatureFlags';
2526
import {isPrimaryRenderer} from './ReactFiberConfig';
@@ -87,7 +88,17 @@ ReactSharedInternals.S = function onStartTransitionFinishForReconciler(
8788
const thenable: Thenable<mixed> = (returnValue: any);
8889
entangleAsyncAction(transition, thenable);
8990
}
90-
queueTransitionTypes(transition.types);
91+
if (enableViewTransition && transition.types !== null) {
92+
// Within this Transition we should've now scheduled any roots we have updates
93+
// to work on. If there are no updates on a root, then the Transition type won't
94+
// be applied to that root.
95+
// TODO: The exception is if we're to an async action, the updates might come in later.
96+
let root = firstScheduledRoot;
97+
while (root !== null) {
98+
queueTransitionTypes(root, transition.types);
99+
root = root.next;
100+
}
101+
}
91102
if (prevOnStartTransitionFinish !== null) {
92103
prevOnStartTransitionFinish(transition, returnValue);
93104
}

packages/react-reconciler/src/ReactFiberTransitionTypes.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
* @flow
88
*/
99

10+
import type {FiberRoot} from './ReactInternalTypes';
1011
import type {TransitionTypes} from 'react/src/ReactTransitionType';
1112

1213
import {enableViewTransition} from 'shared/ReactFeatureFlags';
1314

14-
let queuedTransitionTypes: null | TransitionTypes = null;
15-
1615
export function queueTransitionTypes(
16+
root: FiberRoot,
1717
transitionTypes: null | TransitionTypes,
1818
): void {
19-
// Currently, we assume that all Transitions are batched together into a global single commit.
2019
if (enableViewTransition && transitionTypes !== null) {
21-
let queued = queuedTransitionTypes;
20+
// TODO: We should really store transitionTypes per lane in a LaneMap on
21+
// the root. Then merge it when we commit. We currently assume that all
22+
// Transitions are entangled.
23+
let queued = root.transitionTypes;
2224
if (queued === null) {
23-
queued = queuedTransitionTypes = [];
25+
queued = root.transitionTypes = [];
2426
}
2527
for (let i = 0; i < transitionTypes.length; i++) {
2628
const transitionType = transitionTypes[i];
@@ -31,8 +33,10 @@ export function queueTransitionTypes(
3133
}
3234
}
3335

34-
export function claimQueuedTransitionTypes(): null | TransitionTypes {
35-
const claimed = queuedTransitionTypes;
36-
queuedTransitionTypes = null;
36+
export function claimQueuedTransitionTypes(
37+
root: FiberRoot,
38+
): null | TransitionTypes {
39+
const claimed = root.transitionTypes;
40+
root.transitionTypes = null;
3741
return claimed;
3842
}

packages/react-reconciler/src/ReactFiberWorkLoop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,7 @@ function commitRoot(
34053405
pendingViewTransitionEvents = null;
34063406
if (includesOnlyViewTransitionEligibleLanes(lanes)) {
34073407
// Claim any pending Transition Types for this commit.
3408-
pendingTransitionTypes = claimQueuedTransitionTypes();
3408+
pendingTransitionTypes = claimQueuedTransitionTypes(root);
34093409
passiveSubtreeMask = PassiveTransitionMask;
34103410
} else {
34113411
pendingTransitionTypes = null;

packages/react-reconciler/src/ReactInternalTypes.js

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
ReactComponentInfo,
1919
ReactDebugInfo,
2020
} from 'shared/ReactTypes';
21+
import type {TransitionTypes} from 'react/src/ReactTransitionType';
2122
import type {WorkTag} from './ReactWorkTags';
2223
import type {TypeOfMode} from './ReactTypeOfMode';
2324
import type {Flags} from './ReactFiberFlags';
@@ -280,6 +281,8 @@ type BaseFiberRootProperties = {
280281

281282
formState: ReactFormState<any, any> | null,
282283

284+
// enableViewTransition only
285+
transitionTypes: null | TransitionTypes, // TODO: Make this a LaneMap.
283286
// enableGestureTransition only
284287
pendingGestures: null | ScheduledGesture,
285288
stoppingGestures: null | ScheduledGesture,

0 commit comments

Comments
 (0)