Repository navigation
Conversation
`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 detectedLatest commit: 5251741 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2041
Problem
Sortable.animate()(FLIP) measures how far an item moved by comparing its shape before and after the DOM update:Both shapes come from
getBoundingClientRect(), sodeltais in screen pixels. It's then applied as atranslatekeyframe, which works in the coordinate space of the element's parent. When an ancestor is scaled, like the zoomable diagram in the issue withtransform: scale(2), the item starts its animationscaletimes 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 bygetFrameTransform(element)for scaled iframes, sinceDOMRectanglefolds the frame scale into the shape too. Without scaled ancestors the scale is1, so nothing changes for existing layouts.Rotated ancestors are out of scope: a bounding box isn't a scale there.
Tests
React/Sortable/Scaled: a sortable list insidetransform: scale(2), with a 2s linear transition so the animation can be inspected.apps/stories/tests/sortable-scaled.spec.ts. It drags item 1 over item 2, pauses item 2's sorting animation atcurrentTime = 0and asserts the item starts at its previous on-screen position, within 2px.main: fails, the animation starts 132px away (a full slot in screen pixels).sortable-iframeandsortable-transformed.packages/domunit tests: 88 pass.bun run buildpasses.tscreports no errors insortable.ts.@dnd-kit/dompatch.