Skip to content

fix(dom): keep sortable animations stable inside scaled ancestors - #2184

Open
jhsgumban wants to merge 1 commit into
clauderic:mainfrom
jhsgumban:fix/sortable-animation-scaled-ancestor
Open

jhsgumban wants to merge 1 commit into
clauderic:mainfrom
jhsgumban:fix/sortable-animation-scaled-ancestor

Conversation

@jhsgumban

Copy link
Copy Markdown

Fixes #2041

Problem

Sortable.animate() (FLIP) measures how far an item moved by comparing its shape before and after the DOM update:

const delta = {
  x: shape.boundingRectangle.left - updatedShape.boundingRectangle.left,
  y: shape.boundingRectangle.top - updatedShape.boundingRectangle.top,
};

Both shapes come from getBoundingClientRect(), so delta is in screen pixels. It's then applied as a translate keyframe, which works in the coordinate space of the element's parent. When an ancestor is scaled, like the zoomable diagram in the issue with transform: scale(2), the item starts its animation scale times too far away and visibly jumps while sorting.

Change

Divide the delta by the scale that ancestors apply to the element before building the keyframes. A small private helper, getAncestorScale(), measures it on the closest ancestor with a layout box (getBoundingClientRect() size / offsetWidth, offsetHeight), multiplied by getFrameTransform(element) for scaled iframes, since DOMRectangle folds the frame scale into the shape too. Without scaled ancestors the scale is 1, so nothing changes for existing layouts.

Rotated ancestors are out of scope: a bounding box isn't a scale there.

Tests

  • New hidden story React/Sortable/Scaled: a sortable list inside transform: scale(2), with a 2s linear transition so the animation can be inspected.
  • New Playwright spec apps/stories/tests/sortable-scaled.spec.ts. It drags item 1 over item 2, pauses item 2's sorting animation at currentTime = 0 and asserts the item starts at its previous on-screen position, within 2px.
    • On main: fails, the animation starts 132px away (a full slot in screen pixels).
    • With this PR: passes.
  • Full Playwright suite (chromium): 74 passed, including sortable-iframe and sortable-transformed.
  • packages/dom unit tests: 88 pass. bun run build passes. tsc reports no errors in sortable.ts.
  • Changeset: @dnd-kit/dom patch.

`Sortable.animate()` measures how far an item moved with
getBoundingClientRect(), which is in screen pixels, and applies the
difference as a `translate` keyframe. `translate` is applied in the
coordinate space of the element's parent, so when an ancestor is scaled
(e.g. `transform: scale(2)` on a zoomable canvas) the offset was applied
`scale` times too far. Items started their animation a full slot away
and appeared to jump back and forth while sorting.

Divide the measured delta by the scale that ancestors apply to the
element (CSS transforms on the closest ancestor with a layout box,
combined with the frame transform for iframes).

Fixes clauderic#2041
@changeset-bot

changeset-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5251741

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

This PR includes changesets to release 10 packages
Name Type
@dnd-kit/dom Patch
@dnd-kit/abstract Patch
@dnd-kit/collision Patch
@dnd-kit/geometry Patch
@dnd-kit/helpers Patch
@dnd-kit/react Patch
@dnd-kit/solid Patch
@dnd-kit/state Patch
@dnd-kit/svelte Patch
@dnd-kit/vue 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

This branch has not been deployed

No deployments
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.

Sortable animations jump inside scaled parent container

1 participant