mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 09:11:12 -05:00
Refactor: Implement chunk load error recovery
This commit is contained in:
@@ -120,6 +120,9 @@ function NavigationTracker() {
|
||||
const from = prevLocation.current || undefined;
|
||||
breadcrumb.navigation(location.pathname, from);
|
||||
prevLocation.current = location.pathname;
|
||||
|
||||
// Clear chunk load reload flag on successful navigation
|
||||
sessionStorage.removeItem('chunk-load-reload');
|
||||
}, [location.pathname]);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -32,13 +32,35 @@ export class RouteErrorBoundary extends Component<RouteErrorBoundaryProps, Route
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||
// Detect chunk load failures (deployment cache issue)
|
||||
const isChunkLoadError =
|
||||
error.message.includes('Failed to fetch dynamically imported module') ||
|
||||
error.message.includes('Loading chunk') ||
|
||||
error.message.includes('ChunkLoadError');
|
||||
|
||||
if (isChunkLoadError) {
|
||||
// Check if we've already tried reloading
|
||||
const hasReloaded = sessionStorage.getItem('chunk-load-reload');
|
||||
|
||||
if (!hasReloaded) {
|
||||
// Mark as reloaded and reload once
|
||||
sessionStorage.setItem('chunk-load-reload', 'true');
|
||||
window.location.reload();
|
||||
return; // Don't log error yet
|
||||
} else {
|
||||
// Second failure - clear flag and show error
|
||||
sessionStorage.removeItem('chunk-load-reload');
|
||||
}
|
||||
}
|
||||
|
||||
// Log to database and get error ID for user reference
|
||||
const errorId = handleError(error, {
|
||||
action: 'Route-level component crash',
|
||||
metadata: {
|
||||
componentStack: errorInfo.componentStack,
|
||||
url: window.location.href,
|
||||
severity: 'critical',
|
||||
severity: isChunkLoadError ? 'medium' : 'critical',
|
||||
isChunkLoadError,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -55,6 +77,11 @@ export class RouteErrorBoundary extends Component<RouteErrorBoundaryProps, Route
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
const isChunkError =
|
||||
this.state.error?.message.includes('Failed to fetch dynamically imported module') ||
|
||||
this.state.error?.message.includes('Loading chunk') ||
|
||||
this.state.error?.message.includes('ChunkLoadError');
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-4 bg-background">
|
||||
<Card className="max-w-lg w-full shadow-lg">
|
||||
@@ -63,10 +90,12 @@ export class RouteErrorBoundary extends Component<RouteErrorBoundaryProps, Route
|
||||
<AlertTriangle className="w-8 h-8 text-destructive" />
|
||||
</div>
|
||||
<CardTitle className="text-2xl">
|
||||
Something Went Wrong
|
||||
{isChunkError ? 'New Version Available' : 'Something Went Wrong'}
|
||||
</CardTitle>
|
||||
<CardDescription className="mt-2">
|
||||
We encountered an unexpected error. This has been logged and we'll look into it.
|
||||
{isChunkError
|
||||
? "The app has been updated. Please reload the page to get the latest version."
|
||||
: "We encountered an unexpected error. This has been logged and we'll look into it."}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
|
||||
Reference in New Issue
Block a user