Skip to content

Commit db56bc3

Browse files
committed
Delete immediateQueueCallbackNode
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 edd0701 commit db56bc3

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
@@ -88,6 +88,7 @@ import {
8888
clearContainer,
8989
getCurrentEventPriority,
9090
supportsMicrotasks,
91+
scheduleMicrotask,
9192
} from './ReactFiberHostConfig';
9293

9394
import {
@@ -692,6 +693,13 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
692693
// Special case: Sync React callbacks are scheduled on a special
693694
// internal queue
694695
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
696+
if (supportsMicrotasks) {
697+
// Flush the queue in a microtask.
698+
scheduleMicrotask(flushSyncCallbackQueue);
699+
} else {
700+
// Flush the queue in an Immediate task.
701+
scheduleCallback(ImmediateSchedulerPriority, flushSyncCallbackQueue);
702+
}
695703
newCallbackNode = null;
696704
} else if (newCallbackPriority === SyncBatchedLanePriority) {
697705
newCallbackNode = scheduleCallback(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import {
8888
clearContainer,
8989
getCurrentEventPriority,
9090
supportsMicrotasks,
91+
scheduleMicrotask,
9192
} from './ReactFiberHostConfig';
9293

9394
import {
@@ -692,6 +693,13 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
692693
// Special case: Sync React callbacks are scheduled on a special
693694
// internal queue
694695
scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
696+
if (supportsMicrotasks) {
697+
// Flush the queue in a microtask.
698+
scheduleMicrotask(flushSyncCallbackQueue);
699+
} else {
700+
// Flush the queue in an Immediate task.
701+
scheduleCallback(ImmediateSchedulerPriority, flushSyncCallbackQueue);
702+
}
695703
newCallbackNode = null;
696704
} else if (newCallbackPriority === SyncBatchedLanePriority) {
697705
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)