Fix updating SharedValue crash#4315
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash when updating a SharedValue-backed enabled config in the v3 gesture API by ensuring runOnJS is invoked on the UI runtime (instead of being created on JS and then executed on UI), aligning with Reanimated/Worklets execution constraints.
Changes:
- Updates
useJSResponderHandlerto wrap the JS-side notifier viarunOnJSinside a UI worklet before registeringSharedValuelisteners. - Adjusts the
Reanimatedwrapper type to definerunOnJSas a function property type, enabling safe destructuring and usage in the hook.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/v3/hooks/useJSResponderHandler.ts | Moves runOnJS invocation into the UI worklet to prevent “Remote Function” synchronous call crashes when SharedValue changes. |
| packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts | Updates TypeScript typing for runOnJS to a property function type to support destructuring (const { runOnJS } = reanimated). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
j-piasecki
approved these changes
Jul 15, 2026
Comment on lines
+79
to
+81
| runOnJS: <A extends unknown[], R>( | ||
| fn: (...args: A) => R | ||
| ): (...args: Parameters<typeof fn>) => void; | ||
| ) => (...args: Parameters<typeof fn>) => void; |
Member
There was a problem hiding this comment.
Why change it to an arrow function?
Collaborator
Author
There was a problem hiding this comment.
Changed it to property so it can be destructured with { runOnJS } = reanimated
This file contains hidden or 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
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.
Description
#4158 added
useJSResponderHandler. The problem here is thatnotifyEnabledChangedis initialized asrunOnJS, and then passed to UI.runOnJSshould be executed on UI, otherwise app throws error:Test plan
Tested on the following example: