-
Notifications
You must be signed in to change notification settings - Fork 917
fix: "Uncaught Invariant Violation: Expected to find a valid target."… #740
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
Conversation
… after cancelling a drag into the react sortable tree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works
Hit the same error, this looks like it works. |
I had also hit the same error while I was trying to do a simple tree to tree drag and drop. I tried a local build and the issue resolves. But I am not sure why this actually works. Any idea? |
This fix seems to work, but I am not sure why. @wuweiweiwu is there any reason this PR doesn't have a high prio considering it closes a lot of the open issue |
@@ -230,7 +230,7 @@ class ReactSortableTree extends Component { | |||
// it means that the drag was canceled or the dragSource dropped | |||
// elsewhere, and we should reset the state of this tree | |||
if (!monitor.isDragging() && this.state.draggingTreeData) { | |||
this.endDrag(); | |||
setTimeout(() => {this.endDrag()}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please describe what's to do in this statement. And write a test case to make this PR available to merge and realese
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't figure out a way to write a test case for this, but here's an attempt to describe what's happening:
// If the drag ends and the tree is still in a mid-drag state, it
// means that the drag was canceled or the dragSource dropped
// elsewhere, and we should reset the state of this tree.
//
// However, right now react-dnd is still processing its events, and
// if we unmount the mid-drag React components immediately (by calling
// this.endDrag()), that processing will run into errors (see
// https://github.com/react-dnd/react-dnd/issues/1368 for details).
// So let react-dnd process its events completely (which happens synchronously)
// before we call endDrag).
It looks like setTimeout pushes the execution of this.endDrag further in the JS' task queue and we seem to be hitting an invariant violation in while/after calling this.setState({...}) via resetTree method. Someone can correct me if the above explanation is wrong. |
Hi ! Could this pull request be merged to the main one ? |
+1 on merging this PR, this is a pretty crucial bug fix. Thanks @weirDozzz! In the meantime, you can run |
Does this PR need anything else to be merged? We are waiting for this bugfix too. Thanks @weirDozzz |
Any progress here? The tree is unusable for us without this fix. |
How can we help to merge this PR? |
seems that this is not published right now |
+1, @lifejuggler Can we get a new version of |
it doesn't solve the issue with the patch (or even master since it's on master now)
|
fix: "Uncaught Invariant Violation: Expected to find a valid target." after cancelling a drag into the react sortable tree