Fix gesture relations after freeze#4244
Open
m-bert wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where gesture relations (simultaneousWith, requireToFail, blocksHandlers) could stop working after a freeze/unfreeze cycle (e.g. freezeOnBlur from react-native-screens). It does so by avoiding in-place mutation of gesture.config when extracting relations, and by introducing a per-gesture snapshot of “direct” relations so composed gestures can rebuild relations each render without accumulating stale references (preventing the memory leak addressed in #3763).
Changes:
- Stop mutating
gesture.configinsideextractGestureRelations, returning extracted handler tags without overwriting the original relation refs. - Add
relationsSnapshottoBaseGestureto preserve the “directly defined” relation refs across composition and remounts. - Update
ComposedGesture.prepareSingleGestureto rebuild relation arrays fromrelationsSnapshoton eachprepare, preventing accumulation across renders.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/utils.ts | Makes relation extraction side-effect free to preserve relation refs for later re-resolution. |
| packages/react-native-gesture-handler/src/handlers/gestures/gestureComposition.ts | Rebuilds composed gesture relations from a captured snapshot to avoid stale-reference accumulation. |
| packages/react-native-gesture-handler/src/handlers/gestures/gesture.ts | Introduces relationsSnapshot on BaseGesture to persist direct relation refs across prepares/remounts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
#3763 fixed memory leak where gestures would keep stale references in their relations array. However, this approach introduced a bug where relations wouldn't be applied after freezing (like
freezeOnBlurfromreact-native-screens). This PR addresses this issue by fixing incorrectly applied relations without re-introducing memory-leaks.To do so, we create snapshot of relations at first render. It is later used to prepare relations during next renders.
Fixes #4238
Test plan
Tested on the following reproduction