diff --git a/src/internal/scheduler/AnimationFrameAction.ts b/src/internal/scheduler/AnimationFrameAction.ts index f9b07be8ed..f9c8f8e39d 100644 --- a/src/internal/scheduler/AnimationFrameAction.ts +++ b/src/internal/scheduler/AnimationFrameAction.ts @@ -26,13 +26,14 @@ export class AnimationFrameAction extends AsyncAction { // If delay exists and is greater than 0, or if the delay is null (the // action wasn't rescheduled) but was originally scheduled as an async // action, then recycle as an async action. - if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) { + if (delay != null ? delay > 0 : this.delay > 0) { return super.recycleAsyncId(scheduler, id, delay); } // 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 (id != null && !scheduler.actions.some((action) => action.id === id)) { + const { actions } = scheduler; + if (id != null && actions[actions.length - 1]?.id !== id) { animationFrameProvider.cancelAnimationFrame(id as number); scheduler._scheduled = undefined; } diff --git a/src/internal/scheduler/AsapAction.ts b/src/internal/scheduler/AsapAction.ts index 503d306b2c..bd4b8697c3 100644 --- a/src/internal/scheduler/AsapAction.ts +++ b/src/internal/scheduler/AsapAction.ts @@ -26,13 +26,14 @@ export class AsapAction extends AsyncAction { // If delay exists and is greater than 0, or if the delay is null (the // action wasn't rescheduled) but was originally scheduled as an async // action, then recycle as an async action. - if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) { + if (delay != null ? delay > 0 : this.delay > 0) { return super.recycleAsyncId(scheduler, id, delay); } // 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 (id != null && !scheduler.actions.some((action) => action.id === id)) { + const { actions } = scheduler; + if (id != null && actions[actions.length - 1]?.id !== id) { immediateProvider.clearImmediate(id); scheduler._scheduled = undefined; }