Skip to content

Commit 47dd9f4

Browse files
authored
Remove fakeCallbackNode (#20799)
Don't need this, because sync tasks are never cancelled. We can do the same thing we do for microtask callbacks.
1 parent 114ab52 commit 47dd9f4

4 files changed

+14
-24
lines changed

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
726726
// TODO: Temporary until we confirm this warning is not fired.
727727
if (
728728
existingCallbackNode == null &&
729-
existingCallbackPriority !== InputDiscreteLanePriority
729+
existingCallbackPriority !== InputDiscreteLanePriority &&
730+
existingCallbackPriority !== SyncLanePriority
730731
) {
731732
console.error(
732733
'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) {
747748
if (newCallbackPriority === SyncLanePriority) {
748749
// Special case: Sync React callbacks are scheduled on a special
749750
// 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;
755753
} else if (newCallbackPriority === SyncBatchedLanePriority) {
756754
newCallbackNode = scheduleCallback(
757755
ImmediateSchedulerPriority,

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
726726
// TODO: Temporary until we confirm this warning is not fired.
727727
if (
728728
existingCallbackNode == null &&
729-
existingCallbackPriority !== InputDiscreteLanePriority
729+
existingCallbackPriority !== InputDiscreteLanePriority &&
730+
existingCallbackPriority !== SyncLanePriority
730731
) {
731732
console.error(
732733
'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) {
747748
if (newCallbackPriority === SyncLanePriority) {
748749
// Special case: Sync React callbacks are scheduled on a special
749750
// 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;
755753
} else if (newCallbackPriority === SyncBatchedLanePriority) {
756754
newCallbackNode = scheduleCallback(
757755
ImmediateSchedulerPriority,

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
5757

5858
type SchedulerCallbackOptions = {timeout?: number, ...};
5959

60-
const fakeCallbackNode = {};
61-
6260
// Except for NoPriority, these correspond to Scheduler priorities. We use
6361
// ascending numbers so we can compare them like numbers. They start at 90 to
6462
// avoid clashing with Scheduler's priorities.
@@ -147,6 +145,8 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
147145
if (syncQueue === null) {
148146
syncQueue = [callback];
149147
// 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.
150150
immediateQueueCallbackNode = Scheduler_scheduleCallback(
151151
Scheduler_ImmediatePriority,
152152
flushSyncCallbackQueueImpl,
@@ -156,13 +156,10 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
156156
// we already scheduled one when we created the queue.
157157
syncQueue.push(callback);
158158
}
159-
return fakeCallbackNode;
160159
}
161160

162161
export function cancelCallback(callbackNode: mixed) {
163-
if (callbackNode !== fakeCallbackNode) {
164-
Scheduler_cancelCallback(callbackNode);
165-
}
162+
Scheduler_cancelCallback(callbackNode);
166163
}
167164

168165
export function flushSyncCallbackQueue() {

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;
5757

5858
type SchedulerCallbackOptions = {timeout?: number, ...};
5959

60-
const fakeCallbackNode = {};
61-
6260
// Except for NoPriority, these correspond to Scheduler priorities. We use
6361
// ascending numbers so we can compare them like numbers. They start at 90 to
6462
// avoid clashing with Scheduler's priorities.
@@ -147,6 +145,8 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
147145
if (syncQueue === null) {
148146
syncQueue = [callback];
149147
// 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.
150150
immediateQueueCallbackNode = Scheduler_scheduleCallback(
151151
Scheduler_ImmediatePriority,
152152
flushSyncCallbackQueueImpl,
@@ -156,13 +156,10 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
156156
// we already scheduled one when we created the queue.
157157
syncQueue.push(callback);
158158
}
159-
return fakeCallbackNode;
160159
}
161160

162161
export function cancelCallback(callbackNode: mixed) {
163-
if (callbackNode !== fakeCallbackNode) {
164-
Scheduler_cancelCallback(callbackNode);
165-
}
162+
Scheduler_cancelCallback(callbackNode);
166163
}
167164

168165
export function flushSyncCallbackQueue() {

0 commit comments

Comments
 (0)