Skip to content

Commit c04b180

Browse files
authored
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.
1 parent 212b89f commit c04b180

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

packages/react-reconciler/src/ReactFiberClassComponent.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,9 @@ const classComponentUpdater = {
198198
// $FlowFixMe[missing-local-annot]
199199
enqueueSetState(inst: any, payload: any, callback) {
200200
const fiber = getInstance(inst);
201-
const eventTime = requestEventTime();
202201
const lane = requestUpdateLane(fiber);
203202

204-
const update = createUpdate(eventTime, lane);
203+
const update = createUpdate(lane);
205204
update.payload = payload;
206205
if (callback !== undefined && callback !== null) {
207206
if (__DEV__) {
@@ -212,6 +211,7 @@ const classComponentUpdater = {
212211

213212
const root = enqueueUpdate(fiber, update, lane);
214213
if (root !== null) {
214+
const eventTime = requestEventTime();
215215
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
216216
entangleTransitions(root, fiber, lane);
217217
}
@@ -231,10 +231,9 @@ const classComponentUpdater = {
231231
},
232232
enqueueReplaceState(inst: any, payload: any, callback: null) {
233233
const fiber = getInstance(inst);
234-
const eventTime = requestEventTime();
235234
const lane = requestUpdateLane(fiber);
236235

237-
const update = createUpdate(eventTime, lane);
236+
const update = createUpdate(lane);
238237
update.tag = ReplaceState;
239238
update.payload = payload;
240239

@@ -247,6 +246,7 @@ const classComponentUpdater = {
247246

248247
const root = enqueueUpdate(fiber, update, lane);
249248
if (root !== null) {
249+
const eventTime = requestEventTime();
250250
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
251251
entangleTransitions(root, fiber, lane);
252252
}
@@ -267,10 +267,9 @@ const classComponentUpdater = {
267267
// $FlowFixMe[missing-local-annot]
268268
enqueueForceUpdate(inst: any, callback) {
269269
const fiber = getInstance(inst);
270-
const eventTime = requestEventTime();
271270
const lane = requestUpdateLane(fiber);
272271

273-
const update = createUpdate(eventTime, lane);
272+
const update = createUpdate(lane);
274273
update.tag = ForceUpdate;
275274

276275
if (callback !== undefined && callback !== null) {
@@ -282,6 +281,7 @@ const classComponentUpdater = {
282281

283282
const root = enqueueUpdate(fiber, update, lane);
284283
if (root !== null) {
284+
const eventTime = requestEventTime();
285285
scheduleUpdateOnFiber(root, fiber, lane, eventTime);
286286
entangleTransitions(root, fiber, lane);
287287
}

packages/react-reconciler/src/ReactFiberClassUpdateQueue.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ import {setIsStrictModeForDevtools} from './ReactFiberDevToolsHook';
127127
import assign from 'shared/assign';
128128

129129
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,
133130
lane: Lane,
134131

135132
tag: 0 | 1 | 2 | 3,
@@ -208,9 +205,8 @@ export function cloneUpdateQueue<State>(
208205
}
209206
}
210207

211-
export function createUpdate(eventTime: number, lane: Lane): Update<mixed> {
208+
export function createUpdate(lane: Lane): Update<mixed> {
212209
const update: Update<mixed> = {
213-
eventTime,
214210
lane,
215211

216212
tag: UpdateState,
@@ -331,7 +327,6 @@ export function enqueueCapturedUpdate<State>(
331327
let update: Update<State> = firstBaseUpdate;
332328
do {
333329
const clone: Update<State> = {
334-
eventTime: update.eventTime,
335330
lane: update.lane,
336331

337332
tag: update.tag,
@@ -540,9 +535,6 @@ export function processUpdateQueue<State>(
540535

541536
let update: Update<State> = firstBaseUpdate;
542537
do {
543-
// TODO: Don't need this field anymore
544-
const updateEventTime = update.eventTime;
545-
546538
// An extra OffscreenLane bit is added to updates that were made to
547539
// a hidden tree, so that we can distinguish them from updates that were
548540
// already there when the tree was hidden.
@@ -561,7 +553,6 @@ export function processUpdateQueue<State>(
561553
// skipped update, the previous update/state is the new base
562554
// update/state.
563555
const clone: Update<State> = {
564-
eventTime: updateEventTime,
565556
lane: updateLane,
566557

567558
tag: update.tag,
@@ -583,7 +574,6 @@ export function processUpdateQueue<State>(
583574

584575
if (newLastBaseUpdate !== null) {
585576
const clone: Update<State> = {
586-
eventTime: updateEventTime,
587577
// This update is going to be committed so we never want uncommit
588578
// it. Using NoLane works because 0 is a subset of all bitmasks, so
589579
// this will never be skipped by the check above.

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,10 +2525,10 @@ function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T): void {
25252525
case HostRoot: {
25262526
// Schedule an update on the cache boundary to trigger a refresh.
25272527
const lane = requestUpdateLane(provider);
2528-
const eventTime = requestEventTime();
2529-
const refreshUpdate = createLegacyQueueUpdate(eventTime, lane);
2528+
const refreshUpdate = createLegacyQueueUpdate(lane);
25302529
const root = enqueueLegacyQueueUpdate(provider, refreshUpdate, lane);
25312530
if (root !== null) {
2531+
const eventTime = requestEventTime();
25322532
scheduleUpdateOnFiber(root, provider, lane, eventTime);
25332533
entangleLegacyQueueTransitions(root, provider, lane);
25342534
}

packages/react-reconciler/src/ReactFiberNewContext.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
} from './ReactWorkTags';
2727
import {
2828
NoLanes,
29-
NoTimestamp,
3029
isSubsetOfLanes,
3130
includesSomeLane,
3231
mergeLanes,
@@ -271,7 +270,7 @@ function propagateContextChange_eager<T>(
271270
if (fiber.tag === ClassComponent) {
272271
// Schedule a force update on the work-in-progress.
273272
const lane = pickArbitraryLane(renderLanes);
274-
const update = createUpdate(NoTimestamp, lane);
273+
const update = createUpdate(lane);
275274
update.tag = ForceUpdate;
276275
// TODO: Because we don't have a work-in-progress, this will add the
277276
// update to the current fiber, too, which means it will persist even if

packages/react-reconciler/src/ReactFiberReconciler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ export function createHydrationContainer(
308308
// the update to schedule work on the root fiber (and, for legacy roots, to
309309
// enqueue the callback if one is provided).
310310
const current = root.current;
311-
const eventTime = requestEventTime();
312311
const lane = requestUpdateLane(current);
313-
const update = createUpdate(eventTime, lane);
312+
const update = createUpdate(lane);
314313
update.callback =
315314
callback !== undefined && callback !== null ? callback : null;
315+
const eventTime = requestEventTime();
316316
enqueueUpdate(current, update, lane);
317317
scheduleInitialHydrationOnRoot(root, lane, eventTime);
318318

@@ -329,7 +329,6 @@ export function updateContainer(
329329
onScheduleRoot(container, element);
330330
}
331331
const current = container.current;
332-
const eventTime = requestEventTime();
333332
const lane = requestUpdateLane(current);
334333

335334
if (enableSchedulingProfiler) {
@@ -360,7 +359,7 @@ export function updateContainer(
360359
}
361360
}
362361

363-
const update = createUpdate(eventTime, lane);
362+
const update = createUpdate(lane);
364363
// Caution: React DevTools currently depends on this property
365364
// being called "element".
366365
update.payload = {element};
@@ -381,6 +380,7 @@ export function updateContainer(
381380

382381
const root = enqueueUpdate(current, update, lane);
383382
if (root !== null) {
383+
const eventTime = requestEventTime();
384384
scheduleUpdateOnFiber(root, current, lane, eventTime);
385385
entangleTransitions(root, current, lane);
386386
}

packages/react-reconciler/src/ReactFiberThrow.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ import {logComponentSuspended} from './DebugTracing';
6969
import {isDevToolsPresent} from './ReactFiberDevToolsHook';
7070
import {
7171
SyncLane,
72-
NoTimestamp,
7372
includesSomeLane,
7473
mergeLanes,
7574
pickArbitraryLane,
@@ -86,7 +85,7 @@ function createRootErrorUpdate(
8685
errorInfo: CapturedValue<mixed>,
8786
lane: Lane,
8887
): Update<mixed> {
89-
const update = createUpdate(NoTimestamp, lane);
88+
const update = createUpdate(lane);
9089
// Unmount the root by rendering null.
9190
update.tag = CaptureUpdate;
9291
// Caution: React DevTools currently depends on this property
@@ -105,7 +104,7 @@ function createClassErrorUpdate(
105104
errorInfo: CapturedValue<mixed>,
106105
lane: Lane,
107106
): Update<mixed> {
108-
const update = createUpdate(NoTimestamp, lane);
107+
const update = createUpdate(lane);
109108
update.tag = CaptureUpdate;
110109
const getDerivedStateFromError = fiber.type.getDerivedStateFromError;
111110
if (typeof getDerivedStateFromError === 'function') {
@@ -253,7 +252,7 @@ function markSuspenseBoundaryShouldCapture(
253252
// When we try rendering again, we should not reuse the current fiber,
254253
// since it's known to be in an inconsistent state. Use a force update to
255254
// prevent a bail out.
256-
const update = createUpdate(NoTimestamp, SyncLane);
255+
const update = createUpdate(SyncLane);
257256
update.tag = ForceUpdate;
258257
enqueueUpdate(sourceFiber, update, SyncLane);
259258
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy