Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use fixed event listeners to address race conditions #1566

Open
wants to merge 1 commit into
base: experimental
Choose a base branch
from

Conversation

chrisvxd
Copy link

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.

Copy link

changeset-bot bot commented Dec 12, 2024

🦋 Changeset detected

Latest commit: fc86a6c

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

Comment on lines +108 to +119
for (const draggable of this.manager.registry.draggables.value) {
if (draggable.element) {
documents.add(getDocument(draggable.element));
}
}

for (const droppable of this.manager.registry.droppables.value) {
if (droppable.element) {
documents.add(getDocument(droppable.element));
}
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that this may be better elsewhere for perf reasons

Comment on lines +218 to +221
// Event may have duplicated between documents if user is bubbling events
if (doc !== ownerDocument) {
return;
}
Copy link
Author

@chrisvxd chrisvxd Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, new safe-guard to account for an edge-case where the user bubbles the pointermove event to the parent document (as I am doing with Puck).

I can address this on my end, but a safe-guard seemed sensible.

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