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

Add flashImmediateRunning flag to setupSetImmediate #4280

Merged
merged 3 commits into from
Mar 28, 2023

Conversation

mstach60161
Copy link
Contributor

@mstach60161 mstach60161 commented Mar 25, 2023

Summary

The problem is caused by recursive callMicrotasks calls.
Recursive calls appear when we have an event that trigger another event that calls callMicrotasks synchronously.
In result, we call the same microtasks array multiple times.
In some cases we get the wrong order of instructions and we end up with runRequested set on true without callbacks in the queue, so we never call queueMicrotask again.

The idea of fix is to set flag that inform us, that we are inside callMicrotasks call, so we don't execute the same callbacks again

Test plan

  • Created minimal repro using to Animated.ScrollView components. (one trigger another)
  • Tested on example from issue

@mstach60161 mstach60161 marked this pull request as ready for review March 27, 2023 16:30
Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two comments inline, can you please address these prior to merging?

src/reanimated2/threads.ts Outdated Show resolved Hide resolved
src/reanimated2/threads.ts Outdated Show resolved Hide resolved
@mstach60161 mstach60161 added this pull request to the merge queue Mar 28, 2023
Merged via the queue into main with commit 21bea38 Mar 28, 2023
@mstach60161 mstach60161 deleted the @mstach60161/fix-hooks-stop-running branch March 28, 2023 11:09
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
…#4280)

<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

- fixes software-mansion#4168 

The problem is caused by recursive `callMicrotasks` calls. 
Recursive calls appear when we have an event that trigger another event
that calls `callMicrotasks` synchronously.
In result, we call the same microtasks array multiple times. 
In some cases we get the wrong order of instructions and we end up with
`runRequested` set on `true` without callbacks in the queue, so we never
call `queueMicrotask` again.

The idea of fix is to set flag that inform us, that we are inside
`callMicrotasks` call, so we don't execute the same callbacks again

## Test plan

- Created minimal repro using to `Animated.ScrollView` components. (one
trigger another)
- Tested on example from issue
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 this pull request may close these issues.

hooks randomly stop running
2 participants