import React from 'react'; export class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error) { return { hasError: true, error }; } componentDidCatch(error, errorInfo) { console.error("Uncaught Error caught by ErrorBoundary:", error, errorInfo); // If it's a chunk loading error (common during SPA back-navigation with lazy routes), auto-reload page once if (error && (error.name === 'ChunkLoadError' || error.message?.includes('dynamically imported module') || error.message?.includes('Importing a module script failed'))) { const hasReloaded = sessionStorage.getItem('chunk_reload_retry'); if (!hasReloaded) { sessionStorage.setItem('chunk_reload_retry', 'true'); window.location.reload(); } } } componentDidMount() { sessionStorage.removeItem('chunk_reload_retry'); window.addEventListener('popstate', this.handlePopState); } componentWillUnmount() { window.removeEventListener('popstate', this.handlePopState); } handlePopState = () => { if (this.state.hasError) { this.setState({ hasError: false, error: null }); } }; render() { if (this.state.hasError) { return (
Sorry, due to a temporary technical issue, this page could not be displayed properly. Please refresh the page or contact our support team if the problem persists.