Skip to content

Clear pending timers on unmount in StatefulPressable - #4413

Merged
m-bert merged 13 commits into
mainfrom
@mbert/stateful-pressable-timer-cleanup
Aug 13, 2026
Merged

Clear pending timers on unmount in StatefulPressable#4413
m-bert merged 13 commits into
mainfrom
@mbert/stateful-pressable-timer-cleanup

Conversation

@m-bert

@m-bert m-bert commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Description

The stateful Pressable engine keeps four pending timers - longPressTimeoutRef, pressDelayTimeoutRef, hoverInTimeout and hoverOutTimeout - but never clears them on unmount. If the component unmounts while one is pending, the scheduled callback still fires (onPressIn / onLongPress / onHoverIn / onHoverOut, plus a setState), acting on a torn-down component.

This adds a cleanup effect that clears all four on unmount, matching the cleanup the Touchable-based engine already has.

Follow-up to #4411, flagged by CodeRabbit.

Test plan

Existing v3 suite passes (yarn test in packages/react-native-gesture-handler). No behavior change while mounted — the effect only cancels timers that would otherwise fire after unmount.

Copilot AI lite review requested due to automatic review settings August 13, 2026 07:39
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0a2c6bc3-b1f0-4be4-ac44-31331630ba27

📥 Commits

Reviewing files that changed from the base of the PR and between cb144a3 and 90a5007.

📒 Files selected for processing (1)
  • packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Fixed pending press and hover timers continuing after a pressable component is removed.
    • Prevented delayed long-press, press, and hover interactions from triggering after unmounting.

Walkthrough

StatefulPressable now clears pending press and hover timers when the component unmounts.

Changes

StatefulPressable cleanup

Layer / File(s) Summary
Unmount timer cleanup
packages/react-native-gesture-handler/src/v3/components/StatefulPressable.tsx
An unmount effect clears long-press, delayed-press, hover-in, and hover-out timeout handles.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: clearing pending timers when StatefulPressable unmounts.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

This PR prevents StatefulPressable’s delayed callbacks from firing after the component unmounts by adding an unmount cleanup that clears pending press/hover timers, aligning behavior with the Touchable-based engine.

Changes:

  • Add a useEffect unmount cleanup to clear longPressTimeoutRef, pressDelayTimeoutRef, hoverInTimeout, and hoverOutTimeout.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Base automatically changed from @mbert/pressable-wrapper to main August 13, 2026 08:16
@m-bert
m-bert merged commit 3f1bf74 into main Aug 13, 2026
6 checks passed
@m-bert
m-bert deleted the @mbert/stateful-pressable-timer-cleanup branch August 13, 2026 09:14
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.

3 participants