Description
The ErrorBoundary component introduced in #542 handles stale lazy-loaded chunks gracefully. Two follow-up improvements would make it more robust and maintainable:
1. Simplify the Reload button interaction
Currently, when the user clicks the "Reload" button in RouteErrorFallback, the reset() method clears the sessionStorage guard and resets the React error state. This causes the lazy import to re-attempt → fail → trigger componentDidCatch → auto-reload the page (since the guard was cleared). The user ends up waiting through an indirect reload cycle.
A simpler approach: have the Reload button call window.location.reload() directly (after clearing the session guard), making the behavior transparent and predictable.
// Current (indirect)
private reset = (): void => {
try { window.sessionStorage.removeItem(CHUNK_RELOAD_STORAGE_KEY); } catch {}
this.setState({ error: null });
};
// Proposed (direct)
private reset = (): void => {
try { window.sessionStorage.removeItem(CHUNK_RELOAD_STORAGE_KEY); } catch {}
window.location.reload();
};
2. Add unit tests for ErrorBoundary
The component has no test coverage. Key scenarios to cover:
- A chunk load error triggers
window.location.reload()
- The
sessionStorage guard prevents a second automatic reload
- Non-chunk errors display the fallback without reloading
reset() clears the guard and retries correctly
Scope
- File(s):
pages/src/components/ErrorBoundary.tsx, pages/src/App.tsx
- New test file:
pages/src/components/ErrorBoundary.test.tsx
Acceptance Criteria
Context
Discovered during review of #542. The current implementation is functional and safe — this is a polish pass to improve UX clarity and ensure long-term maintainability of a critical error-handling component.
Description
The
ErrorBoundarycomponent introduced in #542 handles stale lazy-loaded chunks gracefully. Two follow-up improvements would make it more robust and maintainable:1. Simplify the Reload button interaction
Currently, when the user clicks the "Reload" button in
RouteErrorFallback, thereset()method clears thesessionStorageguard and resets the React error state. This causes the lazy import to re-attempt → fail → triggercomponentDidCatch→ auto-reload the page (since the guard was cleared). The user ends up waiting through an indirect reload cycle.A simpler approach: have the Reload button call
window.location.reload()directly (after clearing the session guard), making the behavior transparent and predictable.2. Add unit tests for ErrorBoundary
The component has no test coverage. Key scenarios to cover:
window.location.reload()sessionStorageguard prevents a second automatic reloadreset()clears the guard and retries correctlyScope
pages/src/components/ErrorBoundary.tsx,pages/src/App.tsxpages/src/components/ErrorBoundary.test.tsxAcceptance Criteria
npm run typecheckpasses frompages/npm run buildpasses frompages/Context
Discovered during review of #542. The current implementation is functional and safe — this is a polish pass to improve UX clarity and ensure long-term maintainability of a critical error-handling component.