dnd-kit icon indicating copy to clipboard operation
dnd-kit copied to clipboard

fix: use fixed event listeners to address race conditions

Open chrisvxd opened this issue 1 year ago • 5 comments

Refactor the PointerSensor to use fixed event listeners, rather than dynamic ones, preventing race conditions that can occur if the document changed during drag, such as when dragging across frames.

To reproduce, rapidly drag items from the host to the iframe in the iframe stories.

chrisvxd avatar Dec 12 '24 16:12 chrisvxd

🦋 Changeset detected

Latest commit: e360a81be363ce8da12ac4b4665a69d80af8a6e8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@dnd-kit/dom Patch
@dnd-kit/react Patch
@dnd-kit/abstract Patch
@dnd-kit/collision Patch
@dnd-kit/geometry Patch
@dnd-kit/helpers Patch
@dnd-kit/state Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Dec 12 '24 16:12 changeset-bot[bot]

Moving back to draft as this change results in a bug, seen in https://github.com/measuredco/puck/issues/769. Unclear of resolution yet.

chrisvxd avatar Jan 13 '25 11:01 chrisvxd

Can you provide more specifics about what race conditions this PR was meant to solve? I did notice in the iframe story that sometimes if you released the pointer in a different frame than the one where the drag operation originated, the drag operation would never end. In those cases, the lostpointercapture event gets fired so I added some logic to end the drag operation when that is fired here cc13c26

clauderic avatar Feb 02 '25 03:02 clauderic

It's hard to provide specifics, as I was only able to replicate on certain devices in certain environments (I even noticed differences when using an external display vs not an external display). Removing the dynamic behaviour addressed the issue, and generally seemed like a more reliable approach.

I'm happy to try and reproduce with the updated PointerSensor, but what's the reason for sticking with dynamic?

chrisvxd avatar Feb 13 '25 12:02 chrisvxd

Unfortunately the latest dnd-kit (0.0.10-beta-20250212025300) still encounters this issue. Here's a video of the reproduction in Puck (wait for the 7th item to be added). It was previously possible to reproduce this in Storybook in the iframe story, although I haven't retested it this time.

https://github.com/user-attachments/assets/a440f899-a936-4ccb-8581-1b2df11d9b15

Using my custom PointerSensor still works.

chrisvxd avatar Feb 13 '25 12:02 chrisvxd