Skip to content

fix: handle touchcancel to prevent stuck gesture state#320

Open
AnshuPriya-1 wants to merge 1 commit intoAOSSIE-Org:mainfrom
AnshuPriya-1:fix/touchcancel-clean
Open

fix: handle touchcancel to prevent stuck gesture state#320
AnshuPriya-1 wants to merge 1 commit intoAOSSIE-Org:mainfrom
AnshuPriya-1:fix/touchcancel-clean

Conversation

@AnshuPriya-1
Copy link
Contributor

@AnshuPriya-1 AnshuPriya-1 commented Mar 18, 2026

Addressed Issues:

Fixes #75

Description

This PR adds handling for the touchcancel event to ensure gesture state is properly reset when touch interactions are interrupted.

On mobile and touch devices, interactions may end with touchcancel instead of touchend due to:

  • system interruptions (notifications, app switch)
  • browser gesture takeover (scroll/zoom)
  • loss of window focus

Without handling this event, the app could remain in an inconsistent state (e.g., stuck dragging or pressed input).

Functional Verification

  • Gesture state resets correctly when touchcancel occurs
  • No stuck dragging or pressed input state after interruption
  • Normal gestures (tap, drag, scroll) still work correctly

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.

  • My code follows the project's code style and conventions

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • If applicable, I have made corresponding changes or additions to the documentation

  • If applicable, I have made corresponding changes or additions to tests

  • My changes generate no new warnings or errors

  • I have joined the discord and I will share a link to this PR with the project maintainers there

  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

Summary by CodeRabbit

  • Bug Fixes
    • Added support for cancelled touch events in trackpad handling. When touch interactions are interrupted, the system now properly resets all gesture tracking states (active touches, gesture state, pinch state, and drag timeouts), preventing stuck mouse states and improving touch interaction reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c255c8ae-21e0-4baf-9ccb-492437672b77

📥 Commits

Reviewing files that changed from the base of the PR and between 25b2382 and 8904822.

📒 Files selected for processing (2)
  • src/components/Trackpad/TouchArea.tsx
  • src/hooks/useTrackpadGesture.ts

Walkthrough

This PR adds touchcancel event handling to prevent stuck drag and pressed input states. The changes extend the TouchArea component props with an onTouchCancel handler and implement handleTouchCancel in useTrackpadGesture hook to reset all gesture, tracking, and pinch state.

Changes

Cohort / File(s) Summary
Touch Cancel Event Handler
src/components/Trackpad/TouchArea.tsx, src/hooks/useTrackpadGesture.ts
Added onTouchCancel handler to TouchArea props interface and implemented handleTouchCancel function that clears active touches, resets tracking state (isTracking, moved, releasedCount), resets pinch state (lastPinchDist, pinching), clears dragging timeout, releases active drag, and sends a final non-press click event.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

Typescript Lang

Poem

🐰 A touch falls silent mid-stride,
Cancelled by forces outside,
Now gentle reset brings peace,
No stuck drags—just release,
Clean state hops on with pride!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: handle touchcancel to prevent stuck gesture state' clearly and specifically describes the main change—adding touchcancel event handling to prevent gesture state issues.
Description check ✅ Passed The description addresses the linked issue and explains the problem, solution, and verification performed. However, some checklist items (comments, documentation, tests) are not completed.
Linked Issues check ✅ Passed The code changes fully address issue #75's objectives: handleTouchCancel clears active touches, resets tracking/gesture state, releases drag/press, and wires onTouchCancel into the public API.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to touchcancel handling; no modifications to existing touchstart/touchmove/touchend flows or unrelated functionality were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

@AnshuPriya-1
Copy link
Contributor Author

AnshuPriya-1 commented Mar 18, 2026

I was able to reproduce the issue on a touch-enabled device (mobile browser).

Steps:

  1. Start a drag gesture
  2. Interrupt interaction (e.g., notification panel / app switch / browser gesture)
  3. Observe that gesture state may remain active (e.g., drag stuck)

After this fix:

  • touchcancel properly resets the gesture state
  • no stuck drag or pressed input state occurs

This behavior is consistent with how touchcancel is expected to work in touch event lifecycle.

Tested on:

  • Android Chrome (mobile)
  • Touch-enabled browser

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.

[Bug]: Handle touchcancel to prevent stuck drag or pressed input state

1 participant