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 with delay causes incorrect behavior (and exception) #6891

Open
ajafff opened this issue Mar 14, 2022 · 0 comments · May be fixed by #6892
Open

animationFrameScheduler with delay causes incorrect behavior (and exception) #6891

ajafff opened this issue Mar 14, 2022 · 0 comments · May be fixed by #6892

Comments

@ajafff
Copy link
Contributor

ajafff commented Mar 14, 2022

Describe the bug

If AnimationFrameScheduler#schedule is used with a delay > 0, the action is scheduled as AsyncAction. Executing the action takes the same code path as AnimationFrameAction.
So if the AsyncAction executes while AnimationFrameActions are scheduled, it executes those too, which is too early as the browser is not yet preparing the next frame.

With the fix in #6889 it will throw an error, when rAF tries to execute the actual AnimationFrameActions, but the queue is already empty:

Uncaught TypeError: Cannot read properties of undefined (reading 'execute')
      at AnimationFrameScheduler.flush (src\internal\scheduler\AnimationFrameScheduler.ts:24:27)
      at C:\code\rxjs\src\internal\scheduler\AnimationFrameAction.ts:21:121

Expected behavior

AsyncAction to be handled separately. Ideally we could use asyncScheduler.schedule(...) instead of super.request/recycleAsyncId.

Reproduction code

animationFrameScheduler.schedule(() => console.log('async'), 1);
animationFrameScheduler.schedule(() => console.log('animation frame'));

Reproduction URL

No response

Version

7.5.5

Environment

No response

Additional context

I could try to fix this, but I'm not sure how to test this properly. The code above flaky, because the timeout of 1ms is not guaranteed to be executed before the next animation frame. I guess I could mock the relevant animationFrameProvider

asapScheduler uses similar code, but seems not to be affected, because timeouts will never be executed before microtasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant