From fb9abf2ae896388d99faaa2421e9a2eb11ff75f9 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Sun, 14 Nov 2021 08:24:29 +1000 Subject: [PATCH] fix: avoid calling flush with empty actions queue Closes #6672 --- src/internal/scheduler/AnimationFrameAction.ts | 8 ++++---- src/internal/scheduler/AsapAction.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/internal/scheduler/AnimationFrameAction.ts b/src/internal/scheduler/AnimationFrameAction.ts index 1ab54d82f6..771212f73d 100644 --- a/src/internal/scheduler/AnimationFrameAction.ts +++ b/src/internal/scheduler/AnimationFrameAction.ts @@ -27,10 +27,10 @@ export class AnimationFrameAction extends AsyncAction { if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) { return super.recycleAsyncId(scheduler, id, delay); } - // If the scheduler queue is empty, cancel the requested animation frame and - // set the scheduled flag to undefined so the next AnimationFrameAction will - // request its own. - if (scheduler.actions.length === 0) { + // If the scheduler queue has no remaining actions with the same async id, + // cancel the requested animation frame and set the scheduled flag to + // undefined so the next AnimationFrameAction will request its own. + if (!scheduler.actions.some((action) => action.id === id)) { animationFrameProvider.cancelAnimationFrame(id); scheduler._scheduled = undefined; } diff --git a/src/internal/scheduler/AsapAction.ts b/src/internal/scheduler/AsapAction.ts index a9239b0d56..f8f5116e50 100644 --- a/src/internal/scheduler/AsapAction.ts +++ b/src/internal/scheduler/AsapAction.ts @@ -27,10 +27,10 @@ export class AsapAction extends AsyncAction { if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) { return super.recycleAsyncId(scheduler, id, delay); } - // If the scheduler queue is empty, cancel the requested microtask and - // set the scheduled flag to undefined so the next AsapAction will schedule - // its own. - if (scheduler.actions.length === 0) { + // If the scheduler queue has no remaining actions with the same async id, + // cancel the requested microtask and set the scheduled flag to undefined + // so the next AsapAction will request its own. + if (!scheduler.actions.some((action) => action.id === id)) { immediateProvider.clearImmediate(id); scheduler._scheduled = undefined; }