Skip to content

fix: crash when mount listener fires after GestureDetector unmount - #4268

Draft
kosmydel wants to merge 1 commit into
software-mansion:mainfrom
discord:kosmydel/fix-use-mount-reactions
Draft

fix: crash when mount listener fires after GestureDetector unmount#4268
kosmydel wants to merge 1 commit into
software-mansion:mainfrom
discord:kosmydel/fix-use-mount-reactions

Conversation

@kosmydel

@kosmydel kosmydel commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings June 17, 2026 12:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@kosmydel
kosmydel force-pushed the kosmydel/fix-use-mount-reactions branch 2 times, most recently from 0f3115f to a4b2c3f Compare July 31, 2026 12:06
@kosmydel kosmydel closed this Jul 31, 2026
@kosmydel
kosmydel force-pushed the kosmydel/fix-use-mount-reactions branch from a4b2c3f to a5545af Compare July 31, 2026 12:08
@kosmydel kosmydel reopened this Jul 31, 2026
@kosmydel kosmydel changed the title [General] Register mount reactions in layout effect to avoid crash on unmounted detector Fix crash when mount listener fires after GestureDetector unmount Jul 31, 2026
@kosmydel kosmydel changed the title Fix crash when mount listener fires after GestureDetector unmount fix: crash when mount listener fires after GestureDetector unmount Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants