Remove eventTime field from class Update type (#26219)
`eventTime` is a vestigial field that can be cleaned up. It was originally used as part of the starvation mechanism but it's since been replaced by a per-lane field on the root. This is a part of a series of smaller refactors I'm doing to simplify/speed up the `setState` path, related to the Sync Unification project that @tyao1 has been working on.
Andrew Clark committed
Feb 22, 2023 at 15:32 UTC
c04b18070145b82111e1162729f4776f4d2c6112
6 files changed
+17
-29
packages/react-reconciler/src/ReactFiberClassComponent.js
+6
-6
@@ -198,10 +198,9 @@ const classComponentUpdater = {
198
// $FlowFixMe[missing-local-annot]
199
enqueueSetState(inst: any, payload: any, callback) {
200
const fiber = getInstance(inst);
201
- const eventTime = requestEventTime();
201
const lane = requestUpdateLane(fiber);
202
204
- const update = createUpdate(eventTime, lane);
203
+ const update = createUpdate(lane);
204
update.payload = payload;
205
if (callback !== undefined && callback !== null) {
206
if (__DEV__) {
@@ -212,6 +211,7 @@ const classComponentUpdater = {
211
212
const root = enqueueUpdate(fiber, update, lane);
213
if (root !== null) {
214
+ const eventTime = requestEventTime();
215
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
216
entangleTransitions(root, fiber, lane);
217
}
@@ -231,10 +231,9 @@ const classComponentUpdater = {
231
},
232
enqueueReplaceState(inst: any, payload: any, callback: null) {
233
const fiber = getInstance(inst);
234
- const eventTime = requestEventTime();
234
const lane = requestUpdateLane(fiber);
235
237
- const update = createUpdate(eventTime, lane);
236
+ const update = createUpdate(lane);
237
update.tag = ReplaceState;
238
update.payload = payload;
239
@@ -247,6 +246,7 @@ const classComponentUpdater = {
246
247
const root = enqueueUpdate(fiber, update, lane);
248
if (root !== null) {
249
+ const eventTime = requestEventTime();
250
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
251
entangleTransitions(root, fiber, lane);
252
}
@@ -267,10 +267,9 @@ const classComponentUpdater = {
267
// $FlowFixMe[missing-local-annot]
268
enqueueForceUpdate(inst: any, callback) {
269
const fiber = getInstance(inst);
270
- const eventTime = requestEventTime();
270
const lane = requestUpdateLane(fiber);
271
273
- const update = createUpdate(eventTime, lane);
272
+ const update = createUpdate(lane);
273
update.tag = ForceUpdate;
274
275
if (callback !== undefined && callback !== null) {
@@ -282,6 +281,7 @@ const classComponentUpdater = {
281
282
const root = enqueueUpdate(fiber, update, lane);
283
if (root !== null) {
284
+ const eventTime = requestEventTime();
285
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
286
entangleTransitions(root, fiber, lane);
287
}
packages/react-reconciler/src/ReactFiberClassUpdateQueue.js
+1
-11
@@ -127,9 +127,6 @@ import {setIsStrictModeForDevtools} from './ReactFiberDevToolsHook';
127
import assign from 'shared/assign';
128
129
export type Update<State> = {
130
- // TODO: Temporary field. Will remove this by storing a map of
131
- // transition -> event time on the root.
132
- eventTime: number,
130
lane: Lane,
131
132
tag: 0 | 1 | 2 | 3,
@@ -208,9 +205,8 @@ export function cloneUpdateQueue<State>(
205
}
206
}
207
211
-export function createUpdate(eventTime: number, lane: Lane): Update<mixed> {
208
+export function createUpdate(lane: Lane): Update<mixed> {
209
const update: Update<mixed> = {
213
- eventTime,
210
lane,
211
212
tag: UpdateState,
@@ -331,7 +327,6 @@ export function enqueueCapturedUpdate<State>(
327
let update: Update<State> = firstBaseUpdate;
328
do {
329
const clone: Update<State> = {
334
- eventTime: update.eventTime,
330
lane: update.lane,
331
332
tag: update.tag,
@@ -540,9 +535,6 @@ export function processUpdateQueue<State>(
535
536
let update: Update<State> = firstBaseUpdate;
537
do {
543
- // TODO: Don't need this field anymore
544
- const updateEventTime = update.eventTime;
545
-
538
// An extra OffscreenLane bit is added to updates that were made to
539
// a hidden tree, so that we can distinguish them from updates that were
540
// already there when the tree was hidden.
@@ -561,7 +553,6 @@ export function processUpdateQueue<State>(
553
// skipped update, the previous update/state is the new base
554
// update/state.
555
const clone: Update<State> = {
564
- eventTime: updateEventTime,
556
lane: updateLane,
557
558
tag: update.tag,
@@ -583,7 +574,6 @@ export function processUpdateQueue<State>(
574
575
if (newLastBaseUpdate !== null) {
576
const clone: Update<State> = {
586
- eventTime: updateEventTime,
577
// This update is going to be committed so we never want uncommit
578
// it. Using NoLane works because 0 is a subset of all bitmasks, so
579
// this will never be skipped by the check above.
packages/react-reconciler/src/ReactFiberHooks.js
+2
-2
@@ -2525,10 +2525,10 @@ function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T): void {
2525
case HostRoot: {
2526
// Schedule an update on the cache boundary to trigger a refresh.
2527
const lane = requestUpdateLane(provider);
2528
- const eventTime = requestEventTime();
2529
- const refreshUpdate = createLegacyQueueUpdate(eventTime, lane);
2528
+ const refreshUpdate = createLegacyQueueUpdate(lane);
2529
const root = enqueueLegacyQueueUpdate(provider, refreshUpdate, lane);
2530
if (root !== null) {
2531
+ const eventTime = requestEventTime();
2532
scheduleUpdateOnFiber(root, provider, lane, eventTime);
2533
entangleLegacyQueueTransitions(root, provider, lane);
2534
}
packages/react-reconciler/src/ReactFiberNewContext.js
+1
-2
@@ -26,7 +26,6 @@ import {
26
} from './ReactWorkTags';
27
import {
28
NoLanes,
29
- NoTimestamp,
29
isSubsetOfLanes,
30
includesSomeLane,
31
mergeLanes,
@@ -271,7 +270,7 @@ function propagateContextChange_eager<T>(
270
if (fiber.tag === ClassComponent) {
271
// Schedule a force update on the work-in-progress.
272
const lane = pickArbitraryLane(renderLanes);
274
- const update = createUpdate(NoTimestamp, lane);
273
+ const update = createUpdate(lane);
274
update.tag = ForceUpdate;
275
// TODO: Because we don't have a work-in-progress, this will add the
276
// update to the current fiber, too, which means it will persist even if
packages/react-reconciler/src/ReactFiberReconciler.js
+4
-4
@@ -308,11 +308,11 @@ export function createHydrationContainer(
308
// the update to schedule work on the root fiber (and, for legacy roots, to
309
// enqueue the callback if one is provided).
310
const current = root.current;
311
- const eventTime = requestEventTime();
311
const lane = requestUpdateLane(current);
313
- const update = createUpdate(eventTime, lane);
312
+ const update = createUpdate(lane);
313
update.callback =
314
callback !== undefined && callback !== null ? callback : null;
315
+ const eventTime = requestEventTime();
316
enqueueUpdate(current, update, lane);
317
scheduleInitialHydrationOnRoot(root, lane, eventTime);
318
@@ -329,7 +329,6 @@ export function updateContainer(
329
onScheduleRoot(container, element);
330
}
331
const current = container.current;
332
- const eventTime = requestEventTime();
332
const lane = requestUpdateLane(current);
333
334
if (enableSchedulingProfiler) {
@@ -360,7 +359,7 @@ export function updateContainer(
359
}
360
}
361
363
- const update = createUpdate(eventTime, lane);
362
+ const update = createUpdate(lane);
363
// Caution: React DevTools currently depends on this property
364
// being called "element".
365
update.payload = {element};
@@ -381,6 +380,7 @@ export function updateContainer(
380
381
const root = enqueueUpdate(current, update, lane);
382
if (root !== null) {
383
+ const eventTime = requestEventTime();
384
scheduleUpdateOnFiber(root, current, lane, eventTime);
385
entangleTransitions(root, current, lane);
386
}
packages/react-reconciler/src/ReactFiberThrow.js
+3
-4
@@ -69,7 +69,6 @@ import {logComponentSuspended} from './DebugTracing';
69
import {isDevToolsPresent} from './ReactFiberDevToolsHook';
70
import {
71
SyncLane,
72
- NoTimestamp,
72
includesSomeLane,
73
mergeLanes,
74
pickArbitraryLane,
@@ -86,7 +85,7 @@ function createRootErrorUpdate(
85
errorInfo: CapturedValue<mixed>,
86
lane: Lane,
87
): Update<mixed> {
89
- const update = createUpdate(NoTimestamp, lane);
88
+ const update = createUpdate(lane);
89
// Unmount the root by rendering null.
90
update.tag = CaptureUpdate;
91
// Caution: React DevTools currently depends on this property
@@ -105,7 +104,7 @@ function createClassErrorUpdate(
104
errorInfo: CapturedValue<mixed>,
105
lane: Lane,
106
): Update<mixed> {
108
- const update = createUpdate(NoTimestamp, lane);
107
+ const update = createUpdate(lane);
108
update.tag = CaptureUpdate;
109
const getDerivedStateFromError = fiber.type.getDerivedStateFromError;
110
if (typeof getDerivedStateFromError === 'function') {
@@ -253,7 +252,7 @@ function markSuspenseBoundaryShouldCapture(
252
// When we try rendering again, we should not reuse the current fiber,
253
// since it's known to be in an inconsistent state. Use a force update to
254
// prevent a bail out.
256
- const update = createUpdate(NoTimestamp, SyncLane);
255
+ const update = createUpdate(SyncLane);
256
update.tag = ForceUpdate;
257
enqueueUpdate(sourceFiber, update, SyncLane);
258
}