Skip to content

Commit 496f82e

Browse files
acustiSTRML
authored andcommitted
Get ownerDocument before calling onStop handlers (#198)
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.
1 parent 8542089 commit 496f82e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/DraggableCore.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ export default class DraggableCore extends React.Component {
301301
if (position == null) return;
302302
const {x, y} = position;
303303
const coreEvent = createCoreData(this, x, y);
304+
const {ownerDocument} = ReactDOM.findDOMNode(this);
304305

305306
// Remove user-select hack
306-
if (this.props.enableUserSelectHack) removeUserSelectStyles(ReactDOM.findDOMNode(this).ownerDocument.body);
307+
if (this.props.enableUserSelectHack) removeUserSelectStyles(ownerDocument.body);
307308

308309
log('DraggableCore: handleDragStop: %j', coreEvent);
309310

@@ -318,7 +319,6 @@ export default class DraggableCore extends React.Component {
318319
this.props.onStop(e, coreEvent);
319320

320321
// Remove event handlers
321-
const {ownerDocument} = ReactDOM.findDOMNode(this);
322322
log('DraggableCore: Removing handlers');
323323
removeEvent(ownerDocument, dragEventFor.move, this.handleDrag);
324324
removeEvent(ownerDocument, dragEventFor.stop, this.handleDragStop);

0 commit comments

Comments
 (0)