From 884ada45b06ed9e6ea7cb3b394d1ce0119a9d04c Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 26 Oct 2014 01:04:44 +0400 Subject: [PATCH] You'd expect `endDrag` not to be called on an unmounted component --- modules/mixins/DragDropMixin.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/mixins/DragDropMixin.js b/modules/mixins/DragDropMixin.js index 90dcf76462..a9954d4fbe 100644 --- a/modules/mixins/DragDropMixin.js +++ b/modules/mixins/DragDropMixin.js @@ -160,24 +160,25 @@ var DragDropMixin = { }, handleDragEnd(type, e) { - - // Note: this method may be invoked even *after* component was unmounted - // This happens if source node was removed from DOM while dragging. - // We mustn't assume being mounted, but still need to gracefully reset state. - NativeDragDropSupport.handleDragEnd(); - if (this.isMounted()) { - this.setState({ - ownDraggedItemType: null - }); - } - var { endDrag } = this._dragSources[type], didDrop = DragDropStore.didDrop(); DragDropActionCreators.endDragging(); + if (!this.isMounted()) { + + // Note: this method may be invoked even *after* component was unmounted + // This happens if source node was removed from DOM while dragging. + + return; + } + + this.setState({ + ownDraggedItemType: null + }); + if (endDrag) { endDrag(didDrop, e); }