feat: migrate dnd-kit story to @dnd-kit/react#869
feat: migrate dnd-kit story to @dnd-kit/react#869vimzh wants to merge 2 commits intoinokawa:mainfrom
Conversation
Replace @dnd-kit/core + @dnd-kit/sortable with @dnd-kit/react +
@dnd-kit/helpers following the official migration guide.
Key changes:
- DndContext → DragDropProvider
- SortableContext removed (automatic registration)
- useSortable returns unified {ref, isDragging}
- DragOverlay uses render function (no more activeId state)
- move() helper replaces manual arrayMove + indexOf
Closes inokawa#852
|
Thanks for the review! thanks! |
|
Many users uses dnd-kit with virtualization clauderic/dnd-kit#1372. It might be a good idea to provide feedback to dnd-kit repo. |
|
Thanks for the suggestion! I investigated a few bypass approaches to make it work:
@dnd-kit/react v0.3.x ties registration to component lifecycle (useSortable → useInstance → useLayoutEffect cleanup). I'll open an issue/discussion on the dnd-kit repo. For now, should I close this PR or keep it open? thanks! |
onDragEnd alone breaks with virtualized lists because unmounted items unregister from dnd-kit's collision detection. Live reordering via onDragOver keeps drop targets among mounted items. Matches the pattern from dnd-kit's official virtualization examples.
|
Updated the story to use onDragOver for live reordering instead of onDragEnd. This fixes the virtualization issue, the dnd-kit maintainer pointed out that their official virtualization examples use this pattern so that drop targets are always among mounted items. Also added snapshot restore on cancel and reused the existing range() utility. thanks! |
Summary
Migrates the dnd-kit Storybook story from
@dnd-kit/core+@dnd-kit/sortable+@dnd-kit/utilitiesto@dnd-kit/react+@dnd-kit/helpers, following the official migration guide.Closes #852
Changes
Dependencies (
package.json):@dnd-kit/core,@dnd-kit/sortable@dnd-kit/react,@dnd-kit/helpersStory (
stories/react/advanced/With dnd-kit.stories.tsx):DndContext→DragDropProviderSortableContext+verticalListSortingStrategy→ removed (automatic registration)useSensors/useSensor/closestCenter→ removed (built-in defaults)useSortabledestructured{attributes, listeners, setNodeRef, transform, transition}→ unified{ref, isDragging}CSS.Transform.toString(transform)→ automatic (handled internally)forwardRefItem + SortableItem → singleSortableItemcomponentuseState(activeId)+onDragStart/onDragEndstate management →DragOverlayrender function patternarrayMove+ manualindexOf→move(items, event)from@dnd-kit/helpersitemStyleconstant (matchesChat.stories.tsxconvention)The net result is 120 → 59 lines — a significantly simpler story that demonstrates the same drag-and-drop + virtual scrolling integration.
Test plan
npm test— all 206 tests passnpm run lint— 0 errorsnpm run format:ci— cleannpx tsc --noEmit— no type errorsnpm run storybook, navigate to "With dnd-kit" story, verify drag-and-drop reordering works within the virtual list