Skip to content

Commit

Permalink
Prevent double dragend race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Feb 8, 2025
1 parent c51778d commit 86ed6c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/prevent-double-dragend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dnd-kit/dom': patch
---

Fixed a regression in the `PointerSensor` where the same drag operation could fire a dragend event twice due to a race condition between `pointerup` and `lostpointercapture`.
4 changes: 2 additions & 2 deletions packages/dom/src/core/sensors/pointer/PointerSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class PointerSensor extends Sensor<
]);

const cleanup = () => {
setTimeout(unbindListeners);
unbindListeners();
this.#clearTimeout?.();
this.initialCoordinates = undefined;
};
Expand Down Expand Up @@ -242,7 +242,7 @@ export class PointerSensor extends Sensor<
// End the drag and drop operation
const {status} = this.manager.dragOperation;

if (!status.idle) {
if (status.dragging) {
// Prevent the default behaviour of the event
event.preventDefault();
event.stopPropagation();
Expand Down

0 comments on commit 86ed6c8

Please sign in to comment.