Skip to content

animationFrameScheduler incorrect behavior #6854

Open
@Dmi-tryBobrov

Description

@Dmi-tryBobrov

Describe the bug

AnimationFrameScheduler doesn't execute scheduled tasks under certain circumstances.

If AnimationFrameScheduler gets a new id (e.g. new task is scheduled) before the flush method empties current actions array in the do-while loop we encounter wrong behavior.
In this case we enter the recycleAsyncId method of AnimationFrameAction .
Then recycleAsyncId sets _scheduled field to undefined.
After that we add new actions to the actions array in requestAsyncId, start requestAnimationFrame and enter flush method again on browser repaint.
But this time actions array in the flush method has two types of action with different id's.
What is the most important is that the first element of the actions array has id which is different from the current frame id.
This leads us to false condition "action.id === flushId" (in do-while loop) because action.id is the id of the previous frame but flushId is the id of the current frame.
Since that moment we are unable to execute any action in the actions array and empty it.

Problem occured after commit e35f589
in src/internal/scheduler/AnimationFrameAction.ts lines 30-33

Expected behavior

Expected console log output:
default task
task1
task2
default task
task1
task2

Reproduction code

let reschedule = true;
function log() {
  console.log('default task');
  animationFrameScheduler.schedule(() => console.log('task1'));
  animationFrameScheduler.schedule(() => console.log('task2'));
  if (reschedule) {
    this.schedule();
    reschedule = false;
  }
}

animationFrameScheduler.schedule(log);

Reproduction URL

https://stackblitz.com/edit/1gjlhu?devtoolsheight=50&file=index.ts

Version

7.5.1

Environment

No response

Additional context

animationFrameScheduler from rxjs version 7.1.0 worked correctly in this case

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions