-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix useFrameCallback cleanup #6143
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tomekzaw
approved these changes
Jun 20, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but let's wait for @piaskowyk's approval
piaskowyk
approved these changes
Jun 20, 2024
This was referenced Jul 21, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jul 24, 2024
## Summary #6143 was supposed to improve cleanup of `useFrameCallback` but also deleted a needed line - setting `callbackId` of callback registry to -1. Seems like some code is dependent on this value and it caused some crashes such as this one: #6143. I haven't found a reliable way to reproduce the issue since we got the info from issue creator's sentry. Nonetheless, analysis of the code has shown that we need to set the `callbackId` to -1 on cleanup, otherwise we perform operations that shouldn't be done anymore (e.g there's this check: https://github.com/software-mansion/react-native-reanimated/blob/818ed78870bf41b6255abdd16b153444761101b2/packages/react-native-reanimated/src/frameCallback/FrameCallbackRegistryUI.ts#L105-L107). ## Test plan As stated, the issue isn't really reproducible but the change doesn't risk any regression and time will tell if it fixes the problem
This was referenced Jul 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
useFrameCallback
had a bit faulty cleanup: it used ref.current during useEffect cleanup, when the ref value could as well be unreachable (already deallocated). I added thecallbackId
memoization + removed unnecessary setting it to -1.Test plan
useFrameCallback example
from Example App, as well as this code:Code