Uncaught Error: Invariant Violation: Expected to find a valid target.

See original GitHub issue

I’ve implemented a sortable list and another list to drag items from into that sortable list. The app works as expected. But when I try to move around items that have initially been in that sortable list, I get the following error:

Uncaught Error: Invariant Violation: Expected to find a valid target
.n @ app.js:50803
t.canDropOnTarget @ app.js:50804
(anonymous function) @ app.js:50804
t.handleTopDragEnter @ app.js:50804

I have no idea where to start, because the code works reliably and I only have a the minified version dist/ReactDnD.min.js.

Any hint? What could be a typical for causing this error?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:29 (4 by maintainers)

github_iconTop GitHub Comments

37reactions
mariomccommented, Jun 10, 2018

Just in case someone stumbles on this error and issue, I had a similar issue when composing a sortable list and each item having a key composed of the concatenation of its id and its index on the list. The fix was simply done by setting a proper (ie, consistent) key for the element being dragged.

18reactions
chulanovskyicommented, Feb 10, 2019

If someone still runs in this issue, please note that the element of the list you are mapping by needs to have a persistent key prop. In my case I was dispatching a Redux action to change the items in list, and then providing the key to the mapped element like this:

blocks.map((block, idx) => {
  <React.Fragment key={`${block.name}_${idx}`}>
    ...
  <React.Fragment />
})

which apparently fires the error, because the idx is changing on-the-fly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React DnD Expected to find a valid target - Stack Overflow
The problem is that the component is updating too quickly and the target id that DnD is expecting, has already changed due to...
Read more >
gaearon/react-dnd - Gitter
and i try to create a mini demo , first dnd is ok, but second is Uncaught Invariant Violation: Expected to find a...
Read more >
React Dnd Expected To Find A Valid Target - ADocLib
and i try to create a mini demo first dnd is ok but second is Uncaught Invariant Violation: Expected to find a valid...
Read more >
"Uncaught Invariant Violation: Expected to find a valid target ...
"Uncaught Invariant Violation: Expected to find a valid target." after cancelling a drag into the react sortable tree ... I discovered this issue ......
Read more >
cuong-react-sortable-tree - npm package - Snyk
In the past month we didn't find any pull request activity or change in issues ... error: "Uncaught Invariant Violation: Expected to find...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found