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 race conditions with keyboard sensor #745

Merged
merged 1 commit into from
May 19, 2022

Conversation

clauderic
Copy link
Owner

The keyboard sensor now keeps track of the initial coordinates of the collision rect to provide a translate delta when move events are dispatched.

Previously the keyboard sensor would measure the initial rect of the active node and store its top and left properties as its initial coordinates it would then compare all subsequent move coordinates to calculate the delta.

This approach was flawed on a number of different levels:

  • It didn't respect the measuring configuration defined on the <DndContext> for the draggable node
  • Some consumers re-render the active node after dragging begins, which would lead to stale measurements
  • An error had to be thrown if there was no active node during the activation phase of the keyboard sensor. This shouldn't be a concern of the keyboard sensor.

@changeset-bot
Copy link

changeset-bot bot commented May 18, 2022

🦋 Changeset detected

Latest commit: 265ab1d

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

This PR includes changesets to release 3 packages
Name Type
@dnd-kit/core Major
@dnd-kit/modifiers Major
@dnd-kit/sortable Major

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

The keyboard sensor now keeps track of the initial coordinates of the collision rect to provide a translate delta when move events are dispatched.

Previously the keyboard sensor would measure the initial rect of the active node and store its top and left properties as its initial coordinates it would then compare all subsequent move coordinates to calculate the delta.

This approach was flawed on a number of different levels:

- It didn't respect the measuring configuration defined on the `<DndContext>` for the draggable node
- Some consumers re-render the active node after dragging begins, which would lead to stale measurements
- An error had to be thrown if there was no active node during the activation phase of the keyboard sensor. This shouldn't be a concern of the keyboard sensor.
@clauderic clauderic force-pushed the keyboard-sensor-race-conditions branch from e46d798 to 265ab1d Compare May 18, 2022 21:03
@clauderic clauderic merged commit 5f3c700 into master May 19, 2022
@clauderic clauderic deleted the keyboard-sensor-race-conditions branch May 19, 2022 01:11
@github-actions github-actions bot mentioned this pull request May 19, 2022
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

1 participant