1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 13:11:17 +02:00

Add error boundary to save Slate from a crash on corrupt DOM (#2792)

* Working version of restore dom

* Fix linting errors

* Add button to corrupt DOM

* Added error boundary that fixes DOM on render error

* Fix linting errors

* Fix debug output for componentDidCatch

* Improve example by adding a separate restoreDOM button

* Remove key change from error boundary which is not necessary

* Fix linting error
This commit is contained in:
Sunny Hirai
2019-05-16 16:26:13 -07:00
committed by GitHub
parent fd8e18b9cf
commit 48eb6700b7
3 changed files with 130 additions and 9 deletions

View File

@@ -75,6 +75,22 @@ class Content extends React.Component {
tagName: 'div',
}
/**
* An error boundary. If there is a render error, we increment `errorKey`
* which is part of the container `key` which forces a re-render from
* scratch.
*
* @param {Error} error
* @param {String} info
*/
componentDidCatch(error, info) {
debug('componentDidCatch', { error, info })
// The call to `setState` is required despite not setting a value.
// Without this call, React will not try to recreate the component tree.
this.setState({})
}
/**
* Temporary values.
*