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()