Skip to content

[Roadmap] Migrate drag-and-drop engine to @dnd-kit & modernize architecture #390

Closed

Description

@ccombe

Status (2026-11-01)

Three open PRs, all based on main, all green:

PR Scope State
#391 Migration to @dnd-kit + <DragOverlay> previews open, checks pass, mergeable
#399 Keyboard handler extraction + computeDrop dedupe open, checks pass, mergeable
#400 Circular imports + type-only imports open, checks pass, mergeable

Closed in the process: #392 (DragOverlay, folded into #391), #393 and #394 (reopened as #397 and #398 so they could land independently of the migration).

Still open as follow-up: #396 (external DndContext). #397 and #398 were closed as delivered by #399 and #400, so the requirement text now lives in those PR bodies.

Motivation

In #371, @TrevorBurnham noted:

"I'm wary of cutting a new major version that uses an obscure fork of react-dnd. I'd be more interested in a PR that swaps out react-dnd entirely for a more modern, actively maintained library like dnd-kit."

This issue tracks migrating react-arborist from react-dnd to @dnd-kit, delivered in #391. Follow-up architecture work is tracked separately.

Why @dnd-kit

  • Zero required peer dependencies: consumers install react-arborist directly without react-dnd and react-dnd-html5-backend.
  • Native touch and pointer support: PointerSensor works across desktop and mobile without extra packages.
  • Context isolation: standard React Context removes the global HTML5 backend singleton conflict (Support latest react-dnd 15.x #319).
  • Cleaner drag previews: built-in <DragOverlay> with GPU transforms.

Decision: target @dnd-kit/core 6.x

We target @dnd-kit/core 6.3.1 (latest stable) rather than @dnd-kit/react / @dnd-kit/dom (0.5.x, pre-1.0). 6.x is stable, widely used, and already fits the integration surface. A second migration now would add risk without a corresponding payoff; revisit the newer packages when they reach a stable release.

What v5 gives up

Listed plainly in the #391 changeset:

  • Dragging rows onto the host app's react-dnd targets (the drag-out showcase), and dropping the app's react-dnd items into the tree.
  • Native HTML5 drag and drop: OS file drops, dragging out to other apps or windows, and iframe setups via dndRootElement.
  • dragType as a filter: it is now a label on drag data only, so a custom type no longer makes a row non-reorderable within the tree.
  • dndBackend, dndManager, and dndRootElement are removed outright; TypeScript flags existing uses.

Scope

Migration only:

Out of scope

Activity

  1. TrevorBurnham commented on Oct 25, 2026

    @TrevorBurnham
    Collaborator

    Thanks for taking this on, and for following up on #371. Moving off react-dnd is the direction I want: dropping the peer deps and fixing #319 are real wins. Before reviewing the PRs in detail, I'd like to adjust the plan.

    Scope

    Let's limit this roadmap to the migration. #393 (keyboard handler and computeDrop cleanup) and #394 (circular imports) don't depend on dnd-kit. Stacking them on the riskiest change means they can't land until it does. Please open them as separate issues against main, each with the concrete problem it solves. I'm less persuaded by metrics alone (complexity scores, madge counts).

    The stack isn't reviewable as-is. All four PRs target main and each one contains every earlier commit, so #394 is 46 files and includes the whole migration. Could you either retarget each PR at the previous one's branch, or put #392–#394 in draft until #391 merges?

    Decisions to make before merging #391

    Which dnd-kit? @dnd-kit/core hasn't published since 6.3.1 (Dec 2024). Development has moved to @dnd-kit/react / @dnd-kit/dom (0.5.x). Targeting 6.x may be the right call because it's stable and widely used, but I'd like that to be a stated decision. Otherwise we may face a second migration later. What's your read on the new API's readiness?

    What v5 gives up. "Non-breaking fallback" undersells it, since dndBackend and dndManager become silent no-ops. Things that work today and won't after this:

    • dragging rows onto the host app's react-dnd targets (the drag-out showcase), and dropping the app's react-dnd items into the tree
    • native HTML5 drag and drop: OS file drops, dragging out to other apps or windows, and iframe setups via dndRootElement
    • dragType as a filter: it's now just a label on the drag data, so a custom type no longer makes a row non-reorderable within the tree

    That's acceptable for a major, but the changeset should list it plainly. I'd also rather remove dndBackend, dndManager, and dndRootElement outright, so TypeScript flags them, than keep them as unknown no-ops.

    Technical notes on #391

    • Parent-context detection: useHasParentDndContext checks the .length of dnd-kit's internal default-context stubs. A dnd-kit refactor or a minifier could break that silently. An explicit prop (or always creating our own context unless one is supplied) seems safer.
    • Shared DndContext: this mode looks unsafe as written, and it's what the treeCollisionDetection export is for:
      • every tree's useDndMonitor gets every drag in the context. handleDragStart treats any active.id as its own node, so a drag from another tree or from the app could reach api.drop() with IDs the tree doesn't own.
      • draggable and droppable IDs are raw node.ids, and OUTER_DROP_ID is a single constant, so two trees, or a tree plus the app's own droppables, will collide. Namespacing IDs per tree and filtering monitor events to the tree's own draggables would address both.
    • Pointer position: it's computed as the starting coordinates plus event.delta. I believe dnd-kit's delta includes scroll adjustments, which would skew computeDrop after the list auto-scrolls mid-drag. I haven't verified this, so a test that drags across a scroll would settle it.
    • Listener wiring: drag-hook.ts attaches dnd-kit's React listeners with addEventListener and a fake { nativeEvent }, which depends on dnd-kit internals. KeyboardSensor starts a drag on Space or Enter, so a button or checkbox inside a custom row renderer might start a keyboard drag when activated. Worth a test.
    • Virtualization: please add a test for dragging a row far enough that its source row unmounts.
    • Test evidence: the Cypress specs and DnD unit tests were largely rewritten to match the new event model. So a passing run shows the new tests fit the new code, not that behavior was preserved. Where possible, I'd like the old specs kept with only the event simulation swapped. Please also confirm the change keeps the drag-performance gains from Improved drag and drop performance #385.

    Proposed order

    1. Narrow [Roadmap] Migrate drag-and-drop engine to @dnd-kit & modernize architecture #390 to the migration, with the dnd-kit version decision and the list of capabilities v5 drops.
    2. Update Migrate drag and drop from react-dnd to @dnd-kit #391 per the notes above.
    3. [Stacked on #391] Use dnd-kit's native DragOverlay for drag previews #392 (DragOverlay) as a follow-up retargeted onto Migrate drag and drop from react-dnd to @dnd-kit #391. It looks like a good simplification once the base is settled.
    4. Decouple keyboard navigation and simplify drop logic (Stack 3/4) #393 and Untangle circular dependencies for an acyclic module graph (Stack 4/4) #394 as their own issues.

    Happy to discuss any of this, especially if you've already looked into @dnd-kit/react.

  2. ccombe commented on Oct 27, 2026

    @ccombe
    ContributorAuthor

    Thanks, this is a better shape for the stack. #391 is updated.

    Scope. #390 covers only the migration now: the version decision, what v5 gives up, and the PR list. I closed #393 and #394 as PRs and reopened them as #397 (keyboard handler and computeDrop dedupe) and #398 (circular imports), each with the concrete problem it solves. Their branches are kept for after this lands. I also opened #396 for coordinating a tree with an external DndContext, since that is what the old external-context mode was for.

    Stack. #392 to #394 are drafts. #392 cannot be retargeted: migrate-to-dnd-kit exists only on my fork, so upstream has no base to point at. It stays draft and I will rebase it onto main once #391 merges.

    Which dnd-kit. Sticking with @dnd-kit/core 6.3.1, now stated in #390. @dnd-kit/react is at 0.5.1 and is where development moved, but it is still 0.x with the 1.0 API unsettled. A library is a bad place to pin a moving API, since consumers cannot easily upgrade with us. I would migrate when it reaches 1.0, not before. 6.3.1 has had no release since December 2024, which is fine for us: nothing changes under the library and there is no new version to chase.

    What v5 gives up. Listed in the changeset and in the README's v4 to v5 section: react-dnd interop in both directions, native HTML5 DnD (OS file drops, dragging out of the window, dndRootElement iframes), and dragType as a filter. dndBackend, dndManager, and dndRootElement are removed outright so TypeScript flags them.

    Parent-context detection. Gone. Every <Tree> creates and owns its <DndContext>, so there is no branch left to detect. A supported opt-in is #396.

    Shared DndContext. Also gone, along with the treeCollisionDetection export and the drag-out demo and spec. Both problems you named are why #396 has to namespace IDs and filter monitor events before the mode comes back: foreign active.ids reaching api.drop(), and collisions on raw node ids plus the single OUTER_DROP_ID.

    Pointer position. You were right about delta. It is dnd-kit's scrollAdjustedTranslate, so the skew is not a rounding error. A test that scrolls the list 100px mid-drag with the pointer held still showed the derived position jumping exactly 100px (translate(10px, 140px) where the pointer said 40). #391 now tracks the pointer from capture-phase pointermove/mousemove/touchmove while a drag is active, and feeds that to both computeDrop and the preview. The same test asserts the preview does not move when only the list scrolls.

    Listener wiring. Two changes. The addEventListener shim now hands activators an event with target, preventDefault, and stopPropagation, not just nativeEvent. Without target, KeyboardSensor never activated. And the default sensors are pointer-only: KeyboardSensor starts a drag on Space or Enter on the row, which is the button and checkbox case you described, and it also shadowed the tree's own Space/Enter (select/toggle, rename). Keyboard reordering never existed in v4, so nothing is lost, but adding it means defining how a keyboard drag picks its target, because computeDrop works from pointer coordinates. That is new work, not a port of something removed.

    The shim stays because dragHandle is a ref callback, so dnd-kit's React listeners cannot be spread onto JSX. It is commented to that effect. Changing dragHandle to a props bag would remove it, but that is a second public API break on top of a major. I will do it in #391 if you want it there rather than later.

    Tests. New: the scroll mid-drag above, a drag that keeps working after the source row is scrolled out of the window, Space/Enter on a nested button, and the collision-detection cases. Restored: the gmail and variable-height Cypress specs are identical to main except the dragAndDrop helper, which now drives pointer events instead of a DataTransfer. The drag-out spec went with its demo.

    #385. All three mechanisms survive, with their tests unchanged and green: tree.hover() still lands in the store at most once per animation frame, the dnd reducer still bails on unchanged state, and rows still subscribe via useDestinationUpdates.

    Verification. Unit 138/138, warning-clean. Cypress 17/17 against a rebuilt showcase. yarn lint and yarn fmt:check clean. #391's head is 991d23d.

    If you want to review this in smaller pieces, tell me and I will split it.

  3. ccombe commented on Oct 29, 2026

    @ccombe
    ContributorAuthor

    One correction to what I said about tests earlier.

    I folded the DragOverlay work from #392 into #391. As a follow-up it could not be reviewed on its own: its base had to be main, so it showed #391's whole diff, and the only thing behind its own 6 files was the preview swap. #391 now renders previews with dnd-kit's <DragOverlay> and is a single PR.

    That changes the scroll test I described. The old test asserted that the preview's translate transform did not move when only the list scrolled. DragOverlay positions the preview itself and folds scroll into its transform on purpose, so the assertion no longer describes the tree. I could not move it down to computeDrop either: jsdom has no layout, so pointerWithin finds no droppable and computeDrop never runs there. The pointer fix is still in place; the PR body says that a Cypress test scrolling mid-drag is what would cover it, and I have not added one.

    One further breaking change came out of the fold: DragPreviewProps no longer carries offset or mouse, since those would always be null once the overlay positions the preview. A custom preview that positioned itself with offset needs to stop.

    Current numbers on #391: 137 unit tests warning-free, 3 Cypress specs and 17 tests, lint and format clean.

  4. ccombe commented on Oct 31, 2026

    @ccombe
    ContributorAuthor

    Closing this now that the work is in review. Where everything lives:

    Work Where
    Migration to @dnd-kit + <DragOverlay> previews #391
    Keyboard handler extraction + computeDrop dedupe #399
    Circular imports + madge CI guard #400
    Type-only imports #391
    Shared or external DndContext #396

    The decisions above stay as the record: @dnd-kit/core 6.x over @dnd-kit/react, and what v5 gives up. Each PR body carries its own problem statement and acceptance criteria, so review happens there rather than here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions