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:
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user