Describe the bug
I have a connected drop target that is removed from the DOM, once something is dropped on to it.
Now since upgrading to v7.1.0
, I'm getting
Uncaught TypeError: Cannot read property '0' of undefined
in the monitor.isOver()
call inside the collect
function.
Somehow, it sees that the collect function is still called one more time, after the drop target has been removed (targetId
is undefined).
Interesting
6.0.0
resolved the issue.setTimeout
wrapper around my callback that removed the drop target, resolved the issue.Any idea what could cause that?
To Reproduce
Steps to reproduce the behavior:
monitor.isOver()
in collect
drop(...)
that removes the drop targetExpected behavior
There is no timing issue with isOver
and drop targets can be immediately removed.
Screenshots
Desktop (please complete the following information):
7.1.0
Same issue
I tried to revert this change https://github.com/react-dnd/react-dnd/commit/0feb250b7ee90483e31f3bc159ebf946980d53a7#diff-ac418ba19283aec1fb0b70e6570c5613 and resolved.. .
Same issue.
Waiting for fix.
Rolled back to v7.0.2
Confirmed we are receiving the same issue - Reverting to 7.0.2 fixes the issue
This is being caused because the change at 0feb250b7ee90483e31f3bc159ebf946980d53a7 is allowing target ID to be undefined
but nobody checked the PR with that change for isOverTarget
Currently it's prototype is:
public isOverTarget(targetId: string, options = { shallow: false })
unlike the other functions which changed in that pr which move targetId
/ sourceId
to
targetId: string | undefined
sourceId: string | undefined
and check:
if (!targetId) {
return false;
}
A fix for this issue will be to check for targetId
being undefined
here: https://github.com/mattkrick/react-dnd/blob/aafcf7d67f8b3a2035b561e97b7874e1064447e4/packages/dnd-core/src/DragDropMonitorImpl.ts#L128
This should be fixed by cfrank's PR in a release today
Amazing, guys, thanks @cfrank
Most helpful comment
This should be fixed by cfrank's PR in a release today