isModuleNotFoundError does not detect Rspack/Webpack ChunkLoadError, breaking lazy route auto-reload after deploy
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #7653 by @sijie-Z — closed without merging
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript, webpack
- Domain
- frontend
Research direction
Start in packages/router-core/src/utils.ts by reading isModuleNotFoundError(), then trace its use in packages/react-router/src/lazyRouteComponent.tsx. Reproduce the stale-chunk case with the linked demo using pnpm build and pnpm preview. Done means the existing one-time reload behavior also handles the reported ChunkLoadError case without breaking the existing module-not-found checks.
Written by the indexing model from the issue text.
Description
Which project does this relate to?
Router
Describe the bug
TanStack Router already has built-in stale-deploy recovery in lazyRouteComponent: when a lazy route chunk fails to load, it calls isModuleNotFoundError() and, if true, performs a one-time sessionStorage-guarded window.location.reload().
That works for native ESM / Vite-style dynamic import failures, but not for Rspack/Webpack ChunkLoadError errors thrown after a deploy when a user still has an old bundle open.
In that case, navigating to a code-split route throws an error like:
ChunkLoadError: Loading chunk 123 failed.
(error: http://localhost:3333/js/123.abc123.chunk.js)
isModuleNotFoundError() in @tanstack/router-core only checks Vite/native ESM message prefixes today, so the reload path in lazyRouteComponent is never triggered and the navigation fails permanently until the user manually refreshes.
Relevant upstream code:
packages/router-core/src/utils.ts—isModuleNotFoundError()packages/react-router/src/lazyRouteComponent.tsx— reload-on-module-missing behavior
Complete minimal reproducer
https://github.com/CKanishka/tsr-chunk-reload-demo
The repo has two branches:
main— vanilla@tanstack/[email protected](broken behavior)fix/chunk-load-retry— proposed patch extendingisModuleNotFoundError(working behavior)
Steps to Reproduce the Bug
- On
main, runpnpm buildthenpnpm preview - Open http://localhost:3333 and stay on Home (do not refresh)
- Edit any lazy route file (e.g.
src/components/SettingsPage.tsx) and runpnpm buildagain to simulate a deploy with new chunk hashes - Without refreshing the browser tab, click Settings
Expected behavior
As a user with a stale tab open after a deploy, I expected TanStack Router's existing lazy-route reload behavior to detect the missing chunk and perform one automatic full-page reload, then load the route successfully.
This is the behavior already implemented in lazyRouteComponent for Vite-style module-not-found errors.
Actual behavior
- Console shows
ChunkLoadError: Loading chunk … failed - Route does not load
- No automatic reload occurs
- User must manually refresh the page
On the reproducer's fix/chunk-load-retry branch (same steps, after pnpm install), the page reloads once and navigation succeeds.
Screenshots or Videos
Before the fix
https://viddynest.com/v/jh9_ibAHXi
After the patch fix
https://viddynest.com/v/jh9_ibAHXi
Platform
- Router / Start Version:
@tanstack/[email protected],@tanstack/[email protected],@tanstack/[email protected] - OS: macOS (also applicable to any OS/browser combo using Rspack/Webpack)
- Browser: Chrome (ChunkLoadError format is bundler-specific; same class of failure occurs with Webpack/Rspack)
- Browser Version: latest
- Bundler: Rspack
- Bundler Version: 1.7.3
Additional context
Root cause
Current isModuleNotFoundError() only matches:
Failed to fetch dynamically imported moduleerror loading dynamically imported moduleImporting a module script failed
Rspack/Webpack instead throws ChunkLoadError with messages starting with Loading chunk.
Proposed fix
Extend isModuleNotFoundError() to also recognize:
error.name === 'ChunkLoadError'
A minimal patch demonstrating the fix is included on the fix/chunk-load-retry branch of the reproducer repo (patches/@[email protected]).
Happy to open a PR upstream if this approach looks good.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 135
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TanStack/router
-
Inline scripts are duplicated after hydration when the CSP nonce is sent in a headerPossibly taken @gabriel-le claimed this 5 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
start-plugin-core: sitemap lastmod and pages.json lastBuilt are stamped with the build's wall clock (no SOURCE_DATE_EPOCH support)Possibly taken @treadnot claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Empty .ts route file is scaffolded with JSX, breaking all route generationPossibly taken @nathan-logan claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
information needed
Difficulty 1/5 Under an hour Newbie friendliness 90/100
TanStack/router#8464 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
TanStack/router#8407 · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
szTheory/exifcleaner#383 ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
LucasSantana-Dev/Lucky#2637 ·
Maintainers usually reply within 1 day
-
good first issue type: bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
medusajs/medusa#17127 · 2 comments ·
Maintainers usually reply within 1 day
-
Desktop: SSH connect and forward budgets are fixed at 15 s with no override; slow links loop on boot failurePossibly taken @liuhao1024 claimed this today. Openbackend/ssh comp/desktop P2 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
NousResearch/hermes-agent#132508 · 3 comments ·
Maintainers usually reply within 1 day
-
Show the error reference on the error pagePossibly taken A pull request linked to this issue is open or already merged. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
tomjn/coilbox-hub#454 ·
Maintainers usually reply within 1 day