/** * Error boundary that catches render errors in the app tree and shows a fallback * with a reload option. Uses pure i18n (getLang/translate) so it does not depend * on React context that might be broken. */ "use client"; import React from "react"; import { getLang } from "@/i18n/messages"; import { translate } from "@/i18n/messages"; import { Button } from "@/components/ui/button"; interface AppErrorBoundaryProps { children: React.ReactNode; } interface AppErrorBoundaryState { hasError: boolean; } /** * Catches JavaScript errors in the child tree and renders a fallback UI * instead of crashing. Provides a Reload button to recover. */ export class AppErrorBoundary extends React.Component< AppErrorBoundaryProps, AppErrorBoundaryState > { constructor(props: AppErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(): AppErrorBoundaryState { return { hasError: true }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { if (typeof console !== "undefined" && console.error) { console.error("AppErrorBoundary caught an error:", error, errorInfo); } } handleReload = (): void => { if (typeof window !== "undefined") { window.location.reload(); } }; render(): React.ReactNode { if (this.state.hasError) { const lang = getLang(); const message = translate(lang, "error_boundary.message"); const reloadLabel = translate(lang, "error_boundary.reload"); return (

{message}

); } return this.props.children; } }