mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:31:11 -05:00
Refactor: Implement chunk load error recovery
This commit is contained in:
@@ -120,6 +120,9 @@ function NavigationTracker() {
|
|||||||
const from = prevLocation.current || undefined;
|
const from = prevLocation.current || undefined;
|
||||||
breadcrumb.navigation(location.pathname, from);
|
breadcrumb.navigation(location.pathname, from);
|
||||||
prevLocation.current = location.pathname;
|
prevLocation.current = location.pathname;
|
||||||
|
|
||||||
|
// Clear chunk load reload flag on successful navigation
|
||||||
|
sessionStorage.removeItem('chunk-load-reload');
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -32,13 +32,35 @@ export class RouteErrorBoundary extends Component<RouteErrorBoundaryProps, Route
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
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
|
// Log to database and get error ID for user reference
|
||||||
const errorId = handleError(error, {
|
const errorId = handleError(error, {
|
||||||
action: 'Route-level component crash',
|
action: 'Route-level component crash',
|
||||||
metadata: {
|
metadata: {
|
||||||
componentStack: errorInfo.componentStack,
|
componentStack: errorInfo.componentStack,
|
||||||
url: window.location.href,
|
url: window.location.href,
|
||||||
severity: 'critical',
|
severity: isChunkLoadError ? 'medium' : 'critical',
|
||||||
|
isChunkLoadError,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,6 +77,11 @@ export class RouteErrorBoundary extends Component<RouteErrorBoundaryProps, Route
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.state.hasError) {
|
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 (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center p-4 bg-background">
|
<div className="min-h-screen flex items-center justify-center p-4 bg-background">
|
||||||
<Card className="max-w-lg w-full shadow-lg">
|
<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" />
|
<AlertTriangle className="w-8 h-8 text-destructive" />
|
||||||
</div>
|
</div>
|
||||||
<CardTitle className="text-2xl">
|
<CardTitle className="text-2xl">
|
||||||
Something Went Wrong
|
{isChunkError ? 'New Version Available' : 'Something Went Wrong'}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-2">
|
<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>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-4">
|
<CardContent className="space-y-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user