From 3ce35f3f7b0c5c045e9a8e90b921b52362c005f7 Mon Sep 17 00:00:00 2001 From: fritz-c Date: Sat, 9 Dec 2017 13:24:33 +0900 Subject: [PATCH] fix: dragging past the bottom of the tree no longer slows down rendering When dragging a node with a visible child to the last row displayed for the tree, a render was triggered for each dragover event, causing significant slowdown. The issue lied in the fact that the child was being perceived as another node with which the dragged node should swap with. The new implementation adds another condition - stopping the rendering short if the previous render used the same drag position (depth and minimum index). --- src/react-sortable-tree.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/react-sortable-tree.js b/src/react-sortable-tree.js index bfd1e7e1..76df00de 100644 --- a/src/react-sortable-tree.js +++ b/src/react-sortable-tree.js @@ -319,6 +319,14 @@ class ReactSortableTree extends Component { depth: draggedDepth, minimumTreeIndex: draggedMinimumTreeIndex, }) { + // Ignore this hover if it is at the same position as the last hover + if ( + this.state.draggedDepth === draggedDepth && + this.state.draggedMinimumTreeIndex === draggedMinimumTreeIndex + ) { + return; + } + // Fall back to the tree data if something is being dragged in from // an external element const draggingTreeData = this.state.draggingTreeData || this.props.treeData;