import { Component, type ErrorInfo, type ReactNode } from "react"; import { withTranslation, type WithTranslation } from "react-i18next"; interface Props extends WithTranslation { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; } /** * Error boundary is a classical React class component, so we bridge it to * i18next via the `withTranslation` HOC. That keeps the tree-shaking of * `react-i18next`'s hook path intact while giving us a `t` prop here. */ class ErrorBoundaryInner extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("ErrorBoundary caught:", error, errorInfo); } render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; const { t } = this.props; return (

{t("errors.somethingWrong")}

{t("errors.unexpectedDescription")}

{this.state.error && (
{t("errors.errorDetails")}
{this.state.error.message}
)}
); } return this.props.children; } } export const ErrorBoundary = withTranslation()(ErrorBoundaryInner);