Repository navigation
Fix Reanimated subscriptions when replacing a mounted gesture - #4634
Conversation
Expose committed handler props to the retained NativeEventsManager before updating subscriptions. Reset previous props when effects attach again so Activity visibility changes do not leave stale or duplicate registrations. Add regression coverage for handler replacement, addition and removal, retained children, cleanup, and Activity reconnection.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused lifecycle fix and regression coverage address the stale subscriptions without identified blocking issues; tests were not independently executed.
No open issues 🎉
What changed in this PR
Fixes Reanimated subscriptions when worklet gestures change on a mounted v3 detector, preserving the detector and its child state.
Changes:
- Exposes the latest committed handler props to Reanimated’s retained event manager.
- Resets subscription bookkeeping when effects reconnect, including React
Activityreveals. - Adds regression tests for handler replacement, addition/removal, unchanged handlers, state preservation, and cleanup.
| File | Description |
|---|---|
packages/react-native-gesture-handler/src/v3/detectors/ReanimatedNativeDetector.tsx |
Keeps event-manager props current and resets previous props on effect setup. |
packages/react-native-gesture-handler/src/__tests__/reanimatedNativeDetector.test.tsx |
Tests subscription updates and lifecycle behavior using Reanimated’s real event manager. |
Review effort: Balanced
m-bert
left a comment
There was a problem hiding this comment.
Thank you for fixing this!
Description
Replacing one worklet gesture with another on a mounted
GestureDetectorleaves the new gesture's callbacks disconnected.NativeEventsManagerretains the component object created on mount, but itspropsstill points to the first set of worklet handlers. LaterupdateEventscalls therefore compare against stale props, and cleanup also reads that initial set.Expose the latest committed worklet props through a getter on the retained object. Update the ref before calling
updateEvents, so Reanimated can replace subscriptions while preserving the detector and its children. Set the current props and clear the previous props when the manager starts, including when React reconnects effects after anActivitybecomes visible.The regression uses Reanimated's real
NativeEventsManagerwith mocked worklet-handler registration methods. It covers repeated replacements, handler addition/removal, unchanged handlers, child state, and cleanup on unmount. ReactActivitytests also check that revealing a detector attaches its current handler exactly once.The standalone reproduction switches between two worklet pans on a retained detector and includes a remount control.
Test plan
ff34dbf), three tests fail: replacement, addition, and duplicate registration when a previously visibleActivityis revealed. With the fix, all five pass. Main (a83496b) has the same detector source.yarn workspace react-native-gesture-handler test --runInBand: 238 tests pass across 24 suites.ts-check,lint-js, andcircular-dependency-checkpass. Existing lint/dependency warnings remain.