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
Cannot drag element twice. Uncaught Invariant Violation: Cannot call beginDrag while dragging. #455
Comments
@gabrielbull Assuming you might be doing the same thing I was. Namely, you have some list and the items are wrapped as both DropTarget and DragSource. I was getting the same error. From the target specification, the drop function called a swap action but then it was if the element was from then on always monitored as dragable. So I added an endDrag function to the source specification and consoled out when it got called. Never was the result. So the monitor never is made aware that dragging has finished. Likely, a tick cycle problem since the issue disappears then debugging with break points. Rather than trying to understand the logic in the HTML5 Backend code, I changed the drop (or hover if that is where you make swaps) to return an identifier of the item being dropped on to. The return value can be captured by the endDrag (monitor.getDropResult()) and the swap executed from endDrag. This solved my problem but I would love for somebody else to weight in on the original problem. |
Looks like the same issue as #442, components which are both DropTarget and DragSource. |
@MatthewDavidCampbell Have been trying to reproduce this issue. Am guessing you mean the But then you have mentioned, you moved the code from the |
@vegetableman, i had the same issue and fixed it with @MatthewDavidCampbell solution
to fix it, i'm returning an identifier to be read by endDrag and moved
hope that helps. |
Thanks @ndao for chipping in. The issue we were facing was due to this rogue class If a native item was dragged in, the above class used to return, leaving the state of Solution:- We removed the above class and the code was using |
To anyone facing this issue, add console logs in |
On the off chance it's helpful to anyone with this issue, I ran into this error message recently and it turned out to be because I was generating my components from a map command, and I was assigning them randomly-generated keys. When the list re-ordered, the keys would be re-generated randomly, so React DnD was losing connection to the components. I changed my map commands to use deterministic keys that would stick with the component even after re-ordering, and the issue went away instantly. Obvious in hindsight, but frustrating until then! |
same problem here, but the solution above doesn't work with |
I have figured it out (at least for my specific case): I just improperly created completely new Just check your items with |
Had the same problem here. Thanks @deepsweet for pointing out the issue. |
I was using |
Had exactly the same problem, thanks for pointing out an easy fix. I used the same approach as @jiajiawang and generate a random id for each item in the array I have sortable. I wonder if the examples for sortable should mention that (or somewhere else). I spent now ±2 hours finding that by debugging with console.log. I think that could be avoided with some docs. I'd be willing to contribute that if somebody points me to where the best place for that would be :) |
@ndao 's solution worked for me, but does not provide the during-hover action that I am hoping for. When a user would like to re-arrange the items in a list, it is a good user experience to swap the items as they hover, without requiring the user to drop ( But whenever I try to use Interestingly, when I debounce I seek suggestions as to how to do error-free draggable item list mutation in |
@nottoseethesun - i believe you want to do this
Reference: Sortable |
@theTechie - Apparently in |
Could you post a code snippet or is there working example? |
@nottoseethesun - You are right.
|
Thanks @theTechie - but @deepsweet , unfortunately at this time I am not likely able to create a small test reproduction of the issue. I am definitely not re-creating the instances. |
For any future readers; I also sat staring blankly at my code wondering what was going wrong until I realised that even though my Sortable (i.e. Card) components were configured correctly, the problem lay with the fact that the components were being instantiated in the parent's render method. This meant that whenever the parent component re-renderered, react-dnd would lose the connection to the child Sortable components. |
hi, @nottoseethesun How exactly did you debounce hover to about 20ms? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Just wanted to add my experience for any future travelers. I had a component that contained a Hope that helps someone! |
Fixed it. Just make sure that if you're iterating through an array to display your components and your components have dnd in them (either direct or their children) to add a |
os
OS X El Capitan Version 10.11.4 (15E65)
browser
Google Chrome Version 51.0.2704.36 beta (64-bit)
react-dnd
2.1.4
react-dnd-html5-backend
2.1.2
Error happens after a drag and drop where the source element has been removed after the drop when trying to drag the element again.
The text was updated successfully, but these errors were encountered: