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 issue with over being null in onDragEnd #1167

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

Conversation

adrianmxb
Copy link

I am currently implementing drag and drop behavior within our application and I've noticed that sometimes the over property is set to null. Found a issue for this one as well: #391

After some investigation, I was able to reproduce this on storybook in the MultipleContainers example as well, as I first thought I made a mistake in the implementation. Its very hard to reliably reproduce it so pardon me for not providing a codesandbox. I tried writing a test for this but it turns out this is not very easy to achieve.

Ways on how to reproduce (takes quite some time):

  1. Do a very fast click (mouse down, mouse up) on a Draggable.
  2. The over property you get through onDragEnd is sometimes null.

It really feels like a timing issue, since the sensorContext.over is set through this useIsomorphicLayoutEffect:

useIsomorphicLayoutEffect(() => {
sensorContext.current = {
activatorEvent,
active,
activeNode,
collisionRect,
collisions,
droppableRects,
draggableNodes,
draggingNode,
draggingNodeRect,
droppableContainers,
over,
scrollableAncestors,
scrollAdjustedTranslate,
};
activeRects.current = {
initial: draggingNodeRect,
translated: collisionRect,
};
}, [
active,
activeNode,
collisions,
collisionRect,
draggableNodes,
draggingNode,
draggingNodeRect,
droppableRects,
droppableContainers,
over,
scrollableAncestors,
scrollAdjustedTranslate,
]);

By setting over directly in the sensorContext instead of relying on the useIsomorphicLayoutEffect to fire before the onDragEnd callback is called.

@changeset-bot
Copy link

changeset-bot bot commented Jun 29, 2023

🦋 Changeset detected

Latest commit: ef41376

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

This PR includes changesets to release 1 package
Name Type
@dnd-kit/core 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

@balexand
Copy link

I'm also having problems with over being null in onDragEnd due to an inconsistently reproducible timing issue. This pull-request does not fix the issue and doesn't seem like the correct approach.

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.

None yet

2 participants