Skip to content

Commit d3b8ff6

Browse files
authored
Unify BatchConfigTransition and Transition types (#32783)
This is some overdue refactoring. The two types never made sense. It also should be defined by isomorphic since it defines how it should be used by renderers rather than isomorphic depending on Fiber. Clean up hidden classes to be consistent. Fix missing name due to wrong types. I choose not to invoke the transition tracing callbacks if there's no name since the name is required there.
1 parent a7fa870 commit d3b8ff6

12 files changed

+100
-99
lines changed

packages/react-reconciler/src/ReactFiberActivityComponent.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
import type {ReactNodeList, OffscreenMode, Wakeable} from 'shared/ReactTypes';
1111
import type {Lanes} from './ReactFiberLane';
1212
import type {SpawnedCachePool} from './ReactFiberCacheComponent';
13-
import type {
14-
Transition,
15-
TracingMarkerInstance,
16-
} from './ReactFiberTracingMarkerComponent';
13+
import type {Transition} from 'react/src/ReactStartTransition';
14+
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent';
1715
import type {RetryQueue} from './ReactFiberSuspenseComponent';
1816

1917
export type OffscreenProps = {

packages/react-reconciler/src/ReactFiberAsyncAction.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
RejectedThenable,
1414
} from 'shared/ReactTypes';
1515
import type {Lane} from './ReactFiberLane';
16-
import type {BatchConfigTransition} from './ReactFiberTracingMarkerComponent';
16+
import type {Transition} from 'react/src/ReactStartTransition';
1717

1818
import {requestTransitionLane} from './ReactFiberRootScheduler';
1919
import {NoLane} from './ReactFiberLane';
@@ -46,7 +46,7 @@ let currentEntangledLane: Lane = NoLane;
4646
let currentEntangledActionThenable: Thenable<void> | null = null;
4747

4848
export function entangleAsyncAction<S>(
49-
transition: BatchConfigTransition,
49+
transition: Transition,
5050
thenable: Thenable<S>,
5151
): Thenable<S> {
5252
// `thenable` is the return value of the async action scope function. Create

packages/react-reconciler/src/ReactFiberCommitWork.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import type {
3030
} from './ReactFiberActivityComponent';
3131
import type {Cache} from './ReactFiberCacheComponent';
3232
import type {RootState} from './ReactFiberRoot';
33+
import type {Transition} from 'react/src/ReactStartTransition';
3334
import type {
34-
Transition,
3535
TracingMarkerInstance,
3636
TransitionAbort,
3737
} from './ReactFiberTracingMarkerComponent';

packages/react-reconciler/src/ReactFiberHooks.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ import {
149149
SuspenseActionException,
150150
} from './ReactFiberThenable';
151151
import type {ThenableState} from './ReactFiberThenable';
152-
import type {BatchConfigTransition} from './ReactFiberTracingMarkerComponent';
152+
import type {Transition} from 'react/src/ReactStartTransition';
153153
import {
154154
peekEntangledActionLane,
155155
peekEntangledActionThenable,
@@ -2137,11 +2137,15 @@ function runActionStateAction<S, P>(
21372137

21382138
// This is a fork of startTransition
21392139
const prevTransition = ReactSharedInternals.T;
2140-
const currentTransition: BatchConfigTransition = {};
2141-
ReactSharedInternals.T = currentTransition;
2140+
const currentTransition: Transition = ({}: any);
2141+
if (enableTransitionTracing) {
2142+
currentTransition.name = null;
2143+
currentTransition.startTime = -1;
2144+
}
21422145
if (__DEV__) {
2143-
ReactSharedInternals.T._updatedFibers = new Set();
2146+
currentTransition._updatedFibers = new Set();
21442147
}
2148+
ReactSharedInternals.T = currentTransition;
21452149
try {
21462150
const returnValue = action(prevState, payload);
21472151
const onStartTransitionFinish = ReactSharedInternals.S;
@@ -3012,7 +3016,15 @@ function startTransition<S>(
30123016
);
30133017

30143018
const prevTransition = ReactSharedInternals.T;
3015-
const currentTransition: BatchConfigTransition = {};
3019+
const currentTransition: Transition = ({}: any);
3020+
if (enableTransitionTracing) {
3021+
currentTransition.name =
3022+
options !== undefined && options.name !== undefined ? options.name : null;
3023+
currentTransition.startTime = now();
3024+
}
3025+
if (__DEV__) {
3026+
currentTransition._updatedFibers = new Set();
3027+
}
30163028

30173029
// We don't really need to use an optimistic update here, because we
30183030
// schedule a second "revert" update below (which we use to suspend the
@@ -3023,17 +3035,6 @@ function startTransition<S>(
30233035
ReactSharedInternals.T = currentTransition;
30243036
dispatchOptimisticSetState(fiber, false, queue, pendingState);
30253037

3026-
if (enableTransitionTracing) {
3027-
if (options !== undefined && options.name !== undefined) {
3028-
currentTransition.name = options.name;
3029-
currentTransition.startTime = now();
3030-
}
3031-
}
3032-
3033-
if (__DEV__) {
3034-
currentTransition._updatedFibers = new Set();
3035-
}
3036-
30373038
try {
30383039
const returnValue = callback();
30393040
const onStartTransitionFinish = ReactSharedInternals.S;

packages/react-reconciler/src/ReactFiberLane.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {Fiber, FiberRoot} from './ReactInternalTypes';
11-
import type {Transition} from './ReactFiberTracingMarkerComponent';
11+
import type {Transition} from 'react/src/ReactStartTransition';
1212
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates';
1313

1414
// TODO: Ideally these types would be opaque but that doesn't work well with

packages/react-reconciler/src/ReactFiberRootScheduler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type {FiberRoot} from './ReactInternalTypes';
1111
import type {Lane, Lanes} from './ReactFiberLane';
1212
import type {PriorityLevel} from 'scheduler/src/SchedulerPriorities';
13-
import type {BatchConfigTransition} from './ReactFiberTracingMarkerComponent';
13+
import type {Transition} from 'react/src/ReactStartTransition';
1414

1515
import {
1616
disableLegacyMode,
@@ -635,7 +635,7 @@ export function requestTransitionLane(
635635
// This argument isn't used, it's only here to encourage the caller to
636636
// check that it's inside a transition before calling this function.
637637
// TODO: Make this non-nullable. Requires a tweak to useOptimistic.
638-
transition: BatchConfigTransition | null,
638+
transition: Transition | null,
639639
): Lane {
640640
// The algorithm for assigning an update to a lane should be stable for all
641641
// updates at the same priority within the same event. To do this, the

packages/react-reconciler/src/ReactFiberTracingMarkerComponent.js

+48-44
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
Fiber,
1313
FiberRoot,
1414
} from './ReactInternalTypes';
15+
import type {Transition} from 'react/src/ReactStartTransition';
1516
import type {OffscreenInstance} from './ReactFiberActivityComponent';
1617
import type {StackCursor} from './ReactFiberStack';
1718

@@ -36,19 +37,6 @@ export type PendingTransitionCallbacks = {
3637
markerComplete: Map<string, Set<Transition>> | null,
3738
};
3839

39-
// TODO: Unclear to me why these are separate types
40-
export type Transition = {
41-
name: string,
42-
startTime: number,
43-
...
44-
};
45-
46-
export type BatchConfigTransition = {
47-
name?: string,
48-
startTime?: number,
49-
_updatedFibers?: Set<Fiber>,
50-
};
51-
5240
// TODO: Is there a way to not include the tag or name here?
5341
export type TracingMarkerInstance = {
5442
tag?: TracingMarkerTag,
@@ -79,9 +67,11 @@ export function processTransitionCallbacks(
7967
const transitionStart = pendingTransitions.transitionStart;
8068
const onTransitionStart = callbacks.onTransitionStart;
8169
if (transitionStart !== null && onTransitionStart != null) {
82-
transitionStart.forEach(transition =>
83-
onTransitionStart(transition.name, transition.startTime),
84-
);
70+
transitionStart.forEach(transition => {
71+
if (transition.name != null) {
72+
onTransitionStart(transition.name, transition.startTime);
73+
}
74+
});
8575
}
8676

8777
const markerProgress = pendingTransitions.markerProgress;
@@ -95,13 +85,15 @@ export function processTransitionCallbacks(
9585
? Array.from(markerInstance.pendingBoundaries.values())
9686
: [];
9787
markerInstance.transitions.forEach(transition => {
98-
onMarkerProgress(
99-
transition.name,
100-
markerName,
101-
transition.startTime,
102-
endTime,
103-
pending,
104-
);
88+
if (transition.name != null) {
89+
onMarkerProgress(
90+
transition.name,
91+
markerName,
92+
transition.startTime,
93+
endTime,
94+
pending,
95+
);
96+
}
10597
});
10698
}
10799
});
@@ -112,12 +104,14 @@ export function processTransitionCallbacks(
112104
if (markerComplete !== null && onMarkerComplete != null) {
113105
markerComplete.forEach((transitions, markerName) => {
114106
transitions.forEach(transition => {
115-
onMarkerComplete(
116-
transition.name,
117-
markerName,
118-
transition.startTime,
119-
endTime,
120-
);
107+
if (transition.name != null) {
108+
onMarkerComplete(
109+
transition.name,
110+
markerName,
111+
transition.startTime,
112+
endTime,
113+
);
114+
}
121115
});
122116
});
123117
}
@@ -153,12 +147,14 @@ export function processTransitionCallbacks(
153147
});
154148

155149
if (filteredAborts.length > 0) {
156-
onMarkerIncomplete(
157-
transition.name,
158-
markerName,
159-
transition.startTime,
160-
filteredAborts,
161-
);
150+
if (transition.name != null) {
151+
onMarkerIncomplete(
152+
transition.name,
153+
markerName,
154+
transition.startTime,
155+
filteredAborts,
156+
);
157+
}
162158
}
163159
});
164160
});
@@ -168,21 +164,29 @@ export function processTransitionCallbacks(
168164
const onTransitionProgress = callbacks.onTransitionProgress;
169165
if (onTransitionProgress != null && transitionProgress !== null) {
170166
transitionProgress.forEach((pending, transition) => {
171-
onTransitionProgress(
172-
transition.name,
173-
transition.startTime,
174-
endTime,
175-
Array.from(pending.values()),
176-
);
167+
if (transition.name != null) {
168+
onTransitionProgress(
169+
transition.name,
170+
transition.startTime,
171+
endTime,
172+
Array.from(pending.values()),
173+
);
174+
}
177175
});
178176
}
179177

180178
const transitionComplete = pendingTransitions.transitionComplete;
181179
const onTransitionComplete = callbacks.onTransitionComplete;
182180
if (transitionComplete !== null && onTransitionComplete != null) {
183-
transitionComplete.forEach(transition =>
184-
onTransitionComplete(transition.name, transition.startTime, endTime),
185-
);
181+
transitionComplete.forEach(transition => {
182+
if (transition.name != null) {
183+
onTransitionComplete(
184+
transition.name,
185+
transition.startTime,
186+
endTime,
187+
);
188+
}
189+
});
186190
}
187191
}
188192
}

packages/react-reconciler/src/ReactFiberTransition.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import type {Thenable} from 'shared/ReactTypes';
1111
import type {Lanes} from './ReactFiberLane';
1212
import type {StackCursor} from './ReactFiberStack';
1313
import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent';
14-
import type {
15-
BatchConfigTransition,
16-
Transition,
17-
} from './ReactFiberTracingMarkerComponent';
14+
import type {Transition} from 'react/src/ReactStartTransition';
1815

1916
import {enableTransitionTracing} from 'shared/ReactFeatureFlags';
2017
import {isPrimaryRenderer} from './ReactFiberConfig';
@@ -57,7 +54,7 @@ export const NoTransition = null;
5754
// reconciler. Leaving this for a future PR.
5855
const prevOnStartTransitionFinish = ReactSharedInternals.S;
5956
ReactSharedInternals.S = function onStartTransitionFinishForReconciler(
60-
transition: BatchConfigTransition,
57+
transition: Transition,
6158
returnValue: mixed,
6259
) {
6360
if (
@@ -81,7 +78,7 @@ ReactSharedInternals.S = function onStartTransitionFinishForReconciler(
8178
}
8279
};
8380

84-
export function requestCurrentTransition(): BatchConfigTransition | null {
81+
export function requestCurrentTransition(): Transition | null {
8582
return ReactSharedInternals.T;
8683
}
8784

packages/react-reconciler/src/ReactFiberWorkLoop.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import type {Fiber, FiberRoot} from './ReactInternalTypes';
1414
import type {Lanes, Lane} from './ReactFiberLane';
1515
import type {SuspenseState} from './ReactFiberSuspenseComponent';
1616
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks';
17+
import type {Transition} from 'react/src/ReactStartTransition';
1718
import type {
1819
PendingTransitionCallbacks,
1920
PendingBoundaries,
20-
Transition,
2121
TransitionAbort,
2222
} from './ReactFiberTracingMarkerComponent';
2323
import type {OffscreenInstance} from './ReactFiberActivityComponent';
@@ -927,8 +927,6 @@ export function scheduleUpdateOnFiber(
927927
transition.startTime = now();
928928
}
929929

930-
// $FlowFixMe[prop-missing]: The BatchConfigTransition and Transition types are incompatible but was previously untyped and thus uncaught
931-
// $FlowFixMe[incompatible-call]: "
932930
addTransitionToLanesMap(root, transition, lane);
933931
}
934932
}

packages/react-reconciler/src/ReactInternalTypes.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ import type {
3333
TransitionStatus,
3434
} from './ReactFiberConfig';
3535
import type {Cache} from './ReactFiberCacheComponent';
36-
import type {
37-
TracingMarkerInstance,
38-
Transition,
39-
} from './ReactFiberTracingMarkerComponent';
36+
import type {Transition} from 'react/src/ReactStartTransition';
37+
import type {TracingMarkerInstance} from './ReactFiberTracingMarkerComponent';
4038
import type {ConcurrentUpdate} from './ReactFiberConcurrentUpdates';
4139
import type {ComponentStackNode} from 'react-server/src/ReactFizzComponentStack';
4240
import type {ThenableState} from './ReactFiberThenable';

packages/react/src/ReactSharedInternalsClient.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
12-
import type {BatchConfigTransition} from 'react-reconciler/src/ReactFiberTracingMarkerComponent';
12+
import type {Transition} from './ReactStartTransition';
1313
import type {TransitionTypes} from './ReactTransitionType';
1414

1515
export type SharedStateClient = {
1616
H: null | Dispatcher, // ReactCurrentDispatcher for Hooks
1717
A: null | AsyncDispatcher, // ReactCurrentCache for Cache
18-
T: null | BatchConfigTransition, // ReactCurrentBatchConfig for Transitions
19-
S: null | ((BatchConfigTransition, mixed) => void), // onStartTransitionFinish
18+
T: null | Transition, // ReactCurrentBatchConfig for Transitions
19+
S: null | ((Transition, mixed) => void), // onStartTransitionFinish
2020
V: null | TransitionTypes, // Pending Transition Types for the Next Transition
2121

2222
// DEV-only

0 commit comments

Comments
 (0)