Skip to content
Source
Sign inSign up
TanStack/router

fix(react-router): improve error handling for module loading failures in lazyRouteComponent #3262

MergedSheraff(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/3262/headmerged by schiller-manuel(GitHub profile, opens in a new tab)

Showing 1 changed file with 34 additions and 31 deletions.

x
0 of 1 viewed, 1 left
34 additions and 31 deletionspackages/react-router/src/lazyRouteComponent.tsxModified
View file
@@ -8,9 +8,14 @@
// URL to the lazy module.
// In that case, we want to attempt one window refresh to get the latest.
function isModuleNotFoundError(error: any): boolean {
+ // chrome: "Failed to fetch dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split"
+ // firefox: "error loading dynamically imported module: http://localhost:5173/src/routes/posts.index.tsx?tsr-split"
+ // safari: "Importing a module script failed."
+ if (typeof error?.message !== 'string') return false
return (
- typeof error?.message === 'string' &&
- /Failed to fetch dynamically imported module/.test(error.message)
+ error.message.startsWith('Failed to fetch dynamically imported module') ||
+ error.message.startsWith('error loading dynamically imported module') ||
+ error.message.startsWith('Importing a module script failed')
​
@@ -46,6 +51,7 @@
let loadPromise: Promise<any> | undefined
let comp: T[TKey] | T['default']
let error: any
+ let reload: boolean
​
const load = () => {
if (typeof document === 'undefined' && ssr?.() === false) {