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).


  • 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.

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 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:

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

Amazing, guys, thanks @cfrank

Was this page helpful?
0 / 5 - 0 ratings