Make Hyper more robust against plugins
* Add some try/catch * Support React@16 error boundaries for render decorated components
This commit is contained in:
parent
3e632577e5
commit
9bd410f1e4
2 changed files with 51 additions and 8 deletions
|
|
@ -431,7 +431,11 @@ function exposeDecorated(Component_) {
|
|||
}
|
||||
onRef(decorated_) {
|
||||
if (this.props.onDecorated) {
|
||||
this.props.onDecorated(decorated_);
|
||||
try {
|
||||
this.props.onDecorated(decorated_);
|
||||
} catch (e) {
|
||||
notify('Plugin error', `Error occurred. Check Developer Tools for details`);
|
||||
}
|
||||
}
|
||||
}
|
||||
render() {
|
||||
|
|
@ -487,9 +491,21 @@ function getDecorated(parent, name) {
|
|||
// that wraps with the higher-order components
|
||||
// exposed by plugins
|
||||
export function decorate(Component_, name) {
|
||||
return class DecoratedCompenent extends React.Component {
|
||||
return class DecoratedComponent extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {has_error: false};
|
||||
}
|
||||
componentDidCatch() {
|
||||
this.setState({hasError: true});
|
||||
// No need to detail this error because React print those informations.
|
||||
notify(
|
||||
'Plugin error',
|
||||
`Plugins decorating ${name} has been disabled because of a plugin crash. Check Developer Tools for details.`
|
||||
);
|
||||
}
|
||||
render() {
|
||||
const Sub = getDecorated(Component_, name);
|
||||
const Sub = this.state.hasError ? Component_ : getDecorated(Component_, name);
|
||||
return React.createElement(Sub, this.props);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue