Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

animationFrameScheduler incorrect behavior #6854

Open
Dmi-tryBobrov opened this issue Mar 2, 2022 · 0 comments · May be fixed by #6889
Open

animationFrameScheduler incorrect behavior #6854

Dmi-tryBobrov opened this issue Mar 2, 2022 · 0 comments · May be fixed by #6889
Labels
bug Confirmed bug

Comments

@Dmi-tryBobrov
Copy link

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

@benlesh benlesh added the bug Confirmed bug label Mar 10, 2022
@benlesh benlesh assigned cartant and unassigned cartant Mar 10, 2022
ajafff added a commit to ajafff/rxjs that referenced this issue Mar 14, 2022
ajafff added a commit to ajafff/rxjs that referenced this issue Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants