Skip to content

fix: preserve pointer data when cancelling a drag - #831

Open
feritcemkahraman wants to merge 1 commit into
react-grid-layout:masterfrom
feritcemkahraman:fix/preserve-cancelled-drag-event
Open

feritcemkahraman wants to merge 1 commit into
react-grid-layout:masterfrom
feritcemkahraman:fix/preserve-cancelled-drag-event

Conversation

@feritcemkahraman

@feritcemkahraman feritcemkahraman commented Oct 20, 2026 •

Copy link
Copy Markdown

Returning false from onDrag creates a mouse-up event at (0, 0). For mouse drags, onStop therefore receives the wrong coordinates; for touch drags, the event has no matching touch identifier, so dragging never stops and subsequent moves still trigger callbacks.

Pass the original move event to handleDragStop so it retains the pointer coordinates and touch identifier. This also removes the synthetic-event fallback. Two regressions failed before the fix; all 206 unit tests and 23 Chromium browser tests now pass. ESLint, source/public types (React 18 and 19), CJS/ESM/declaration/UMD builds, and the build-contract checks pass.

Related to #486. Other browsers and the full Node-version matrix were not run.

Summary by CodeRabbit

  • Bug Fixes

    • Improved drag cancellation handling so the final position and movement changes are preserved when a drag ends unexpectedly.
    • Prevented additional movement notifications after a touch drag is canceled.
    • Prevented duplicate drag-stop notifications during cancellation or component removal.
  • Tests

    • Added coverage for mouse and touch drag cancellation scenarios, including final coordinates, movement changes, and callback behavior.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: be89e1e1-7364-4faf-a115-e23e2ac667c0
📥 Commits

Reviewing files that changed from the base of the PR and between 40829e3 and a4a6ea4.

📒 Files selected for processing: 2
  • lib/DraggableCore.tsx
  • test/DraggableCore.test.jsx

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

When a drag ends because onDrag returns false, handleDrag now passes the original event to handleDragStop. New tests cover mouse cancellation data and touch cancellation callbacks.

Changes: Drag cancellation

Layer / File(s) Summary
Stop event and cancellation tests
lib/DraggableCore.tsx, test/DraggableCore.test.jsx
handleDrag passes the original event to handleDragStop on cancellation. Tests verify that mouse cancellation preserves coordinates and deltas, and that touch cancellation suppresses later movement callbacks and duplicate stop callbacks.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: strml

Merge Risk: ⚪ Minimal · up to a4a6e

Cancelling a drag now preserves the real pointer coordinates and touch identifier, so onStop receives correct data. No actionable merge risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving pointer data when a drag is cancelled.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

lib/DraggableCore.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

test/DraggableCore.test.jsx

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

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.

This branch has not been deployed

No deployments
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.

1 participant