Remove fakeCallbackNode (#20799)
Don't need this, because sync tasks are never cancelled. We can do the same thing we do for microtask callbacks.
Andrew Clark committed
Feb 10, 2021 at 22:03 UTC
47dd9f44133845febfcb4f04c76cf9961131b2d2
4 files changed
+14
-24
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+4
-6
@@ -726,7 +726,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
726
// TODO: Temporary until we confirm this warning is not fired.
727
if (
728
existingCallbackNode == null &&
729
- existingCallbackPriority !== InputDiscreteLanePriority
729
+ existingCallbackPriority !== InputDiscreteLanePriority &&
730
+ existingCallbackPriority !== SyncLanePriority
731
) {
732
console.error(
733
'Expected scheduled callback to exist. This error is likely caused by a bug in React. Please file an issue.',
@@ -747,11 +748,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
748
if (newCallbackPriority === SyncLanePriority) {
749
// Special case: Sync React callbacks are scheduled on a special
750
// internal queue
750
-
751
- // TODO: After enableDiscreteEventMicroTasks lands, we can remove the fake node.
752
- newCallbackNode = scheduleSyncCallback(
753
- performSyncWorkOnRoot.bind(null, root),
754
- );
751
+ scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
752
+ newCallbackNode = null;
753
} else if (newCallbackPriority === SyncBatchedLanePriority) {
754
newCallbackNode = scheduleCallback(
755
ImmediateSchedulerPriority,
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+4
-6
@@ -726,7 +726,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
726
// TODO: Temporary until we confirm this warning is not fired.
727
if (
728
existingCallbackNode == null &&
729
- existingCallbackPriority !== InputDiscreteLanePriority
729
+ existingCallbackPriority !== InputDiscreteLanePriority &&
730
+ existingCallbackPriority !== SyncLanePriority
731
) {
732
console.error(
733
'Expected scheduled callback to exist. This error is likely caused by a bug in React. Please file an issue.',
@@ -747,11 +748,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
748
if (newCallbackPriority === SyncLanePriority) {
749
// Special case: Sync React callbacks are scheduled on a special
750
// internal queue
750
-
751
- // TODO: After enableDiscreteEventMicroTasks lands, we can remove the fake node.
752
- newCallbackNode = scheduleSyncCallback(
753
- performSyncWorkOnRoot.bind(null, root),
754
- );
751
+ scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
752
+ newCallbackNode = null;
753
} else if (newCallbackPriority === SyncBatchedLanePriority) {
754
newCallbackNode = scheduleCallback(
755
ImmediateSchedulerPriority,
packages/react-reconciler/src/SchedulerWithReactIntegration.new.js
+3
-6
@@ -57,8 +57,6 @@ export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
57
58
type SchedulerCallbackOptions = {timeout?: number, ...};
59
60
-const fakeCallbackNode = {};
61
-
60
// Except for NoPriority, these correspond to Scheduler priorities. We use
61
// ascending numbers so we can compare them like numbers. They start at 90 to
62
// avoid clashing with Scheduler's priorities.
@@ -147,6 +145,8 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
145
if (syncQueue === null) {
146
syncQueue = [callback];
147
// Flush the queue in the next tick, at the earliest.
148
+ // TODO: Figure out how to remove this It's only here as a last resort if we
149
+ // forget to explicitly flush.
150
immediateQueueCallbackNode = Scheduler_scheduleCallback(
151
Scheduler_ImmediatePriority,
152
flushSyncCallbackQueueImpl,
@@ -156,13 +156,10 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
156
// we already scheduled one when we created the queue.
157
syncQueue.push(callback);
158
}
159
- return fakeCallbackNode;
159
}
160
161
export function cancelCallback(callbackNode: mixed) {
163
- if (callbackNode !== fakeCallbackNode) {
164
- Scheduler_cancelCallback(callbackNode);
165
- }
162
+ Scheduler_cancelCallback(callbackNode);
163
}
164
165
export function flushSyncCallbackQueue() {
packages/react-reconciler/src/SchedulerWithReactIntegration.old.js
+3
-6
@@ -57,8 +57,6 @@ export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
57
58
type SchedulerCallbackOptions = {timeout?: number, ...};
59
60
-const fakeCallbackNode = {};
61
-
60
// Except for NoPriority, these correspond to Scheduler priorities. We use
61
// ascending numbers so we can compare them like numbers. They start at 90 to
62
// avoid clashing with Scheduler's priorities.
@@ -147,6 +145,8 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
145
if (syncQueue === null) {
146
syncQueue = [callback];
147
// Flush the queue in the next tick, at the earliest.
148
+ // TODO: Figure out how to remove this It's only here as a last resort if we
149
+ // forget to explicitly flush.
150
immediateQueueCallbackNode = Scheduler_scheduleCallback(
151
Scheduler_ImmediatePriority,
152
flushSyncCallbackQueueImpl,
@@ -156,13 +156,10 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
156
// we already scheduled one when we created the queue.
157
syncQueue.push(callback);
158
}
159
- return fakeCallbackNode;
159
}
160
161
export function cancelCallback(callbackNode: mixed) {
163
- if (callbackNode !== fakeCallbackNode) {
164
- Scheduler_cancelCallback(callbackNode);
165
- }
162
+ Scheduler_cancelCallback(callbackNode);
163
}
164
165
export function flushSyncCallbackQueue() {