import { Component, type ErrorInfo, type ReactNode } from "react"; interface Props { children: ReactNode; } interface State { error: Error | null; } // خطای رندر/لود ماژول نباید کل DOM را خالی کند — با این باکس، به‌جای صفحه‌ی // سفید، پیام + دکمه‌ی «تلاش مجدد» (بارگذاری مجدد صفحه) نمایش داده می‌شود. export class ErrorBoundary extends Component { state: State = { error: null }; static getDerivedStateFromError(error: Error): State { return { error }; } componentDidCatch(error: Error, info: ErrorInfo) { console.error("ErrorBoundary caught:", error, info); } private retry = () => { this.setState({ error: null }); window.location.reload(); }; render() { if (!this.state.error) return this.props.children; return (
⚠️

خطایی در نمایش صفحه رخ داد

{this.state.error.message || "مشکلی پیش آمد — لطفاً دوباره تلاش کنید."}

); } }