@samitouri / QOS-React-2 / commits / 2bd88e38aa

[Scheduler] Bugfix: Cancelling a continuation (#16151)

Cancelling the original task should also cancel its continuation.

Andrew Clark committed Jul 22, 2019 at 13:10 UTC 2bd88e38aad28d4dc1fabd93a5dac0f32d812757
2 files changed +15 -8
packages/scheduler/src/Scheduler.js
+2 -8
@@ -144,14 +144,8 @@ function flushTask(task, currentTime) {
144 // with the same priority and expiration as the just-finished callback.
145 if (typeof continuationCallback === 'function') {
146 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;
149
150 // Insert the new callback into the list, sorted by its timeout. This is
151 // almost the same as the code in `scheduleCallback`, except the callback
packages/scheduler/src/__tests__/Scheduler-test.js
+13
@@ -275,6 +275,19 @@ describe('Scheduler', () => {
275 },
276 );
277
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 +
291 it('top-level immediate callbacks fire in a subsequent task', () => {
292 scheduleCallback(ImmediatePriority, () =>
293 Scheduler.unstable_yieldValue('A'),