import { AlertTriangle, RefreshCw } from 'lucide-react'; import { Component, type ErrorInfo, type ReactNode } from 'react'; import log from 'electron-log/renderer'; import TextButton from './styled/TextButton'; type Props = { tabName: string; children: ReactNode; }; type State = { error?: Error; componentStack?: string; }; class TabErrorBoundary extends Component { state: State = {}; static getDerivedStateFromError(error: Error): State { return { error }; } componentDidCatch(error: Error, info: ErrorInfo) { log.error(`Tab "${this.props.tabName}" crashed:`, error, info); this.setState({ error, componentStack: info.componentStack ?? undefined }); } componentDidUpdate(prevProps: Props) { if (prevProps.tabName !== this.props.tabName) { this.setState({ error: undefined, componentStack: undefined }); } } #reset = () => this.setState({ error: undefined, componentStack: undefined }); render() { if (!this.state.error) return this.props.children; const { error, componentStack } = this.state; return (

{this.props.tabName} crashed


{error.name}: {error.message}

{componentStack && (
						{componentStack.trim()}
					
)}
Try again
); } } export default TabErrorBoundary;