From 2c1a9a3f1cf7df861e4d25f94ef7693d397e32cd Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Tue, 6 Sep 2016 11:26:32 -0700 Subject: [PATCH] Get ownerDocument before calling onStop handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a draggable onStop handler causes the wrapped component to unmount, ReactDOM.findDOMNode will error with “Uncaught Invariant Violation: findDOMNode was called on an unmounted component”. This avoids that. Plus it’s cleaner. --- lib/DraggableCore.es6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/DraggableCore.es6 b/lib/DraggableCore.es6 index 1e630dd3..eb36d6cb 100644 --- a/lib/DraggableCore.es6 +++ b/lib/DraggableCore.es6 @@ -301,9 +301,10 @@ export default class DraggableCore extends React.Component { if (position == null) return; const {x, y} = position; const coreEvent = createCoreData(this, x, y); + const {ownerDocument} = ReactDOM.findDOMNode(this); // Remove user-select hack - if (this.props.enableUserSelectHack) removeUserSelectStyles(ReactDOM.findDOMNode(this).ownerDocument.body); + if (this.props.enableUserSelectHack) removeUserSelectStyles(ownerDocument.body); log('DraggableCore: handleDragStop: %j', coreEvent); @@ -318,7 +319,6 @@ export default class DraggableCore extends React.Component { this.props.onStop(e, coreEvent); // Remove event handlers - const {ownerDocument} = ReactDOM.findDOMNode(this); log('DraggableCore: Removing handlers'); removeEvent(ownerDocument, dragEventFor.move, this.handleDrag); removeEvent(ownerDocument, dragEventFor.stop, this.handleDragStop);