[General] Fix gestures becoming unresponsive after a fast refresh#4096
Open
j-piasecki wants to merge 1 commit intomainfrom
Open
[General] Fix gestures becoming unresponsive after a fast refresh#4096j-piasecki wants to merge 1 commit intomainfrom
j-piasecki wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Fast Refresh regression where Reanimated gesture worklet event handlers could become stale and ignore events after a regenerated handlerTag.
Changes:
- Track
handlerTagchanges viauseRef+useEffectto detect post-refresh tag regeneration. - Force
Reanimated.useEventto rebuild the worklet event handler when thehandlerTagchanges. - Deduplicate the Reanimated event names into a shared constant.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
82
to
86
| const reanimatedEvent = Reanimated?.useEvent( | ||
| callback, | ||
| [ | ||
| 'onGestureHandlerReanimatedEvent', | ||
| 'onGestureHandlerReanimatedStateChange', | ||
| 'onGestureHandlerReanimatedTouchEvent', | ||
| ], | ||
| !!reanimatedHandler?.doDependenciesDiffer | ||
| REANIMATED_EVENT_NAMES, | ||
| handlerTagChanged || !!reanimatedHandler?.doDependenciesDiffer | ||
| ); |
There was a problem hiding this comment.
Consider adding a unit test for this regression by mocking Reanimated.useEvent and asserting the third argument (rebuild) flips to true when handlerTag changes between renders (simulating Fast Refresh preserving refs). This would prevent future changes from reintroducing the stale-closure issue.
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
Fast refresh was able to make gestures unresponsive - Gesture Handler uses
useMemoto store the handler tag, which gets invalidated on the fast refresh. Reanimated'suseHandler/useEventpreserves their internal state, and the worklet event handler didn't rebuild. This caused a gesture with a new tag to use the event handler built for the previous tag, which was ignoring all incoming events.This PR fixes this by tracking handler tag changes and rebuilding the event handler when it changes.
Supersedes #3997
Test plan
File1.tsx
File2.tsx
File2COMMENT_THISand saveFile1