import React, { Component, ErrorInfo } from "react"; import { AlertCircle, RefreshCw } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; interface Props { children: React.ReactNode; sessionId: string; onRestart?: () => void; } interface State { hasError: boolean; error: Error | null; } /** * BUG-06 fix: Error boundary for terminal components * Catches xterm.js errors (WebGL context loss, canvas errors, etc.) * and displays a friendly recovery UI instead of crashing the app. */ export class TerminalErrorBoundary 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: ErrorInfo) { console.error("[TerminalErrorBoundary] Terminal crashed:", { sessionId: this.props.sessionId, error: error.message, stack: error.stack, componentStack: errorInfo.componentStack, }); } handleRestart = () => { this.setState({ hasError: false, error: null }); this.props.onRestart?.(); }; render() { if (this.state.hasError) { return (

Terminal Crashed

{this.state.error?.message?.includes("WebGL") ? "WebGL context was lost. This can happen with GPU driver issues." : "An unexpected error occurred in the terminal."}

{this.state.error && (
Technical details
                {this.state.error.message}
              
)}
); } return this.props.children; } }