Skip to content

Conversation

@cbeer
Copy link
Contributor

@cbeer cbeer commented Jun 8, 2020

Changes proposed in this pull request:

This should allow containing applications to provide an external react-dnd context. It seems like this may have been supported by previous react-dnd (#74), but we're seeing this crop up again in ProjectMirador/mirador#3094 when we use react-dnd in our application.

HTML5Backend.js?56ae:380 Uncaught Error: Cannot have two HTML5 backends at the same time.
    at HTML5Backend.setup (HTML5Backend.js?56ae:380)
    at _default.setup (MultiBackend.js?7d82:75)
    at DragDropManagerImpl.handleRefCountChange (DragDropManagerImpl.js?e1b0:40)
    at Object.dispatch (redux.js?0a4a:222)
    at HandlerRegistryImpl.addTarget (HandlerRegistryImpl.js?0db8:99)
    at registerTarget (registration.js?c129:3)
    at registerHandler (drop.js?169c:50)

Passing the dragDropManager through as a prop allows Mosaic to use the same context:

      <DndContext.Consumer>
				{(ctx) => (
          <Mosaic
            manager={ctx.dragDropManager}
            ...
          />
        )}

@nomcopter
Copy link
Owner

What's the benefit of this over using MosaicWithoutDragDropContext directly?

cbeer added a commit to cbeer/mosaic-test-case that referenced this pull request Jun 8, 2020
@cbeer
Copy link
Contributor Author

cbeer commented Jun 8, 2020

I wasn't able to get MosaicWithoutDragDropContext to work for me -- react-dnd kept complaining that there was no dragDropContext:

Could not find the drag and drop manager in the context of RootDropTargetsClass. Make sure to render a DndProvider component in your top-level component. Read more: http://react-dnd.github.io/react-dnd/docs/troubleshooting#could-not-find-the-drag-and-drop-manager-in-the-context

I've replicated the failure in a simple test case app: https://github.com/cbeer/mosaic-test-case/blob/master/src/App.js

I think it's because react-mosaic has react-dnd as a direct dependency instead of a peer dependency, so the context isn't getting propagated into react-mosaic-component?

@nomcopter
Copy link
Owner

I wasn't able to get MosaicWithoutDragDropContext to work for me -- react-dnd kept complaining that there was no dragDropContext:

Could not find the drag and drop manager in the context of RootDropTargetsClass. Make sure to render a DndProvider component in your top-level component. Read more: http://react-dnd.github.io/react-dnd/docs/troubleshooting#could-not-find-the-drag-and-drop-manager-in-the-context

I've replicated the failure in a simple test case app: https://github.com/cbeer/mosaic-test-case/blob/master/src/App.js

I think it's because react-mosaic has react-dnd as a direct dependency instead of a peer dependency, so the context isn't getting propagated into react-mosaic-component?

Ah interesting - I think you are on the right track. Can you try pinning your version of react-dnd to the identical version that react-mosaic uses in that test case app? If they both use the same instance of react-dnd it should work.

@cbeer
Copy link
Contributor Author

cbeer commented Jun 8, 2020

Hm. I'm not seeing any difference pinning react-dnd to ^10.0.2 or 10.0.2.

@mejackreed
Copy link
Contributor

Just curious about seeing if this could move forward. @nomcopter would you mind taking a look again? Thanks!

@nomcopter nomcopter merged commit c572217 into nomcopter:master Aug 3, 2022
@nomcopter
Copy link
Owner

Sorry about the crazy delay - hope this is still useful!

@cbeer cbeer deleted the dragAndDropManager branch August 3, 2022 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants