Pass empty callbacks to UI when runOnJS is true#4326
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the v3 gesture hooks pipeline to avoid passing user callbacks into Reanimated’s UI runtime when runOnJS is statically true, preventing Reanimated from freezing objects captured in callback closures (and avoiding related worklets warnings).
Changes:
- Introduces an empty “UI callbacks” object and routes it to
Reanimated.useHandler/useReanimatedEventHandlerwhenconfig.runOnJS === true. - Keeps the original callbacks for the JS event handler path, so JS-side behavior remains intact.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+61
to
+64
| const uiCallbacks = | ||
| config.runOnJS === true | ||
| ? (EMPTY_UI_CALLBACKS as typeof callbacks) | ||
| : callbacks; |
j-piasecki
approved these changes
Jul 22, 2026
j-piasecki
left a comment
Member
There was a problem hiding this comment.
I assume that when runOnJS is switched on/off the hook is updated and the correct callbacks are run, right?
Collaborator
Author
Well, assuming that I tested it correctly then it does work 😅 |
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
Currently we call
useReanimatedEventHandlerwith original callbacks from config. However, objects captured in the callbacks' closures will be frozen by Reanimated as they will be passed to UI, even ifrunOnJSis set totrue. This triggers warning from worklets, as well as prevents modification of objects in closure.To fix that, we pass empty callbacks when
runOnJSistrue.Test plan
Tested on the following code: