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
Removing dragged element on hover throws "Expected to find a valid target." #361
Comments
+1 I am also having this issue |
Please provide an example reproducing the issue. I can take a look then. |
This is probably fixed in 2.1.0. |
@gaearon I recently upgraded to react-dnd v5 and this issue is replicated again. Seems like it worked fine in |
Any news on this? |
@gaearon any update? |
Same problem here |
same here in |
same problem here |
same problem , Any suggestions for fix ? |
Anyone had any luck with this? |
I have this issue on react-sortable-tree external source sample. Dragging to a red area. https://frontend-collective.github.io/react-sortable-tree/?path=/story/advanced--drag-from-external-source
|
The following fix worked for me |
I added a debounce to the hover handler (with trailing option) and that solved the issue. The components were updating too quickly by setting the state before DnD could catch up, and the target ID had changed by the time the user dropped the item. So for those of you that could get the above solutions to work, maybe this may help. |
Thank you! @GNARGNARDAVE That really helped me. I wrapped my dnd function in useCallback and debounce like this:
It finally works! |
Glad that you were able to get it to work! |
Have you solved this problem yet? |
I posted a potential solution - if you haven't tried it yet, I'd suggest putting in a console.log on the hover handler if you haven't tried to debounce solution on the handler. From the console log - output the target ids and you'll notice that the target id doesn't match up because it's triggering too many changes. Try adding the debounce to the hover handler |
let me know if anyone find solution to this problem |
If you are still facing this problem, check how you update your collection (array) state when the dragging happens. Better to use an immutability helpers such as immerjs or immutability-helper. |
Anyone wondering about the Hover handler, here is a working example for me with the debounce: const [{ isOver, canDrop }, drop] = useDrop(
() => ({
accept: types.PEC,
canDrop: () => true,
drop: () => console.log("it did drop ! On PEC :", order),
collect: (monitor) => ({
isOver: !!monitor.isOver(),
canDrop: !!monitor.canDrop(),
}),
hover: debounce(() => setOver(order), 300),
}),
[]
); SetOver is a custom state passed from the parent to update the order of all the elements. |
I met the same error. I have a tree structure, when I dragged a node from one node to another node (change the parent), this error will happen. But if I only dragged a node in the current list (don't change the parent, just reorder), it is okay.
Hi, @karlavv I meet this issue too. Where did u put the function any help will be much appreciated. |
hi guys,
i cannot really post a specific code example as it's too cluttered at the moment but i think iv'e isolated the steps required to reproduce the issue.
the error was thrown at DragDropMonitor.prototype.canDropOnTarget
because it couldn't find a target with the targetID (obviously).
use case: i"m building a sortable tree and i need to relocate the dragged & hovered item
to after it's parent node:
(normal behaviour for tree's: http://pqx.github.io/react-ui-tree/)
on more thing: while the error occurs, it still works.
thanks!
The text was updated successfully, but these errors were encountered: