Skip to content

[Stacked on #391] Use dnd-kit's native DragOverlay for drag previews - #392

Closed
ccombe wants to merge 4 commits into
jameskerr:mainfrom
ccombe:drag-overlay-modernization
Closed

ccombe wants to merge 4 commits into
jameskerr:mainfrom
ccombe:drag-overlay-modernization

Conversation

@ccombe

@ccombe ccombe commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #391. Read the delta, not the file count.
The 26 files in Files changed are #391 plus this PR. This PR's own change is 6 files, +61 −189, after #391's head 991d23d:
git diff migrate-to-dnd-kit drag-overlay-modernization --stat

GitHub cannot base a PR on migrate-to-dnd-kit, because that branch exists only on the fork and the base has to be a branch of jameskerr/react-arborist (attempting it returns Proposed base branch 'migrate-to-dnd-kit' was not found). So the base stays main and the diff carries #391's commits until #391 merges. Once it does, this branch is rebased onto main and un-drafted, and the diff shows those 6 files.

Part 2 of the @dnd-kit migration stack (#390).

Summary

Replaces the custom fixed-viewport drag preview with @dnd-kit/core's <DragOverlay>.

Changes

  • components/drag-preview-container.tsx: renders the preview inside <DragOverlay dropAnimation={null}>, taking the dragged id from useDndContext().
  • components/default-drag-preview.tsx: drops the manual translate(x, y) styles and the fixed viewport layer; the overlay positions itself.
  • components/provider.tsx: removes dragPreviewState, INITIAL_DRAG_PREVIEW_STATE, DragPreviewContext wiring and the preview offset math. Keeps the pointer tracking from Migrate drag and drop from react-dnd to @dnd-kit #391, which still feeds computeDrop through updateHover.
  • context.ts: removes DragPreviewContext and useDragPreviewState.
  • dnd/dnd-provider.test.tsx: awaits act so the overlay's lifecycle updates flush; drops the test that asserted the tree-computed preview offset.

Test note

#391 adds a scroll mid-drag test that asserts the preview's translate transform, because the tree computed that offset itself. With DragOverlay, dnd-kit positions the preview and deliberately folds scroll into its transform, so that assertion no longer describes this branch's behavior and the test is removed here. The pointer fix it guards (feeding the real pointer, not activator + delta, to computeDrop) is unchanged and still exercised by the hover and drop tests; if you want the scroll case covered after this lands, the assertion has to target the computed drop rather than the preview's transform.

Verification

  • yarn workspace react-arborist test: 12 suites, 137 tests passing, warning-free.
  • yarn workspace showcase build + xvfb-run yarn workspace e2e test: 3 specs, 17 tests passing.
  • yarn lint, yarn fmt:check: clean.

@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for react-arborist ready!

Name Link
🔨 Latest commit 6357a27
🔍 Latest deploy log https://app.netlify.com/projects/react-arborist/deploys/6ae1d5b55f2362185c52fc5c
😎 Deploy Preview https://deploy-preview-392--react-arborist.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ccombe
ccombe force-pushed the drag-overlay-modernization branch from 220edab to b77a3a1 Compare October 21, 2026 09:26
Each Tree now always owns its DndContext. Removes the parent-context
detection that relied on dnd-kit's internal noop stubs, the
treeCollisionDetection export, and the dndBackend/dndManager/
dndRootElement props. Deletes the drag-out showcase and its spec, which
depended on sharing one context with the app.

Tracks the real pointer during a drag instead of deriving it from
activator coordinates plus event.delta, which dnd-kit folds scroll
adjustments into. Defaults to a pointer sensor only: KeyboardSensor
started a drag on Space or Enter, swallowing the tree's own commands.
The drag listeners now receive the target and event methods the
activators touch.

Adds tests for a scroll mid-drag, a source row unmounting during a drag,
and Space/Enter on a nested button.
@ccombe
ccombe force-pushed the drag-overlay-modernization branch from b77a3a1 to 6357a27 Compare October 28, 2026 11:00
@ccombe ccombe changed the title Use @dnd-kit native DragOverlay for drag previews (Stack 2/4) [Stacked on #391] Use dnd-kit's native DragOverlay for drag previews Oct 28, 2026
@ccombe

ccombe commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Folding this into #391 rather than keeping it as a stacked draft.

Reason: with the base pinned to main (GitHub cannot base a PR on a fork-only branch), this PR showed as a 26-file diff that it did not contain, and the only thing behind its own 6 files was the preview swap. Reviewing it separately meant #391 adding a scroll test that this PR then deleted. Both now live in #391, where the preview change is part of the same subject: what positions a drag.

What came with it, beyond a straight merge:

  • DragPreviewProps loses offset and mouse. They were being passed as null once <DragOverlay> took over positioning, which would have left a public type promising coordinates that never arrive. id, dragIds and isDragging are unchanged.
  • README documents the reduced props and says what a custom preview should stop doing.
  • The changeset is breaking and names the prop removal.

Branch migrate-to-dnd-kit now carries the work as 3517dfa; this branch is superseded and being deleted. Verification for the combined branch is in #391.

@ccombe ccombe closed this Oct 29, 2026
@ccombe
ccombe deleted the drag-overlay-modernization branch October 29, 2026 10:07
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.

1 participant