From b967cf7c7936ad8a539e1b18c7d3da1f1d92eec9 Mon Sep 17 00:00:00 2001 From: pa-nam Date: Sun, 11 Jun 2017 00:41:27 +0700 Subject: [PATCH] Clear scroll timer when component unmount (#867) --- src/components/node.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/node.js b/src/components/node.js index a3ced6b60..64327abf2 100644 --- a/src/components/node.js +++ b/src/components/node.js @@ -161,6 +161,17 @@ class Node extends React.Component { if (this.props.node != prevProps.node) this.updateScroll() } + /** + * There is a corner case, that some nodes are unmounted right after they update + * Then, when the timer execute, it will throw the error + * `findDOMNode was called on an unmounted component` + * We should clear the timer from updateScroll here + */ + + componentWillUnmount = () => { + clearTimeout(this.scrollTimer) + } + /** * Update the scroll position after a change as occured if this is a leaf * block and it has the selection's ending edge. This ensures that scrolling @@ -182,7 +193,7 @@ class Node extends React.Component { // The native selection will be updated after componentDidMount or componentDidUpdate. // Use setTimeout to queue scrolling to the last when the native selection has been updated to the correct value. - setTimeout(() => { + this.scrollTimer = setTimeout(() => { const el = ReactDOM.findDOMNode(this) const window = getWindow(el) const native = window.getSelection()