react-arborist icon indicating copy to clipboard operation
react-arborist copied to clipboard

Duplicate HTML5 backend error

Open jandrew44 opened this issue 1 year ago • 6 comments
trafficstars

Sometimes I am getting the following error when using react-arborist 3.4.0: "Cannot have two HTML5 backends at the same time". My project does not have direct dependencies "react-dnd", "dnd-core" and "react-dnd-html5-backend" and I don't have any other libraries depending on these packages(react-arborist is the only library requesting it). Also I don't use drag&drop functionality in my project at all, but I am using react-arborist trees inside of several react components. I tried to set disableDrag and disableDrop flags for all of my trees but it did not help. Is it possible to configure react-arborist to not initialize HTML5 backend when drag&drop functionality is not needed(or at least do not do it twice)?

jandrew44 avatar Mar 01 '24 15:03 jandrew44

same problem

bijinfeng avatar Apr 07 '24 03:04 bijinfeng

I have managed to solve it by the workaround mentioned here: https://github.com/react-dnd/react-dnd/issues/186?ysclid=luqqkj24pl935939248#issuecomment-978206387

Still I am not happy to have direct dependencies "react-dnd" and "react-dnd-html5-backend". Would prefer react-arborist to handle it by adding DndProvider wrappers internally.

jandrew44 avatar Apr 08 '24 09:04 jandrew44

Glad you have a workaround. The next version of react-arborist will depend on react-aria's use-drag/drop hooks rather than the aging react-dnd. These issues should not longer be a problem.

jameskerr avatar Apr 08 '24 16:04 jameskerr

@jandrew44 would be great if you sahre your solution here , Thank you!

JaafarF avatar May 14 '24 15:05 JaafarF

Screenshot_2

Here is my wrapper component. It requires container element id to be passed as contextId. passRef is used to pass ref parameter to the tree because it cannot be passed directly in this case. If you don't need to pass ref it can be removed.

jandrew44 avatar May 14 '24 18:05 jandrew44

Here is my solution, maybe helps.

  1. add DndProvider with HTML5Backend in root.
  2. get dropManager with useDragDropManager hooks and add it on Tree.

main.tsx

<DndProvider backend={HTML5Backend}>
        <EditorShortcuts>
          {workbenchStore.isReady && <EditCanvas />}
          <Toolbar />
          <LeftPanel />
          <PropertiesPanel />
          <CommandMenu />
        </EditorShortcuts>
      </DndProvider>

tree.tsx

import { useDragDropManager } from 'react-dnd';

export const NodeTree = observer(() => {
   const dragDropManager = useDragDropManager();
   // ...some code
   return <Tree
        ref={treeRef}
        childrenAccessor={(node) => node.reversedChildren || null}
        data={treeData}
        width={width}
        height={height}
        onRename={onRename}
        onMove={onMove}
        onNodeClick={onNodeClick}
        dndManager={dragDropManager}
      />
})

Cmen117696 avatar Oct 10 '24 06:10 Cmen117696

Next version will not rely on react-dnd anymore (thank God)

jameskerr avatar Feb 06 '25 19:02 jameskerr

Maybe I'm misunderstanding something, but react-dnd is still listed in the dependencies as of current 3.4.3 version. Nor this issue has any linked PR, closed or not, regarding removal of react-dnd. Why the issue is closed?

Artboomy avatar Sep 20 '25 14:09 Artboomy

@Artboomy the lib is no longer maintained, so nobody will move from react-dnd to react-aria. See: https://github.com/brimdata/react-arborist/issues/310

goliney avatar Oct 21 '25 21:10 goliney