Clear pending timers on unmount in StatefulPressable - #4413
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesStatefulPressable cleanup
Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
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
useEffectunmount cleanup to clearlongPressTimeoutRef,pressDelayTimeoutRef,hoverInTimeout, andhoverOutTimeout.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Description
The stateful Pressable engine keeps four pending timers -
longPressTimeoutRef,pressDelayTimeoutRef,hoverInTimeoutandhoverOutTimeout- but never clears them on unmount. If the component unmounts while one is pending, the scheduled callback still fires (onPressIn/onLongPress/onHoverIn/onHoverOut, plus asetState), 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 testinpackages/react-native-gesture-handler). No behavior change while mounted — the effect only cancels timers that would otherwise fire after unmount.