React-sortable-tree: Using SortableTreeWithoutDndContext does not work

Created on 27 Aug 2020  路  8Comments  路  Source: frontend-collective/react-sortable-tree

rstwithoutdndcontext

There are two DnDs in a page.
One for the RST with external nodes, and the other for the tab swapping.
We place <DndProvider /> in top level component and
use SortableTreeWithoutDndContext in child component
to avoid two HTML backends issue.

It seems the RST renders nothing or returns null as the dragDropManager is undefined.
https://github.com/frontend-collective/react-sortable-tree/blob/2a5f741d0bc965b47a8ea6764e98a13aa3e51544/src/react-sortable-tree.js#L941-L949

Is there a workaround to deal with this issue?
Thank You.

Most helpful comment

@zourbuth I had the same problem and it was because I ended up with two copies of react-dnd in my final Webpack bundle, one that I was importing and the other that react-sortable-tree imported. Because DndContext is a singleton, having two copies means there are two singletons! I resolved the issue for myself by ensuring Webpack resolved the react-dnd package to a single, top-level installation of react-dnd.

https://webpack.js.org/configuration/resolve/#resolvealias

All 8 comments

Any update?
It seems there is no activity for this repository for weeks.
Is this still maintained?

@zourbuth You need to wrap your component with the DndProvider.

<DndProvider backend={HTML5Backend}>
    <SortableTreeWithoutDndContext />
</DndProvider>

ref: https://github.com/frontend-collective/react-sortable-tree/blob/master/stories/touch-support.js

@zli-aa, we did. We wrap it in top level component.
But dragDropManager always undefined and it makes RST renders null.

https://github.com/frontend-collective/react-sortable-tree/blob/2a5f741d0bc965b47a8ea6764e98a13aa3e51544/src/react-sortable-tree.js#L944

@zli-aa it worked for us but I really do believe as @zourbuth mentioned that this repo seems to be unmaintained...

@zourbuth I had the same problem and it was because I ended up with two copies of react-dnd in my final Webpack bundle, one that I was importing and the other that react-sortable-tree imported. Because DndContext is a singleton, having two copies means there are two singletons! I resolved the issue for myself by ensuring Webpack resolved the react-dnd package to a single, top-level installation of react-dnd.

https://webpack.js.org/configuration/resolve/#resolvealias

I was having the same problem for months now and none of the solutions worked except for @drewpc 's one https://github.com/frontend-collective/react-sortable-tree/issues/788#issuecomment-710661403 ! Thanks :)

If anyone is interested, my webpack modification looks like this:

  resolve: {
    ...
    alias: {
      'react-dnd': path.resolve(__dirname, '../node_modules/react-dnd'),
    },
  },

I just install and configure webpack just for try @drewpc solution but it didn't work for me, I've tried @Nauss just like that :( didn't work either, anyone have suggestions please?

btw: In my case I have a component that use react-sortable-tree and other that I'm trying to use basic HTML Drag and drop using draggable="true", but it doesn't work due the this lib, If I stop loading everything works :/ so I assume the issue is related

None of the suggestions above seem to have helped. Tried resolving and also whenever I use SortableTreeWithoutDndContext it just doesn't render anything.

Was this page helpful?
0 / 5 - 0 ratings