Skip to content
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

Uncaught Invariant Violation: Expected to find a valid target. #559

Closed
francisrod01 opened this issue Oct 11, 2019 · 4 comments
Closed

Uncaught Invariant Violation: Expected to find a valid target. #559

francisrod01 opened this issue Oct 11, 2019 · 4 comments
Labels

Comments

@francisrod01
Copy link

francisrod01 commented Oct 11, 2019

Uncaught Invariant Violation: Expected to find a valid target.

I'm facing this issue when I drag a tag.

image

Envs:

  • react@16.10.2
  • react-dom@16.10.2
  • react-tag-input@6.4.1
  • react-dnd@5.0.0
  • react-dnd-html5-backend@3.0.2

A related tag here: Uncaught Error: Invariant Violation: Expected to find a valid target

@jmfsilva
Copy link

DND and a little buggy.
It rarely works and most of the times i'v that error.
Envs:

  • "react": "^16.9.0"
  • "react-dom": "^16.9.0"
  • "react-dnd": "^5.0.0" (as recommended)
  • "react-dnd-html5-backend": "^3.0.2", (as recommended)

@jameswyse
Copy link

I'm getting the same error. I think it's because the key prop isn't stable

Currently it's set to key={${tag.id}-${index}} in ReactTags.js:389
Changing it to key={tag.id} fixed the problem for me!

@stale
Copy link

stale bot commented Jan 24, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the Stale label Jan 24, 2020
@stale stale bot closed this as completed Jan 31, 2020
@tankorsmash
Copy link
Contributor

tankorsmash commented Feb 25, 2020

I'm having the same issue with dragging a tag and throwing the invariant error about not being able to find a target.

Same as above, except

"react": "^16.8.0"
"@hot-loader/react-dom": "^16.8.0"

Some potential causes is inconsistent ids (maybe based on their position on the array) and keys. We'll see if I can make any progress on my own error.

edit: it seems like ReactTags (or my own code somewhere...) is adding the index to the key of the Tag, which needs to not happen so that dnd can track the values, I think.
image

This is likely happening in ReactTags.js, which was introduced in this commit to allow duplicate/unique tags.

I'm not sure what to do, because if you remove the idx variable there, you can no longer have duplicate tags. Maybe @prakhar1989 has an idea.

tankorsmash added a commit to tankorsmash/react-tags that referenced this issue Feb 25, 2020
As mentioned in an issue, react-tags#559, if you drag and drop, React DND throws an invariant issue.

This change makes it so if you pass in a third property to each of your tags, you can have drag and drop. 

I haven't tested any other usecases beyond mine though, so if anyone else wanted to confirm this works for them, that would be appreciated. Meanwhile, the change can be made in your local `node_modules\react-tag-input\dist-modules\components\ReactTags.js#523`
ad1992 pushed a commit that referenced this issue May 27, 2020
* fix drag and drop not working

As mentioned in an issue, #559, if you drag and drop, React DND throws an invariant issue.

This change makes it so if you pass in a third property to each of your tags, you can have drag and drop. 

I haven't tested any other usecases beyond mine though, so if anyone else wanted to confirm this works for them, that would be appreciated. Meanwhile, the change can be made in your local `node_modules\react-tag-input\dist-modules\components\ReactTags.js#523`

* update Tag shape to include new key property

Co-authored-by: TankorSmash <tankorsmash+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants