Repository navigation
Conversation
👷 Deploy request for react-arborist pending review.Visit the deploys page to approve it
|
ccombe
marked this pull request as ready for review
November 30, 2026 05:39
Contributor
Author
|
@TrevorBurnham Thanks for shipping v5.0.0! This follow-up for #396 is ready for review whenever you have a moment. |
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.
Closes #396.
Why
In v5.0.0, every
<Tree>creates and owns its own@dnd-kit<DndContext>. That isolates standalone trees cleanly, but it blocks two common workflows that apps need once they adopt@dnd-kit:<DndContext>is private, external droppables never see tree drags.<DndContext>. Even if an app tried to share a context, rawnode.idvalues and the sharedOUTER_DROP_IDwould collide across trees,useDndMonitorwould deliver every drag to every tree, and every tree would mount a<DragOverlay>at once.This PR adds an explicit, opt-in
externalDndContextprop and exportstreeCollisionDetectionso apps can share one parent<DndContext>across multiple trees and external droppables without cross-talk or ID collisions.Public API
externalDndContext?: booleanonTreeProps: opts<Tree>into an ancestor@dnd-kit<DndContext>viauseDndMonitorinstead of creating its own. When enabled, the parent<DndContext>ownssensors,accessibility,collisionDetection, and drag-handletouch-actionstyles (just like customsensors).treeCollisionDetectionexported fromreact-arborist: pass to the parent<DndContext collisionDetection={treeCollisionDetection}>so each tree prefers row droppables over its own outer list droppable, clips overscan rows to that tree's visible list rect, and leaves other trees and external app droppables intact.active.data.current: each tree draggable attaches{ treeId, id, node, data }(matchingtreeRef.current.dndId), so parentonDragEndhandlers can identify the source tree and node even when multiple trees reuse identical node IDs.How it works
Key design details:
dnd-ids.ts):@dnd-kit/coreclearsactive.data.currentwhenreact-windowunmounts the dragged row mid-drag, while keepingactive.id. Parsing the per-tree ID prefix (parseNodeDndId(tree.dndId, active.id)) keeps drags, drop targeting, accessibility announcements, and<DragOverlay>working even after the source row scrolls out of view.collision-detection.ts): replaces the globalOUTER_DROP_IDwith container metadata (data.current.treeIdanddata.current.isOuterDrop) so an overscan row sticking out of Tree A is clipped against Tree A's list rect without swallowing collisions on Tree B or external app droppables.externalDndContextis an explicit boolean prop, andExternalDndMonitormemoizes its monitor object before passing it touseDndMonitor(which throws dnd-kit's clear error if no ancestor<DndContext>exists).modules/showcase/next.config.js): Yarn 4 installs a nested@dnd-kit/coreundermodules/showcasewhile symlinkedreact-arboristresolves the hoisted root copy. Aliasing@dnd-kit/coreinnext.config.jsensures the/shared-dnd-contextdemo bundles a single React context instance (andREADME.mdnotes this for monorepo consumers).Scope and non-goals
<Tree>behavior is unchanged (externalDndContextdefaults tofalse).onMovecontinues to fire only for reorders within that tree. Cross-tree moves (dragging a node from Tree A into Tree B) remain under the parent<DndContext onDragEnd>so the app controls cross-tree data mutations.type: feature, inferred5.1.0minor bump in.changes/396-external-dnd-context.md).Demo and verification
/shared-dnd-context(modules/showcase/pages/shared-dnd-context.tsx) with two controlled trees sharing overlapping IDs ("1","2","3") plus an external Archive drop zone.yarn workspace react-arborist testpasses 16 suites, 218/218 tests, with 0 console warnings/errors (added tests for foreign-drag event filtering, cross-tree and external droppable collision clipping, overlapping-ID independent trees, external droppable/draggable coordination,touch-actionpreservation underexternalDndContext, and virtualized unmount survival).yarn workspace showcase build && yarn workspace e2e testpasses 5 specs, 22/22 tests (including newshared-dnd-context-spec.cy.js).yarn lint(0 warnings/errors),yarn fmt:check(clean),yarn workspace react-arborist build(clean),npx madge@8.0.0 --circular modules/react-arborist/dist/module/index.js(0 circular dependencies across 49 files).