import React, { Component, ErrorInfo, ReactNode } from "react"; import { AlertTriangle, RefreshCw, Terminal, ChevronDown, ChevronUp } from "lucide-react"; import { Button } from "@/components/ui/button"; interface ErrorLog { error: Error; errorInfo: ErrorInfo; timestamp: number; } interface Props { children: ReactNode; } interface State { hasError: boolean; errors: ErrorLog[]; isExpanded: boolean; } export class ErrorBoundary extends Component { public state: State = { hasError: false, errors: [], isExpanded: false }; public static getDerivedStateFromError(error: Error): Partial { return { hasError: true }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("CRITICAL UI ERROR:", error, errorInfo); // معالجة أخطاء الاستيراد الديناميكي (Dynamic Import Errors) if (error.name === 'TypeError' && (error.message.includes('dynamically imported module') || error.message.includes('Failed to fetch'))) { console.warn("Dynamic import failed. Attempting to reload the page to fetch the latest assets..."); window.location.reload(); return; } const newError: ErrorLog = { error, errorInfo, timestamp: Date.now() }; this.setState(prevState => ({ errors: [...prevState.errors, newError] })); } private handleReset = () => { this.setState({ hasError: false, errors: [], isExpanded: false }); window.location.href = '/'; }; private toggleExpand = () => { this.setState(prev => ({ isExpanded: !prev })); }; public render() { if (this.state.hasError && this.state.errors.length > 0) { const latestError = this.state.errors[this.state.errors.length - 1]; return (

System Failure

تعرض التطبيق لعدة أخطاء برمجية. تم تجميع كافة الأخطاء أدناه لمساعدتك في التشخيص.

Detected Errors ({this.state.errors.length})
{this.state.errors.map((err, index) => (
Error #{index + 1} {new Date(err.timestamp).toLocaleTimeString()}
Message: {err.error.message || "Unknown Error"}
{(this.state.isExpanded || index === this.state.errors.length - 1) && (
{err.error.stack || "No stack trace available"}
)}
)).reverse()}

Minecraft FX Recovery Environment v1.1 • Multiple Error Support

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