/** * React error boundary component. * * Catches render-time exceptions in child components and shows a fallback UI. */ import React from "react"; interface ErrorBoundaryState { hasError: boolean; errorMessage: string | null; } interface ErrorBoundaryProps { children: React.ReactNode; } export class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, errorMessage: null }; this.handleReload = this.handleReload.bind(this); } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, errorMessage: error.message || "Unknown error" }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { console.error("ErrorBoundary caught an error", { error, errorInfo }); } handleReload(): void { window.location.reload(); } render(): React.ReactNode { if (this.state.hasError) { return (

Something went wrong

{this.state.errorMessage ?? "Please try reloading the page."}

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