import { Component, type ErrorInfo, type ReactNode } from 'react'; interface ErrorBoundaryProps { children: ReactNode; fallback?: ReactNode; } interface ErrorBoundaryState { hasError: boolean; } /** Catches render-time errors in the tree and shows a fallback UI. */ export class ErrorBoundary extends Component { state: ErrorBoundaryState = { hasError: false }; static getDerivedStateFromError(): ErrorBoundaryState { return { hasError: true }; } componentDidCatch(error: Error, info: ErrorInfo): void { console.error('Unhandled error in component tree', error, info.componentStack); } render(): ReactNode { if (this.state.hasError) { return ( this.props.fallback ?? (

Something went wrong. Please reload the page.

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