fix: auto-reload on chunk load errors in ErrorBoundary

RouteError already handled stale chunk errors, but the Sentry ErrorBoundary
didn't — so errors from React lazy() imports hit the generic error UI.
Now auto-reloads with loop prevention (10s cooldown via sessionStorage).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael Chihlas
2026-03-11 03:17:24 -04:00
parent a976f16575
commit c920e825c6

View File

@@ -7,7 +7,29 @@ interface FallbackProps {
resetError: () => void
}
function isChunkLoadError(error: Error): boolean {
const msg = error.message || ''
return (
msg.includes('dynamically imported module') ||
msg.includes('Loading chunk') ||
msg.includes('Failed to fetch') ||
error.name === 'ChunkLoadError'
)
}
function DefaultFallback({ error, resetError }: FallbackProps) {
// Auto-reload on stale chunk errors (happens after deployments)
if (isChunkLoadError(error)) {
const key = 'rf_boundary_chunk_reload'
const lastReload = sessionStorage.getItem(key)
const now = Date.now()
if (!lastReload || now - Number(lastReload) > 10_000) {
sessionStorage.setItem(key, String(now))
window.location.reload()
return null
}
}
return (
<div className="flex min-h-[400px] flex-col items-center justify-center p-8">
<div className="max-w-md text-center">