Skip to content

Handle stale chunk errors by reloading page after deployments#8421

Merged
iHiD merged 3 commits into
mainfrom
fix/8369
Feb 9, 2026
Merged

Handle stale chunk errors by reloading page after deployments#8421
iHiD merged 3 commits into
mainfrom
fix/8369

Conversation

@iHiD

@iHiD iHiD commented Feb 8, 2026

Copy link
Copy Markdown
Member

Closes #8369

Summary

  • Dynamic imports (React.lazy) occasionally fail with transient errors (network blips, CDN hiccups). Old chunk files persist on the CDN, so these are transient failures rather than missing files.
  • Adds a lazy-with-retry utility as a drop-in replacement for React.lazy that retries failed imports up to 3 times with 1-second delays between attempts.
  • Updates all 6 files that use lazy() to import from the retry utility (129 lazy call sites, only import lines change).
  • Adds chunk-load-error-handler utility for detecting dynamic import errors across all browsers (Chrome, Firefox, Safari use different error messages) with a safeReloadForChunkError() last-resort fallback using sessionStorage-based cooldown to prevent infinite loops.
  • Wires the handler into the Sentry ErrorBoundary fallback and a global unhandledrejection listener as safety nets.
  • Fixes the Sentry beforeSend filter to match Firefox ("error loading dynamically imported module") and Safari ("Importing a module script failed.") in addition to Chrome.
  • Guards the ErrorFallback auto-reset in ErrorBoundary.tsx against chunk load errors to prevent infinite retry loops.

Test plan

  • yarn test — all 160 test suites pass (1550 tests)
  • Manual: simulate transient failure, verify retry succeeds without page reload

🤖 Generated with Claude Code

@iHiD iHiD requested a review from dem4ron as a code owner February 8, 2026 20:41
iHiD and others added 3 commits February 9, 2026 14:06
When assets are redeployed with new content hashes, users with cached
pages get TypeError when dynamically imported chunks (React.lazy) no
longer exist on the CDN. This adds graceful recovery by detecting these
errors and triggering a page reload with loop prevention.

- Create chunk-load-error-handler utility with browser-variant detection
  (Chrome, Firefox, Safari all use different error messages)
- Add ErrorBoundary fallback in react-bootloader to catch chunk errors
  in the React tree and reload instead of showing blank components
- Add global unhandledrejection handler as safety net for failures
  outside the React error boundary tree
- Fix Sentry beforeSend filter to match all browser error variants
  (was only matching Chrome's "Failed to fetch dynamically imported module")
- Guard ErrorFallback auto-reset against chunk errors to prevent
  infinite retry loops

Closes #8369

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Old chunk files persist on the CDN, so import failures are transient
(network blips, CDN hiccups) rather than missing files. Instead of
immediately reloading the page, retry the import up to 3 times with
a 1-second delay between attempts.

- Create lazy-with-retry utility as drop-in replacement for React.lazy
- Update all 6 files that use lazy() to import from the retry utility
  (129 lazy call sites, only import lines change)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
After all retries are exhausted, if the error is a chunk load error,
reload the page directly instead of throwing. This ensures the error
never reaches Sentry.captureException via ErrorBoundary handlers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iHiD iHiD merged commit 7b441ad into main Feb 9, 2026
40 checks passed
@iHiD iHiD deleted the fix/8369 branch February 9, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: error loading dynamically imported module: https://assets.exercism.org/assets/WelcomeModal-KXJFQSOM.js

1 participant