Repository navigation
Commit 991ccb5
authored
fix: crash when mount listener fires after GestureDetector unmount (#4268)
## Description
`useMountReactions` registers a `MountRegistry` listener in `useEffect`.
That listener can fire after the owning `GestureDetector` has already
unmounted (e.g. a related gesture mounts while this detector is gone).
Calling `updateDetector` in that case updates a detached detector and
can crash (occasionally in `findNodeHandle`).
Guard with the existing `state.isMounted` flag — the same pattern
`attachHandlers` already uses for the microtask after unmount.
Credit to @hannojg for the original investigation/fix direction.
## Changes
- In `useMountReactions`, return early from the mount listener when
`!state.isMounted`.
## Why not `useLayoutEffect`?
An earlier version of this PR also moved the subscription to
`useIsomorphicLayoutEffect` (same phase as GestureDetector attach/drop).
We A/B tested `useLayoutEffect` vs stock `useEffect`, both with this
early return. Crash rates were equivalent; the `isMounted` check alone
is sufficient, so this PR keeps `useEffect`.1 parent bc605eb commit 991ccb5
1 file changed
Lines changed: 6 additions & 0 deletions
File tree
- packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
0 commit comments