import { Component, type ReactNode, type ErrorInfo } from 'react'; interface Props { children: ReactNode; } interface State { hasError: boolean; message: string; } /** Catches any render/effect error so the app degrades to a recoverable * message instead of a blank white screen. */ export default class ErrorBoundary extends Component { state: State = { hasError: false, message: '' }; static getDerivedStateFromError(error: Error): State { return { hasError: true, message: error.message }; } componentDidCatch(error: Error, info: ErrorInfo) { console.error('Caught by ErrorBoundary:', error, info); } render() { if (this.state.hasError) { return (
Something went wrong while updating the graph. {this.state.message ? ` (${this.state.message})` : ''}
); } return this.props.children; } }