/** * React error boundary wrapping CodeMirrorEditor. * * Catches runtime CM6 errors (OOM, bad extension, corrupted EditorState) * and shows a fallback UI instead of crashing the entire overlay. */ import React from 'react'; import { AlertTriangle } from 'lucide-react'; interface Props { filePath: string; onRetry?: () => void; children: React.ReactNode; } interface State { hasError: boolean; error: string | null; } export class EditorErrorBoundary extends React.Component { state: State = { hasError: false, error: null }; static getDerivedStateFromError(error: Error): State { return { hasError: true, error: error.message }; } componentDidCatch(error: Error, info: React.ErrorInfo): void { console.error(`[EditorErrorBoundary] ${this.props.filePath}:`, error, info.componentStack); } handleRetry = (): void => { this.setState({ hasError: false, error: null }); this.props.onRetry?.(); }; render(): React.ReactElement { if (this.state.hasError) { return (
); } return <>{this.props.children}; } }