|
@@ -49,10 +49,15 @@ class ErrorBoundary extends React.Component<Props, State> {
|
|
};
|
|
};
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
|
+ this._isMounted = true;
|
|
// Listen for route changes so we can clear error
|
|
// Listen for route changes so we can clear error
|
|
- this.unlistenBrowserHistory = browserHistory.listen(() =>
|
|
|
|
- this.setState({error: null})
|
|
|
|
- );
|
|
|
|
|
|
+ this.unlistenBrowserHistory = browserHistory.listen(() => {
|
|
|
|
+ // Prevent race between component unmount and browserHistory change
|
|
|
|
+ // Setting state on a component that is being unmounted throws an error
|
|
|
|
+ if (this._isMounted) {
|
|
|
|
+ this.setState({error: null});
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
@@ -70,13 +75,14 @@ class ErrorBoundary extends React.Component<Props, State> {
|
|
}
|
|
}
|
|
|
|
|
|
componentWillUnmount() {
|
|
componentWillUnmount() {
|
|
|
|
+ this._isMounted = false;
|
|
if (this.unlistenBrowserHistory) {
|
|
if (this.unlistenBrowserHistory) {
|
|
this.unlistenBrowserHistory();
|
|
this.unlistenBrowserHistory();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // XXX: browserHistory.listen does not have a correct return type.
|
|
|
|
- unlistenBrowserHistory: any;
|
|
|
|
|
|
+ private unlistenBrowserHistory?: ReturnType<typeof browserHistory.listen>;
|
|
|
|
+ private _isMounted = false;
|
|
|
|
|
|
render() {
|
|
render() {
|
|
const {error} = this.state;
|
|
const {error} = this.state;
|