Fix drag position jump with memoized layout components#3616
Fix drag position jump with memoized layout components#3616mattgperry wants to merge 1 commit intomainfrom
Conversation
…hanges When a dragged element's component is memoized (e.g. by React.memo or rc-tree's internal optimization), willUpdate() is never called during sibling layout changes. This means the projection system has no snapshot, skips measurement, and the drag position goes uncompensated — causing the element to visually jump. Fix: before the update cycle's transform reset, mark animation-blocked (dragged) nodes as layout-dirty and use their previous layout as the snapshot. This ensures they participate in the measurement cycle and receive correct drag compensation via the didUpdate event. Fixes #3169 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR fixes a drag position jump that occurs when a memoized layout component (e.g., The fix introduces Key implementation details:
All existing tests pass and new E2E tests validate the fix across React 18 and 19. Confidence Score: 5/5
Last reviewed commit: 8c977b1 |
Summary
rc-tree) is being draggedReact.memo, parent state changes don't trigger itswillUpdate(), leaving the projection system without a snapshot — so layout compensation is silently skippedBug
Reported in #3169: dragging a file in an Ant Design Tree causes the element to jump to the wrong position when hovering over folders. The root cause is that
rc-treeinternally memoizes tree nodes — when a sibling's state changes (e.g., folder hover highlight), the dragged node doesn't re-render, sowillUpdate()is never called. Without a snapshot,notifyLayoutUpdate()returns early and the drag'sdidUpdatelistener never fires.Fix
In
create-projection-node.tsupdate(), before the transform reset step, iterate all nodes and for any that areisAnimationBlocked(set during drag) with a stale/missing snapshot:layoutas thesnapshotisLayoutDirty = trueandshouldResetTransform = trueThis ensures
resetTransform()→updateLayout()→notifyLayoutUpdate()all process the node, computing the correct layout delta and emitting thedidUpdateevent for drag compensation.Test plan
yarn buildsucceedsFixes #3169
🤖 Generated with Claude Code