Repository navigation
Description
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-arboristdirectly withoutreact-dndandreact-dnd-html5-backend. - Native touch and pointer support:
PointerSensorworks 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-dndtargets (thedrag-outshowcase), and dropping the app'sreact-dnditems into the tree. - Native HTML5 drag and drop: OS file drops, dragging out to other apps or windows, and iframe setups via
dndRootElement. dragTypeas 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, anddndRootElementare removed outright; TypeScript flags existing uses.
Scope
Migration only:
- Migrate drag and drop from react-dnd to @dnd-kit #391 Core migration to
@dnd-kit- Replace
react-dndandreact-dnd-html5-backendwith@dnd-kit/coreand@dnd-kit/utilities. - Drop the
react-dndpeer dependencies. - Remove
dndBackend,dndManager,dndRootElement. - Keep
ref={dragHandle}andrenderDragPreviewcompatible. - Add the optional
sensorsprop. - Address review notes: scroll-safe pointer handling, listener wiring, virtualization test, restored test evidence.
- Render drag previews with
<DragOverlay>; this was [Stacked on #391] Use dnd-kit's native DragOverlay for drag previews #392 and is folded in, so it ships with the migration.
- Replace
Out of scope
- Keyboard handler extraction and
computeDropdedupe: Simplify keyboard handling and dedupe computeDrop branches #397, delivered by Simplify keyboard handling and dedupe computeDrop branches #399. - Circular import untangling: Untangle circular imports for an acyclic module graph #398, delivered by Untangle the one circular import and the patterns that add more #400.
- External/shared
<DndContext>support: Support coordinating the tree with an external DndContext #396, future work.
Activity
TrevorBurnham commentedon Oct 25, 2026
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
computeDropcleanup) 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 againstmain, 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
mainand 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/corehasn'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
dndBackendanddndManagerbecome silent no-ops. Things that work today and won't after this:drag-outshowcase), and dropping the app's react-dnd items into the treedndRootElementdragTypeas 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 treeThat's acceptable for a major, but the changeset should list it plainly. I'd also rather remove
dndBackend,dndManager, anddndRootElementoutright, so TypeScript flags them, than keep them asunknownno-ops.Technical notes on #391
useHasParentDndContextchecks the.lengthof 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.DndContext: this mode looks unsafe as written, and it's what thetreeCollisionDetectionexport is for:useDndMonitorgets every drag in the context.handleDragStarttreats anyactive.idas its own node, so a drag from another tree or from the app could reachapi.drop()with IDs the tree doesn't own.node.ids, andOUTER_DROP_IDis 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.event.delta. I believe dnd-kit'sdeltaincludes scroll adjustments, which would skewcomputeDropafter the list auto-scrolls mid-drag. I haven't verified this, so a test that drags across a scroll would settle it.drag-hook.tsattaches dnd-kit's React listeners withaddEventListenerand a fake{ nativeEvent }, which depends on dnd-kit internals.KeyboardSensorstarts 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.Proposed order
Happy to discuss any of this, especially if you've already looked into
@dnd-kit/react.ccombe commentedon Oct 27, 2026
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
computeDropdedupe) 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 externalDndContext, since that is what the old external-context mode was for.Stack. #392 to #394 are drafts. #392 cannot be retargeted:
migrate-to-dnd-kitexists only on my fork, so upstream has no base to point at. It stays draft and I will rebase it ontomainonce #391 merges.Which dnd-kit. Sticking with
@dnd-kit/core6.3.1, now stated in #390.@dnd-kit/reactis 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,
dndRootElementiframes), anddragTypeas a filter.dndBackend,dndManager, anddndRootElementare 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 thetreeCollisionDetectionexport and thedrag-outdemo and spec. Both problems you named are why #396 has to namespace IDs and filter monitor events before the mode comes back: foreignactive.ids reachingapi.drop(), and collisions on raw node ids plus the singleOUTER_DROP_ID.Pointer position. You were right about
delta. It is dnd-kit'sscrollAdjustedTranslate, 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-phasepointermove/mousemove/touchmovewhile a drag is active, and feeds that to bothcomputeDropand the preview. The same test asserts the preview does not move when only the list scrolls.Listener wiring. Two changes. The
addEventListenershim now hands activators an event withtarget,preventDefault, andstopPropagation, not justnativeEvent. Withouttarget,KeyboardSensornever activated. And the default sensors are pointer-only:KeyboardSensorstarts 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, becausecomputeDropworks from pointer coordinates. That is new work, not a port of something removed.The shim stays because
dragHandleis a ref callback, so dnd-kit's React listeners cannot be spread onto JSX. It is commented to that effect. ChangingdragHandleto 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
mainexcept thedragAndDrophelper, which now drives pointer events instead of aDataTransfer. Thedrag-outspec 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 viauseDestinationUpdates.Verification. Unit 138/138, warning-clean. Cypress 17/17 against a rebuilt showcase.
yarn lintandyarn fmt:checkclean. #391's head is991d23d.If you want to review this in smaller pieces, tell me and I will split it.
ccombe commentedon Oct 29, 2026
One correction to what I said about tests earlier.
I folded the
DragOverlaywork from #392 into #391. As a follow-up it could not be reviewed on its own: its base had to bemain, 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
translatetransform did not move when only the list scrolled.DragOverlaypositions 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 tocomputeDropeither: jsdom has no layout, sopointerWithinfinds no droppable andcomputeDropnever 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:
DragPreviewPropsno longer carriesoffsetormouse, since those would always benullonce the overlay positions the preview. A custom preview that positioned itself withoffsetneeds to stop.Current numbers on #391: 137 unit tests warning-free, 3 Cypress specs and 17 tests, lint and format clean.
ccombe commentedon Oct 31, 2026
Closing this now that the work is in review. Where everything lives:
@dnd-kit+<DragOverlay>previewscomputeDropdedupeDndContextThe decisions above stay as the record:
@dnd-kit/core6.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.