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
DragSource attempting to setup HTML5Backend a second time in v9.4.0 #1558
Comments
I am also having same issue. #1571 |
I am running into this type of issue as well, in my case I have some set of components mounted that uses On |
@ozzyogkush Maybe you can try using a single DndProvider mounted at the root of your app - there should only be one per document. |
I found a temp. solution that works as such: in my app index file:
futher down the component tree...
In my component defined in an external package:
This way, if the app doesn't provide the manager, it falls back on a default. |
@darthtrevino is the expectation that once the dnd provider component is mounted, it should never unmount ? (i.e. can it mount and unmount and re-mount ?) |
@pjgates I don't know how bad this idea is but you can make it work by setting yourself the property to false on mount.
I don't have much knowledge about working of react dnd and I would like to get feedback on this approach wether this will break code or not. |
The DndProvider break down the HTML5Backend when it is unmounted, and the HTML5Backend will clear that variable in the window. That being said, all of the testing of this library has been done with a stable root DndProvider in the sample apps |
11.1.3 我临时选择了这种方法,期待更好的办法,可能需要用升级版本才可以? |
[HTML5BackendImpl.ts#L108-L108]( react-dnd/packages/backend-html5/src/HTML5BackendImpl.ts Lines 101 to 112 in 8e6f62e
maybe this rootElement can be replace by ReactRef? |
Describe the bug
After updating to v9.4.0 we found that when mounting components using the
DragSource
decorator, it would sometimes attempt to setup theHTML5Backend
again, thus triggering the errorUncaught Error: Cannot have two HTML5 backends at the same time
(asthis.window.__isReactDndBackendSetUp
was notfalse
).The Dnd Context Provider is declared in the root of the page (and thus is above the components that are unmounted and mounted in the tree).
I suspect that either the teardown isn't triggering when it should, or the setup is triggering when it shouldn't, thus triggering this error.
Also, it should be noted that having multiple DragSources (such as items in a list), doesn't trigger this when they're rendered together. It's only when the list is replaced with another list that this bug is triggered.
Expected behaviour
We expect that unmounting and mounting two components that use
react-dnd
to correctly update thethis.window.__isReactDndBackendSetUp
global variable without throwing an error.Desktop (please complete the following information):
Additional context
The stack trace from console:
The text was updated successfully, but these errors were encountered: