import { Component, type ReactNode, type ErrorInfo } from 'react'; import { t } from '../lib/i18n'; interface Props { children: ReactNode; /** Optional fallback — defaults to built-in error card */ fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; } /** * Catches render errors in child components and shows a recovery UI * instead of a blank white screen. */ export class ErrorBoundary extends Component { state: State = { hasError: false, error: null }; static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, info: ErrorInfo) { console.error('[PinchChat] Render error caught by ErrorBoundary:', error, info.componentStack); } handleRetry = () => { this.setState({ hasError: false, error: null }); }; handleReload = () => { window.location.reload(); }; render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; return (
💥

{t('error.title')}

{t('error.description')}

{this.state.error && (
                {this.state.error.message}
              
)}
); } return this.props.children; } }