question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DndProvider: Cannot have two HTML5 backends at the same time

See original GitHub issue

Describe the bug DndProvider backend is not tore down when un-mounting. Although this surfaced in our test, I would think this would also apply to an app.

Reproduction

If you run the test in this CodeSandbox, you should one them fail with the “Cannot have two HTML5 backends at the same time” error. The same test runs twice (using test.each), the first time it passes but second time it fails.

In our actual application, we do use a single DndProvider at the root, hence we don’t run into this issue. However, the errors crops up in our tests, as each tests renders a DndProvider (with an HTML5Backend).

Expected behavior I would expect the backend to be tore down (teardown) between each tests, when the components get unmounted and cleaned up.

Desktop (please complete the following information):

  • OS: MacOS 11.2.2
  • Browser: Jest/jsdom
  • Versions:
    • react-dnd: 13.1.1
    • react-dnd-html5-backend: 12.1.1

Additional context I tried the suggestion from https://github.com/react-dnd/react-dnd/issues/2884#issuecomment-735981457 thinking that teardown didn’t occur because a reference to the drop ref was still alive, but it didn’t fix the error.

We looked into using the test backend in our tests, but it does not work with fireEvent.dragEnter and al - seems like you need to use the public method from the backend (ie.: simulateBeginDrag and …).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:5

github_iconTop GitHub Comments

1reaction
avigoldmancommented, Nov 14, 2021

This was the fix that worked for me!

1reaction
kodedninjacommented, Apr 13, 2021

Had the same issue for a long time and couldn’t find any fix other than the workaround of manually handling the manager. You can use createDropManager from dnd-core and initialize a single manager that you reuse in the DndProvider. Don’t ask me if this is something you should do, but it works. So, something like:

// dnd-utils.js
import { createDropManager } from 'dnd-core'

export const manager = createDragDropManager(HTML5Backend)

...

// somewhere.js
import { manager } from './dnd-utils'

<DndProvider manager={manager}>
  ...
</DndProvider>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot have two HTML5 backends at the same time #3178
Describe the bug I use different react-table draggable in different react-tabs My Index.js contains: import { HTML5Backend } from ...
Read more >
React DnD - "Cannot have two HTML5 backends at the same ...
Just try to make the context of HTML5Backend a singleton. You can check the codes at: https://github.com/react-dnd/react-dnd/issues/186.
Read more >
Cannot have two HTML5 backends at the same time
Cannot have two HTML5 backends at the same time - Communication Site. Getting the following error in Edit Mode when we add more...
Read more >
React DnD Cannot have two HTML5 backends at the same ...
... return (\\n <DndProvider backend={HTML5Backend}>\\n <DndItem />\\n </DndProvider>\\n ) ... DnD Cannot have two HTML5 backends at the same time. repro\" ...
Read more >
"Cannot have two HTML5 backends at the same time."-Reactjs
import { DndProvider, createDndContext } from "react-dnd"; import HTML5Backend from "react-dnd-html5-backend"; import React, { useRef } from "react"; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found