From dc2df8c68c391ef76b14519f44c02d251423bc68 Mon Sep 17 00:00:00 2001 From: Jakub Kosmydel Date: Fri, 31 Jul 2026 14:08:24 +0200 Subject: [PATCH] Fix crash when mount listener fires after GestureDetector unmount --- .../handlers/gestures/GestureDetector/useMountReactions.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/useMountReactions.ts b/packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/useMountReactions.ts index 84732ddbb1..12c37f7cdb 100644 --- a/packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/useMountReactions.ts +++ b/packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/useMountReactions.ts @@ -28,6 +28,12 @@ export function useMountReactions( ) { useEffect(() => { return MountRegistry.addMountListener((gesture) => { + // The detector may already be unmounted when this fires; bail out to avoid + // updating a detached detector. + if (!state.isMounted) { + return; + } + // At this point the ref in the gesture config should be updated, so we can check if one of the gestures // set in a relation with the gesture got mounted. If so, we need to update the detector to propagate // the changes to the native side.