import { Component, type JSX, type ReactNode } from 'react'; import { AlertTriangle } from 'lucide-react'; interface DiffErrorBoundaryProps { children: ReactNode; filePath: string; oldString?: string; newString?: string; onRetry?: () => void; } interface DiffErrorBoundaryState { hasError: boolean; error: Error | null; } export class DiffErrorBoundary extends Component { constructor(props: DiffErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): DiffErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void { console.error( '[DiffErrorBoundary] Error rendering diff for', this.props.filePath, error, errorInfo ); } render(): JSX.Element { if (!this.state.hasError) { return <>{this.props.children}; } const { filePath, oldString, newString, onRetry } = this.props; const { error } = this.state; return (
Failed to render diff view

{error?.message ?? 'An unexpected error occurred while rendering the diff.'}

{onRetry && ( )}
{(oldString || newString) && (
Show raw diff data
File: {filePath}
{oldString && (
--- Original
{oldString.slice(0, 2000)}
{oldString.length > 2000 && ( ... ({oldString.length} chars total) )}
)} {newString && (
+++ Modified
{newString.slice(0, 2000)}
{newString.length > 2000 && ( ... ({newString.length} chars total) )}
)}
)}
); } }