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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/react-sortable-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).

}
}

Expand Down