import { Component, type ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; } /** * React Error Boundary — catches render errors from child components * and displays a fallback UI instead of crashing the entire app. * * Use this to wrap components that may throw during render (e.g., ACE editor). */ export default class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error('[ErrorBoundary] caught render error:', error, errorInfo); } render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; return (

Something went wrong

{this.state.error?.message || 'An unexpected error occurred.'}

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