Skip to content

Commit 2bd88e3

Browse files
authored
[Scheduler] Bugfix: Cancelling a continuation (#16151)
Cancelling the original task should also cancel its continuation.
1 parent 783b8f4 commit 2bd88e3

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

packages/scheduler/src/Scheduler.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,8 @@ function flushTask(task, currentTime) {
144144
// with the same priority and expiration as the just-finished callback.
145145
if (typeof continuationCallback === 'function') {
146146
var expirationTime = task.expirationTime;
147-
var continuationTask = {
148-
callback: continuationCallback,
149-
priorityLevel: task.priorityLevel,
150-
startTime: task.startTime,
151-
expirationTime,
152-
next: null,
153-
previous: null,
154-
};
147+
var continuationTask = task;
148+
continuationTask.callback = continuationCallback;
155149

156150
// Insert the new callback into the list, sorted by its timeout. This is
157151
// almost the same as the code in `scheduleCallback`, except the callback

packages/scheduler/src/__tests__/Scheduler-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,19 @@ describe('Scheduler', () => {
275275
},
276276
);
277277

278+
it('cancelling a continuation', () => {
279+
const task = scheduleCallback(NormalPriority, () => {
280+
Scheduler.unstable_yieldValue('Yield');
281+
return () => {
282+
Scheduler.unstable_yieldValue('Continuation');
283+
};
284+
});
285+
286+
expect(Scheduler).toFlushAndYieldThrough(['Yield']);
287+
cancelCallback(task);
288+
expect(Scheduler).toFlushWithoutYielding();
289+
});
290+
278291
it('top-level immediate callbacks fire in a subsequent task', () => {
279292
scheduleCallback(ImmediatePriority, () =>
280293
Scheduler.unstable_yieldValue('A'),

0 commit comments

Comments
 (0)