Skip to content

Commit 754e307

Browse files
authored
Delete immediateQueueCallbackNode (#20980)
We don't need this anymore. It only existed so we could cancel the callback later. But canceling isn't necessary, was only an "optimization" for something that almost never happens in practice.
1 parent be5a2e2 commit 754e307

File tree

4 files changed

+18
-48
lines changed

4 files changed

+18
-48
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
getCurrentEventPriority,
9090
supportsMicrotasks,
9191
errorHydratingContainer,
92+
scheduleMicrotask,
9293
} from './ReactFiberHostConfig';
9394

9495
import {
@@ -696,6 +697,13 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
696697
// Special case: Sync React callbacks are scheduled on a special
697698
// internal queue
698699
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
700+
if (supportsMicrotasks) {
701+
// Flush the queue in a microtask.
702+
scheduleMicrotask(flushSyncCallbackQueue);
703+
} else {
704+
// Flush the queue in an Immediate task.
705+
scheduleCallback(ImmediateSchedulerPriority, flushSyncCallbackQueue);
706+
}
699707
newCallbackNode = null;
700708
} else if (newCallbackPriority === SyncBatchedLanePriority) {
701709
newCallbackNode = scheduleCallback(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
getCurrentEventPriority,
9090
supportsMicrotasks,
9191
errorHydratingContainer,
92+
scheduleMicrotask,
9293
} from './ReactFiberHostConfig';
9394

9495
import {
@@ -696,6 +697,13 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
696697
// Special case: Sync React callbacks are scheduled on a special
697698
// internal queue
698699
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
700+
if (supportsMicrotasks) {
701+
// Flush the queue in a microtask.
702+
scheduleMicrotask(flushSyncCallbackQueue);
703+
} else {
704+
// Flush the queue in an Immediate task.
705+
scheduleCallback(ImmediateSchedulerPriority, flushSyncCallbackQueue);
706+
}
699707
newCallbackNode = null;
700708
} else if (newCallbackPriority === SyncBatchedLanePriority) {
701709
newCallbackNode = scheduleCallback(

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
getCurrentUpdateLanePriority,
2121
setCurrentUpdateLanePriority,
2222
} from './ReactFiberLane.new';
23-
import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';
2423

2524
const {
2625
unstable_scheduleCallback: Scheduler_scheduleCallback,
@@ -71,7 +70,6 @@ export const requestPaint =
7170
Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : () => {};
7271

7372
let syncQueue: Array<SchedulerCallback> | null = null;
74-
let immediateQueueCallbackNode: mixed | null = null;
7573
let isFlushingSyncQueue: boolean = false;
7674
const initialTimeMs: number = Scheduler_now();
7775

@@ -133,19 +131,6 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
133131
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
134132
if (syncQueue === null) {
135133
syncQueue = [callback];
136-
137-
// TODO: Figure out how to remove this It's only here as a last resort if we
138-
// forget to explicitly flush.
139-
if (supportsMicrotasks) {
140-
// Flush the queue in a microtask.
141-
scheduleMicrotask(flushSyncCallbackQueueImpl);
142-
} else {
143-
// Flush the queue in the next tick.
144-
immediateQueueCallbackNode = Scheduler_scheduleCallback(
145-
Scheduler_ImmediatePriority,
146-
flushSyncCallbackQueueImpl,
147-
);
148-
}
149134
} else {
150135
// Push onto existing queue. Don't need to schedule a callback because
151136
// we already scheduled one when we created the queue.
@@ -158,15 +143,6 @@ export function cancelCallback(callbackNode: mixed) {
158143
}
159144

160145
export function flushSyncCallbackQueue() {
161-
if (immediateQueueCallbackNode !== null) {
162-
const node = immediateQueueCallbackNode;
163-
immediateQueueCallbackNode = null;
164-
Scheduler_cancelCallback(node);
165-
}
166-
flushSyncCallbackQueueImpl();
167-
}
168-
169-
function flushSyncCallbackQueueImpl() {
170146
if (!isFlushingSyncQueue && syncQueue !== null) {
171147
// Prevent re-entrancy.
172148
isFlushingSyncQueue = true;
@@ -199,4 +175,5 @@ function flushSyncCallbackQueueImpl() {
199175
isFlushingSyncQueue = false;
200176
}
201177
}
178+
return null;
202179
}

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
getCurrentUpdateLanePriority,
2121
setCurrentUpdateLanePriority,
2222
} from './ReactFiberLane.old';
23-
import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';
2423

2524
const {
2625
unstable_scheduleCallback: Scheduler_scheduleCallback,
@@ -71,7 +70,6 @@ export const requestPaint =
7170
Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : () => {};
7271

7372
let syncQueue: Array<SchedulerCallback> | null = null;
74-
let immediateQueueCallbackNode: mixed | null = null;
7573
let isFlushingSyncQueue: boolean = false;
7674
const initialTimeMs: number = Scheduler_now();
7775

@@ -133,19 +131,6 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
133131
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
134132
if (syncQueue === null) {
135133
syncQueue = [callback];
136-
137-
// TODO: Figure out how to remove this It's only here as a last resort if we
138-
// forget to explicitly flush.
139-
if (supportsMicrotasks) {
140-
// Flush the queue in a microtask.
141-
scheduleMicrotask(flushSyncCallbackQueueImpl);
142-
} else {
143-
// Flush the queue in the next tick.
144-
immediateQueueCallbackNode = Scheduler_scheduleCallback(
145-
Scheduler_ImmediatePriority,
146-
flushSyncCallbackQueueImpl,
147-
);
148-
}
149134
} else {
150135
// Push onto existing queue. Don't need to schedule a callback because
151136
// we already scheduled one when we created the queue.
@@ -158,15 +143,6 @@ export function cancelCallback(callbackNode: mixed) {
158143
}
159144

160145
export function flushSyncCallbackQueue() {
161-
if (immediateQueueCallbackNode !== null) {
162-
const node = immediateQueueCallbackNode;
163-
immediateQueueCallbackNode = null;
164-
Scheduler_cancelCallback(node);
165-
}
166-
flushSyncCallbackQueueImpl();
167-
}
168-
169-
function flushSyncCallbackQueueImpl() {
170146
if (!isFlushingSyncQueue && syncQueue !== null) {
171147
// Prevent re-entrancy.
172148
isFlushingSyncQueue = true;
@@ -199,4 +175,5 @@ function flushSyncCallbackQueueImpl() {
199175
isFlushingSyncQueue = false;
200176
}
201177
}
178+
return null;
202179
}

0 commit comments

Comments
 (0)