-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple DndProviders inside a pure component can lead to Cannot have two HTML5 backends at the same time
#3257
Comments
+1 Getting the same error I am using version 7.7.0 for both Cannot have two HTML5 backends at the same time.
206 |
> 207 | const wrapper = mount(
| ^
208 | <Provider store={store}>
209 | <DragDropContextProvider backend={HTML5Backend}>
210 | <MyComponent />
at HTML5Backend.Object.<anonymous>.HTML5Backend.setup (node_modules/react-dnd-html5-backend/lib/cjs/HTML5Backend.js:318:19)
at DragDropManagerImpl.handleRefCountChange (node_modules/dnd-core/lib/cjs/DragDropManagerImpl.js:30:31) |
Got the same issue with |
add props context={window}, it's solved my problem. |
Thanks you saved my ass |
thx
|
should this context prop be documented somehow ? |
should this be true by default ?
|
thx,it works |
Have you solved this problem yet? My version is "react-dnd": "^14.0.4", "react-dnd-html5-backend": "^14.0.2", |
有用的!!! |
For people still struggling with this: the issue mostly seems to occur when you wrap your DnD enabled component directly with a DnDProvider (instead of using the Provider at the top level of your app) and then navigating between routes/pages in your app. I see two workarounds:
|
Thanks a lot @ekeijl . Below solution worked for me. Add the |
thx,dude! |
Hi @ekeijl , this |
My guess is that |
Amazing, this worked for me too! Thank you @ymh1028 The docs are pretty terrible and outdated. So it's probably unlikely they'll be updated to include this, but at least this workaround exists.
This approach probably would work if you didn't have multiple sections in your App to have independent DnD interactions. In my case, we don't ever want a single DnD provider. We have multiple widgets within our App that all have their own DnD capabilities that shouldn't cross boundaries into other DnD areas. So I wouldn't recommend this as a potential solution here b/c it shouldn't be the case to have only a single dnd provider at the root. |
This and other proposed solutions are still breaking Next.js apps. Unfortunately, the |
* If the context is not set to window we can end up in a situation where multiple backends are instantiated resulting in an error. More info react-dnd/react-dnd#3257
Describe the bug
Using two
<DndProvider backend={HTML5Backend}>
inside aReact.PureComponent
(which updates only if props change), can under certain conditions lead to an error like: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 ofshouldComponentUpdate
), we have a singleread-only
(this is a prop, in the example:foo
) DnD component, which later is dynamically replaced by a singleread-write
DnD component, and then joined by a 2nd DnD component.Steps to reproduce the behavior:
Expected behavior
Desktop
Related
#1558
#3119
#3178
Since I wasn't sure which/if any of the above qualifies for duplicate, I created a fresh issue.
The text was updated successfully, but these errors were encountered: