Skip to content

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

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

weirDozzz
Copy link
Contributor

fix: "Uncaught Invariant Violation: Expected to find a valid target." after cancelling a drag into the react sortable tree

… after cancelling a drag into the react sortable tree
@coveralls
Copy link

Coverage Status

Coverage remained the same at 76.492% when pulling 9a84113 on weirDozzz:master into 1c1ed8c on frontend-collective:master.

Copy link

@guramnozadze guramnozadze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works

patrickliangli pushed a commit to patrickliangli/react-sortable-tree that referenced this pull request Aug 18, 2020
@7ruth
Copy link

7ruth commented Sep 6, 2020

Hit the same error, this looks like it works.

@redoy11
Copy link

redoy11 commented Sep 9, 2020

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?

danwit added a commit to danwit/react-sortable-tree that referenced this pull request Sep 12, 2020
@hoshomoh
Copy link

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()});

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

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

@mahendradambe
Copy link

Could you explain a bit this fix - it works but I'm not sure why this works? :D

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.

@dimitriacseo
Copy link

Hi ! Could this pull request be merged to the main one ?

@anthonykrivonos
Copy link

anthonykrivonos commented Apr 5, 2021

+1 on merging this PR, this is a pretty crucial bug fix. Thanks @weirDozzz!

In the meantime, you can run npm install / yarn add git+https://github.com/weirDozzz/react-sortable-tree.git to use the code off this PR.

@Divyahb
Copy link

Divyahb commented Apr 26, 2021

Does this PR need anything else to be merged? We are waiting for this bugfix too. Thanks @weirDozzz

@RikuK
Copy link

RikuK commented May 27, 2021

Any progress here? The tree is unusable for us without this fix.

@relferreira
Copy link

How can we help to merge this PR?

@lifejuggler lifejuggler merged commit 52f0bcf into frontend-collective:master Jun 11, 2021
@iamtofr
Copy link

iamtofr commented Jun 17, 2021

seems that this is not published right now

@anthonykrivonos
Copy link

+1, @lifejuggler Can we get a new version of react-sortable-tree published?

@hacking-robot
Copy link

it doesn't solve the issue with the patch (or even master since it's on master now)

index.ts:28 Uncaught Invariant Violation: Expected to find a valid target.
    at invariant (http://localhost:3000/static/js/0.chunk.js:86649:15)
    at DragDropMonitorImpl.canDropOnTarget (http://localhost:3000/static/js/0.chunk.js:122304:77)
    at DropTargetMonitorImpl.canDrop (http://localhost:3000/static/js/0.chunk.js:233347:37)
    at nodeDropTargetPropInjection (http://localhost:3000/static/js/0.chunk.js:270846:28)
    at DragDropContainer.getCurrentState (http://localhost:3000/static/js/0.chunk.js:234955:27)
    at DragDropContainer._this.handleChange (http://localhost:3000/static/js/0.chunk.js:234849:33)
    at handleChange (http://localhost:3000/static/js/0.chunk.js:122249:13)
    at dispatch (http://localhost:3000/static/js/0.chunk.js:287020:7)
    at Object.endDrag (http://localhost:3000/static/js/0.chunk.js:122155:13)
    at HTML5BackendImpl.handleTopDragEndCapture (http://localhost:3000/static/js/0.chunk.js:231684:23)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.