Skip to content

[General] Register mount reactions in layout effect to avoid crash on unmounted detector#4268

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

[General] Register mount reactions in layout effect to avoid crash on unmounted detector#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

GestureDetector registered its mount listener in useEffect, while its attach/drop lifecycle runs in useIsomorphicLayoutEffect. Running in different phases meant the listener could fire after the detector unmounted, doing work against a detached detector (and occasionally crashing in findNodeHandle).

This moves the listener to useIsomorphicLayoutEffect (same phase as attach/drop) and adds a guard that bails out when state.isMounted is false.

Credit to @hannojg for the original fix. This PR upstreams it into the main repository

Test plan

  • yarn ts-check, yarn lint:js, and yarn test pass.
  • Verified gesture relations still update when a related gesture mounts, and rapid mount/unmount no longer updates a detached detector.

… unmounted detector

Run the GestureDetector mount listener in a layout effect (matching the
attach/drop phase) and bail out when the detector is no longer mounted,
preventing updates to a detached detector.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

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