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

Modify reanimated props updates #6330

Merged
merged 9 commits into from
Jul 30, 2024

Conversation

bartlomiejbloniarz
Copy link
Contributor

@bartlomiejbloniarz bartlomiejbloniarz commented Jul 25, 2024

Summary

This PR changes the way performOperations and ReanimatedCommitHook are synchronized. The current implementations faces 2 problems:

  1. Updates that come through performOperations after pleaseSkipReanimatedCommit is called in the commit hook will be deferred until the next commit. Usually it's fine since the next commit will be triggered by the next animation frame. But if there was a singular update scheduled through Reanimated, we might not see the change for a long time. This issue is more thoroughly explained in this issue.

  2. In ReanimatedCommitMarker there is an assumption that there can be at most one commit happening on a given thread (i.e. there can't be nested commits). This isn't true, since there can be an event listener that commits some changes in a reaction to a native mount/unmount (which is a part of the commit function). This exact scenario was observed in the New Expensify App with react-native-keyboard-controller. At first I thought this is a mistake, but this PR in RN seems to allow for scenarios like that.

Applied fixes:

ad 1. Now instead of resetting the skip flag in reanimated after a transaction is mounted (via MountHook), we reset the flag whenever a non-empty batch is read in performOperations. This ensures that we don't make an unnecessary commit, but never skip any updates.

ad 2. Now we mark reanimated commits through ReanimatedCommitShadowNode. This is a class derived from ShadowNode that allows us to modify the root nodes traits_ (and add our custom trait). This ensures that even if the root node gets cloned it will retain the information. We couldn't derive from RootShadowNode since it is a final class.

closes #6245

Test plan

@bartlomiejbloniarz bartlomiejbloniarz requested review from piaskowyk, tjzel and tomekzaw and removed request for piaskowyk July 29, 2024 14:48
@bartlomiejbloniarz bartlomiejbloniarz marked this pull request as ready for review July 30, 2024 09:50
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.

Race condition in NativeReanimatedModule::performOperations()
2 participants