React-dnd: Crashing in isOver with empty targetId

Created on 7 Mar 2019  ·  7Comments  ·  Source: react-dnd/react-dnd

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

  • Downgrading back to 6.0.0 resolved the issue.
  • Also, using a short 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:

  1. Connect a Drop target, call monitor.isOver() in collect
  2. in the target, dispatch an action inside drop(...) that removes the drop target
  3. See error

Expected behavior
There is no timing issue with isOver and drop targets can be immediately removed.

Screenshots
bildschirmfoto 2019-03-07 um 00 58 04

Desktop (please complete the following information):

  • OS: os x
  • Browser chrome
  • react-dnd / html5 backend 7.1.0

Most helpful comment

This should be fixed by cfrank's PR in a release today

All 7 comments

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

Was this page helpful?
0 / 5 - 0 ratings