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.

Multiple DndProviders inside a pure component can lead to `Cannot have two HTML5 backends at the same time`

See original GitHub issue

Describe the bug

Using two <DndProvider backend={HTML5Backend}> inside a React.PureComponent (which updates only if props change), can under certain conditions lead to an error like:

Error: Cannot have two HTML5 backends at the same time.
	    at HTML5BackendImpl.setup node_modules/react-dnd-html5-backend/dist/esm/HTML5BackendImpl.js:423
	    at DragDropManagerImpl.handleRefCountChange node_modules/dnd-core/dist/esm/classes/DragDropManagerImpl.js:21
	    at Object.dispatch node_modules/redux/es/redux.js:297
	    at HandlerRegistryImpl.addSource node_modules/dnd-core/dist/esm/classes/HandlerRegistryImpl.js:92
	    at registerSource node_modules/react-dnd/dist/esm/internals/registration.js:10
	    at registerDragSource node_modules/react-dnd/dist/esm/hooks/useDrag/useRegisteredDragSource.js:24
	    at commitHookEffectListMount node_modules/react-dom/cjs/react-dom.development.js:20573
	    at commitLifeCycles node_modules/react-dom/cjs/react-dom.development.js:20634
	    at commitLayoutEffects node_modules/react-dom/cjs/react-dom.development.js:23426
	    at HTMLUnknownElement.callCallback node_modules/react-dom/cjs/react-dom.development.js:3945
	    at Object.invokeGuardedCallbackDev node_modules/react-dom/cjs/react-dom.development.js:3994
	    at invokeGuardedCallback node_modules/react-dom/cjs/react-dom.development.js:4056
	    at commitRootImpl node_modules/react-dom/cjs/react-dom.development.js:23151
	    at unstable_runWithPriority node_modules/scheduler/cjs/scheduler.development.js:468
	    at runWithPriority$1 node_modules/react-dom/cjs/react-dom.development.js:11276
	    at commitRoot node_modules/react-dom/cjs/react-dom.development.js:22990

Reproduction

This is the smallest reproducing example I was able to come up with: https://codepen.io/dcsaszar/pen/ZEKLVVJ

It describes basically what happens in one of our apps: Inside a PureComponent-like component (we have our own abstraction, but with a similar implementation of shouldComponentUpdate), we have a single read-only (this is a prop, in the example: foo) DnD component, which later is dynamically replaced by a single read-write DnD component, and then joined by a 2nd DnD component.

Steps to reproduce the behavior:

  1. Go to https://codepen.io/dcsaszar/pen/ZEKLVVJ
  2. See the error in the browser console

Expected behavior

  • No error.
  • The components should render successfully.

Desktop

  • Browser: Chrome
  • Version:
    • react 17.0.2
    • react-dnd: 14.0.2
    • react-dnd-html5-backend: 14.0.0

Related #1558 #3119 #3178

Since I wasn’t sure which/if any of the above qualifies for duplicate, I created a fresh issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

9reactions
minghaoyecommented, Sep 7, 2022

add props context={window}, it’s solved my problem.

0reactions
ZijieZhcommented, Dec 12, 2022

thx

add props context={window}, it’s solved my problem too. with version: “react-dnd”: “^9.4.0”, “react-dnd-html5-backend”: “^9.4.1”,

Read more comments on GitHub >

github_iconTop Results From Across the Web

React DnD - "Cannot have two HTML5 backends at the same ...
My front is in ReactJS. I have 3 components, first, the container call "Candidates", this component call 2 "CardBoard" components that call " ......
Read more >
How to implement drag and drop in React with React DnD
The most common use cases for drag and drop in React include uploading files, moving items between multiple lists, and rearranging images ...
Read more >
React DnD Cannot have two HTML5 backends at the same ...
Adding Classes. In CodePen, whatever you write in the HTML editor is what goes within the <body> tags in a basic HTML5 template....
Read more >
"Cannot have two HTML5 backends at the same time."-Reactjs
[Solved]-React DnD - "Cannot have two HTML5 backends at the same time. ... DndProvider has a options prop in where you can set...
Read more >
react-beautiful-dnd - npm
Beautiful and accessible drag and drop for lists with React. ... Start using react-beautiful-dnd in your project by running `npm i ...
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