diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index 4b5ee4b..0b7363d 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -3,10 +3,15 @@ import { t } from '../i18n' import { Empty } from './Page' // Without this, one component throwing while rendering unmounts the whole app and leaves a white -// page. The layout keys it by route, so moving to another page clears the error. -export class ErrorBoundary extends Component<{ children: ReactNode }, { error: Error | null }> { +// page. The layout keys it by route, so moving to another page clears the error; main.tsx also puts +// one around the whole app (the layout included), cleared by a change of `resetKey`. +export class ErrorBoundary extends Component<{ children: ReactNode; resetKey?: string; className?: string }, { error: Error | null }> { state = { error: null as Error | null } + componentDidUpdate(prev: { resetKey?: string }) { + if (this.state.error && prev.resetKey !== this.props.resetKey) this.setState({ error: null }) + } + static getDerivedStateFromError(error: Error) { return { error } } @@ -19,11 +24,11 @@ export class ErrorBoundary extends Component<{ children: ReactNode }, { error: E const { error } = this.state if (!error) return this.props.children return ( -