mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 08:11:53 +02:00
Clear scroll timer when component unmount (#867)
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user