import { Component, type ReactNode } from "react"; import { notify } from "../lib/notifications"; interface Props { children: ReactNode; } interface State { crashed: boolean; } // Catches render-time crashes anywhere in the tree, logs a fatal notification (kept // in the center across the reload) and offers a recovery action. export default class ErrorBoundary extends Component { state: State = { crashed: false }; static getDerivedStateFromError(): State { return { crashed: true }; } componentDidCatch(error: Error) { notify({ level: "fatal", title: "Something broke", message: error.message || "Unexpected error", requiresInteraction: true, }); } render() { if (this.state.crashed) { return (
Something went wrong.
The app hit an unexpected error.
); } return this.props.children; } }