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.
Andrew Clark committed
Mar 19, 2021 at 17:36 UTC
754e307284d5b4de32da1bd64c179885f6d9f253
4 files changed
+18
-48
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+8
@@ -89,6 +89,7 @@ import {
89
getCurrentEventPriority,
90
supportsMicrotasks,
91
errorHydratingContainer,
92
+ scheduleMicrotask,
93
} from './ReactFiberHostConfig';
94
95
import {
@@ -696,6 +697,13 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
697
// Special case: Sync React callbacks are scheduled on a special
698
// internal queue
699
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
+ }
707
newCallbackNode = null;
708
} else if (newCallbackPriority === SyncBatchedLanePriority) {
709
newCallbackNode = scheduleCallback(
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+8
@@ -89,6 +89,7 @@ import {
89
getCurrentEventPriority,
90
supportsMicrotasks,
91
errorHydratingContainer,
92
+ scheduleMicrotask,
93
} from './ReactFiberHostConfig';
94
95
import {
@@ -696,6 +697,13 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
697
// Special case: Sync React callbacks are scheduled on a special
698
// internal queue
699
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
+ }
707
newCallbackNode = null;
708
} else if (newCallbackPriority === SyncBatchedLanePriority) {
709
newCallbackNode = scheduleCallback(
packages/react-reconciler/src/SchedulerWithReactIntegration.new.js
+1
-24
@@ -20,7 +20,6 @@ import {
20
getCurrentUpdateLanePriority,
21
setCurrentUpdateLanePriority,
22
} from './ReactFiberLane.new';
23
-import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';
23
24
const {
25
unstable_scheduleCallback: Scheduler_scheduleCallback,
@@ -71,7 +70,6 @@ export const requestPaint =
70
Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : () => {};
71
72
let syncQueue: Array<SchedulerCallback> | null = null;
74
-let immediateQueueCallbackNode: mixed | null = null;
73
let isFlushingSyncQueue: boolean = false;
74
const initialTimeMs: number = Scheduler_now();
75
@@ -133,19 +131,6 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
131
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
132
if (syncQueue === null) {
133
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
- }
134
} else {
135
// Push onto existing queue. Don't need to schedule a callback because
136
// we already scheduled one when we created the queue.
@@ -158,15 +143,6 @@ export function cancelCallback(callbackNode: mixed) {
143
}
144
145
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() {
146
if (!isFlushingSyncQueue && syncQueue !== null) {
147
// Prevent re-entrancy.
148
isFlushingSyncQueue = true;
@@ -199,4 +175,5 @@ function flushSyncCallbackQueueImpl() {
175
isFlushingSyncQueue = false;
176
}
177
}
178
+ return null;
179
}
packages/react-reconciler/src/SchedulerWithReactIntegration.old.js
+1
-24
@@ -20,7 +20,6 @@ import {
20
getCurrentUpdateLanePriority,
21
setCurrentUpdateLanePriority,
22
} from './ReactFiberLane.old';
23
-import {scheduleMicrotask, supportsMicrotasks} from './ReactFiberHostConfig';
23
24
const {
25
unstable_scheduleCallback: Scheduler_scheduleCallback,
@@ -71,7 +70,6 @@ export const requestPaint =
70
Scheduler_requestPaint !== undefined ? Scheduler_requestPaint : () => {};
71
72
let syncQueue: Array<SchedulerCallback> | null = null;
74
-let immediateQueueCallbackNode: mixed | null = null;
73
let isFlushingSyncQueue: boolean = false;
74
const initialTimeMs: number = Scheduler_now();
75
@@ -133,19 +131,6 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
131
// the next tick, or earlier if something calls `flushSyncCallbackQueue`.
132
if (syncQueue === null) {
133
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
- }
134
} else {
135
// Push onto existing queue. Don't need to schedule a callback because
136
// we already scheduled one when we created the queue.
@@ -158,15 +143,6 @@ export function cancelCallback(callbackNode: mixed) {
143
}
144
145
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() {
146
if (!isFlushingSyncQueue && syncQueue !== null) {
147
// Prevent re-entrancy.
148
isFlushingSyncQueue = true;
@@ -199,4 +175,5 @@ function flushSyncCallbackQueueImpl() {
175
isFlushingSyncQueue = false;
176
}
177
}
178
+ return null;
179
}