Skip to content

Commit

Permalink
Remove fakeCallbackNode (#20799)
Browse files Browse the repository at this point in the history
Don't need this, because sync tasks are never cancelled. We can do the
same thing we do for microtask callbacks.
  • Loading branch information
acdlite authored Feb 11, 2021
1 parent 114ab52 commit 47dd9f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
10 changes: 4 additions & 6 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
// TODO: Temporary until we confirm this warning is not fired.
if (
existingCallbackNode == null &&
existingCallbackPriority !== InputDiscreteLanePriority
existingCallbackPriority !== InputDiscreteLanePriority &&
existingCallbackPriority !== SyncLanePriority
) {
console.error(
'Expected scheduled callback to exist. This error is likely caused by a bug in React. Please file an issue.',
Expand All @@ -747,11 +748,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
if (newCallbackPriority === SyncLanePriority) {
// Special case: Sync React callbacks are scheduled on a special
// internal queue

// TODO: After enableDiscreteEventMicroTasks lands, we can remove the fake node.
newCallbackNode = scheduleSyncCallback(
performSyncWorkOnRoot.bind(null, root),
);
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
newCallbackNode = null;
} else if (newCallbackPriority === SyncBatchedLanePriority) {
newCallbackNode = scheduleCallback(
ImmediateSchedulerPriority,
Expand Down
10 changes: 4 additions & 6 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
// TODO: Temporary until we confirm this warning is not fired.
if (
existingCallbackNode == null &&
existingCallbackPriority !== InputDiscreteLanePriority
existingCallbackPriority !== InputDiscreteLanePriority &&
existingCallbackPriority !== SyncLanePriority
) {
console.error(
'Expected scheduled callback to exist. This error is likely caused by a bug in React. Please file an issue.',
Expand All @@ -747,11 +748,8 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
if (newCallbackPriority === SyncLanePriority) {
// Special case: Sync React callbacks are scheduled on a special
// internal queue

// TODO: After enableDiscreteEventMicroTasks lands, we can remove the fake node.
newCallbackNode = scheduleSyncCallback(
performSyncWorkOnRoot.bind(null, root),
);
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
newCallbackNode = null;
} else if (newCallbackPriority === SyncBatchedLanePriority) {
newCallbackNode = scheduleCallback(
ImmediateSchedulerPriority,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;

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

const fakeCallbackNode = {};

// Except for NoPriority, these correspond to Scheduler priorities. We use
// ascending numbers so we can compare them like numbers. They start at 90 to
// avoid clashing with Scheduler's priorities.
Expand Down Expand Up @@ -147,6 +145,8 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
if (syncQueue === null) {
syncQueue = [callback];
// Flush the queue in the next tick, at the earliest.
// TODO: Figure out how to remove this It's only here as a last resort if we
// forget to explicitly flush.
immediateQueueCallbackNode = Scheduler_scheduleCallback(
Scheduler_ImmediatePriority,
flushSyncCallbackQueueImpl,
Expand All @@ -156,13 +156,10 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
// we already scheduled one when we created the queue.
syncQueue.push(callback);
}
return fakeCallbackNode;
}

export function cancelCallback(callbackNode: mixed) {
if (callbackNode !== fakeCallbackNode) {
Scheduler_cancelCallback(callbackNode);
}
Scheduler_cancelCallback(callbackNode);
}

export function flushSyncCallbackQueue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export type SchedulerCallback = (isSync: boolean) => SchedulerCallback | null;

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

const fakeCallbackNode = {};

// Except for NoPriority, these correspond to Scheduler priorities. We use
// ascending numbers so we can compare them like numbers. They start at 90 to
// avoid clashing with Scheduler's priorities.
Expand Down Expand Up @@ -147,6 +145,8 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
if (syncQueue === null) {
syncQueue = [callback];
// Flush the queue in the next tick, at the earliest.
// TODO: Figure out how to remove this It's only here as a last resort if we
// forget to explicitly flush.
immediateQueueCallbackNode = Scheduler_scheduleCallback(
Scheduler_ImmediatePriority,
flushSyncCallbackQueueImpl,
Expand All @@ -156,13 +156,10 @@ export function scheduleSyncCallback(callback: SchedulerCallback) {
// we already scheduled one when we created the queue.
syncQueue.push(callback);
}
return fakeCallbackNode;
}

export function cancelCallback(callbackNode: mixed) {
if (callbackNode !== fakeCallbackNode) {
Scheduler_cancelCallback(callbackNode);
}
Scheduler_cancelCallback(callbackNode);
}

export function flushSyncCallbackQueue() {
Expand Down

0 comments on commit 47dd9f4

Please sign in to comment.