@tanstack/react-router 1.12.5 → 1.12.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,20 +18,47 @@ function _interopNamespaceDefault(e) {
18
18
  return Object.freeze(n);
19
19
  }
20
20
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
21
+ function isModuleNotFoundError(error) {
22
+ return typeof (error == null ? void 0 : error.message) === "string" && /Failed to fetch dynamically imported module/.test(error.message);
23
+ }
21
24
  function lazyRouteComponent(importer, exportName) {
22
25
  let loadPromise;
23
26
  const load = () => {
24
27
  if (!loadPromise) {
25
- loadPromise = importer();
28
+ loadPromise = importer().catch((error) => {
29
+ if (isModuleNotFoundError(error)) {
30
+ loadPromise.moduleNotFoundError = error;
31
+ return null;
32
+ }
33
+ throw error;
34
+ });
26
35
  }
27
36
  return loadPromise;
28
37
  };
29
38
  const lazyComp = React__namespace.lazy(async () => {
30
- const moduleExports = await load();
31
- const comp = moduleExports[exportName ?? "default"];
32
- return {
33
- default: comp
34
- };
39
+ try {
40
+ const promise = load();
41
+ if (promise.moduleNotFoundError) {
42
+ throw promise.moduleNotFoundError;
43
+ }
44
+ const moduleExports = await promise;
45
+ const comp = moduleExports[exportName ?? "default"];
46
+ return {
47
+ default: comp
48
+ };
49
+ } catch (error) {
50
+ if (error instanceof Error && isModuleNotFoundError(error) && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
51
+ const storageKey = `tanstack_router_reload:${error.message}`;
52
+ if (!sessionStorage.getItem(storageKey)) {
53
+ sessionStorage.setItem(storageKey, "1");
54
+ window.location.reload();
55
+ return {
56
+ default: () => null
57
+ };
58
+ }
59
+ }
60
+ throw error;
61
+ }
35
62
  });
36
63
  lazyComp.preload = load;
37
64
  return lazyComp;
@@ -1 +1 @@
1
- {"version":3,"file":"lazyRouteComponent.cjs","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AsyncRouteComponent } from './route'\n\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any>\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n }\n\n return loadPromise\n }\n\n const lazyComp = React.lazy(async () => {\n const moduleExports = await load()\n const comp = moduleExports[exportName ?? 'default']\n return {\n default: comp,\n }\n })\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGgB,SAAA,mBAId,UACA,YAGQ;AACJ,MAAA;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAS;AAAA,IACzB;AAEO,WAAA;AAAA,EAAA;AAGH,QAAA,WAAWA,iBAAM,KAAK,YAAY;AAChC,UAAA,gBAAgB,MAAM;AACtB,UAAA,OAAO,cAAc,cAAc,SAAS;AAC3C,WAAA;AAAA,MACL,SAAS;AAAA,IAAA;AAAA,EACX,CACD;AACC,WAAiB,UAAU;AAEtB,SAAA;AACT;;"}
1
+ {"version":3,"file":"lazyRouteComponent.cjs","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AsyncRouteComponent } from './route'\n\n// If the load fails due to module not found, it may mean a new version of\n// the build was deployed and the user's browser is still using an old version.\n// If this happens, the old version in the user's browser would have an outdated\n// URL to the lazy module.\n// In that case, we want to attempt one window refresh to get the latest.\nfunction isModuleNotFoundError(error: any): boolean {\n return (\n typeof error?.message === 'string' &&\n /Failed to fetch dynamically imported module/.test(error.message)\n )\n}\n\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any> & {\n moduleNotFoundError?: Error\n }\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer().catch((error) => {\n if (isModuleNotFoundError(error)) {\n // We don't want an error thrown from preload in this case, because\n // there's nothing we want to do about module not found during preload.\n // Record the error, recover the promise with a null return,\n // and we will attempt module not found resolution during the render path.\n\n loadPromise.moduleNotFoundError = error\n\n return null\n }\n throw error\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = React.lazy(async () => {\n try {\n const promise = load()\n\n // Now that we're out of preload and into actual render path,\n // throw the error if it was a module not found error during preload\n if (promise.moduleNotFoundError) {\n throw promise.moduleNotFoundError\n }\n const moduleExports = await promise\n\n const comp = moduleExports[exportName ?? 'default']\n return {\n default: comp,\n }\n } catch (error) {\n if (\n error instanceof Error &&\n isModuleNotFoundError(error) &&\n typeof window !== 'undefined' &&\n typeof sessionStorage !== 'undefined'\n ) {\n // Again, we want to reload one time on module not found error and not enter\n // a reload loop if there is some other issue besides an old deploy.\n // That's why we store our reload attempt in sessionStorage.\n // Use error.message as key because it contains the module path that failed.\n const storageKey = `tanstack_router_reload:${error.message}`\n if (!sessionStorage.getItem(storageKey)) {\n sessionStorage.setItem(storageKey, '1')\n window.location.reload()\n\n // Return empty component while we wait for window to reload\n return {\n default: () => null,\n }\n }\n }\n throw error\n }\n })\n\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQA,SAAS,sBAAsB,OAAqB;AAClD,SACE,QAAO,+BAAO,aAAY,YAC1B,8CAA8C,KAAK,MAAM,OAAO;AAEpE;AAEgB,SAAA,mBAId,UACA,YAGQ;AACJ,MAAA;AAIJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAS,EAAE,MAAM,CAAC,UAAU;AACpC,YAAA,sBAAsB,KAAK,GAAG;AAMhC,sBAAY,sBAAsB;AAE3B,iBAAA;AAAA,QACT;AACM,cAAA;AAAA,MAAA,CACP;AAAA,IACH;AAEO,WAAA;AAAA,EAAA;AAGH,QAAA,WAAWA,iBAAM,KAAK,YAAY;AAClC,QAAA;AACF,YAAM,UAAU;AAIhB,UAAI,QAAQ,qBAAqB;AAC/B,cAAM,QAAQ;AAAA,MAChB;AACA,YAAM,gBAAgB,MAAM;AAEtB,YAAA,OAAO,cAAc,cAAc,SAAS;AAC3C,aAAA;AAAA,QACL,SAAS;AAAA,MAAA;AAAA,aAEJ,OAAO;AAEZ,UAAA,iBAAiB,SACjB,sBAAsB,KAAK,KAC3B,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKM,cAAA,aAAa,0BAA0B,MAAM,OAAO;AAC1D,YAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACxB,yBAAA,QAAQ,YAAY,GAAG;AACtC,iBAAO,SAAS;AAGT,iBAAA;AAAA,YACL,SAAS,MAAM;AAAA,UAAA;AAAA,QAEnB;AAAA,MACF;AACM,YAAA;AAAA,IACR;AAAA,EAAA,CACD;AAEC,WAAiB,UAAU;AAEtB,SAAA;AACT;;"}
@@ -1,18 +1,45 @@
1
1
  import * as React from "react";
2
+ function isModuleNotFoundError(error) {
3
+ return typeof (error == null ? void 0 : error.message) === "string" && /Failed to fetch dynamically imported module/.test(error.message);
4
+ }
2
5
  function lazyRouteComponent(importer, exportName) {
3
6
  let loadPromise;
4
7
  const load = () => {
5
8
  if (!loadPromise) {
6
- loadPromise = importer();
9
+ loadPromise = importer().catch((error) => {
10
+ if (isModuleNotFoundError(error)) {
11
+ loadPromise.moduleNotFoundError = error;
12
+ return null;
13
+ }
14
+ throw error;
15
+ });
7
16
  }
8
17
  return loadPromise;
9
18
  };
10
19
  const lazyComp = React.lazy(async () => {
11
- const moduleExports = await load();
12
- const comp = moduleExports[exportName ?? "default"];
13
- return {
14
- default: comp
15
- };
20
+ try {
21
+ const promise = load();
22
+ if (promise.moduleNotFoundError) {
23
+ throw promise.moduleNotFoundError;
24
+ }
25
+ const moduleExports = await promise;
26
+ const comp = moduleExports[exportName ?? "default"];
27
+ return {
28
+ default: comp
29
+ };
30
+ } catch (error) {
31
+ if (error instanceof Error && isModuleNotFoundError(error) && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
32
+ const storageKey = `tanstack_router_reload:${error.message}`;
33
+ if (!sessionStorage.getItem(storageKey)) {
34
+ sessionStorage.setItem(storageKey, "1");
35
+ window.location.reload();
36
+ return {
37
+ default: () => null
38
+ };
39
+ }
40
+ }
41
+ throw error;
42
+ }
16
43
  });
17
44
  lazyComp.preload = load;
18
45
  return lazyComp;
@@ -1 +1 @@
1
- {"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AsyncRouteComponent } from './route'\n\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any>\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n }\n\n return loadPromise\n }\n\n const lazyComp = React.lazy(async () => {\n const moduleExports = await load()\n const comp = moduleExports[exportName ?? 'default']\n return {\n default: comp,\n }\n })\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":[],"mappings":";AAGgB,SAAA,mBAId,UACA,YAGQ;AACJ,MAAA;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAS;AAAA,IACzB;AAEO,WAAA;AAAA,EAAA;AAGH,QAAA,WAAW,MAAM,KAAK,YAAY;AAChC,UAAA,gBAAgB,MAAM;AACtB,UAAA,OAAO,cAAc,cAAc,SAAS;AAC3C,WAAA;AAAA,MACL,SAAS;AAAA,IAAA;AAAA,EACX,CACD;AACC,WAAiB,UAAU;AAEtB,SAAA;AACT;"}
1
+ {"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AsyncRouteComponent } from './route'\n\n// If the load fails due to module not found, it may mean a new version of\n// the build was deployed and the user's browser is still using an old version.\n// If this happens, the old version in the user's browser would have an outdated\n// URL to the lazy module.\n// In that case, we want to attempt one window refresh to get the latest.\nfunction isModuleNotFoundError(error: any): boolean {\n return (\n typeof error?.message === 'string' &&\n /Failed to fetch dynamically imported module/.test(error.message)\n )\n}\n\nexport function lazyRouteComponent<\n T extends Record<string, any>,\n TKey extends keyof T = 'default',\n>(\n importer: () => Promise<T>,\n exportName?: TKey,\n): T[TKey] extends (props: infer TProps) => any\n ? AsyncRouteComponent<TProps>\n : never {\n let loadPromise: Promise<any> & {\n moduleNotFoundError?: Error\n }\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer().catch((error) => {\n if (isModuleNotFoundError(error)) {\n // We don't want an error thrown from preload in this case, because\n // there's nothing we want to do about module not found during preload.\n // Record the error, recover the promise with a null return,\n // and we will attempt module not found resolution during the render path.\n\n loadPromise.moduleNotFoundError = error\n\n return null\n }\n throw error\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = React.lazy(async () => {\n try {\n const promise = load()\n\n // Now that we're out of preload and into actual render path,\n // throw the error if it was a module not found error during preload\n if (promise.moduleNotFoundError) {\n throw promise.moduleNotFoundError\n }\n const moduleExports = await promise\n\n const comp = moduleExports[exportName ?? 'default']\n return {\n default: comp,\n }\n } catch (error) {\n if (\n error instanceof Error &&\n isModuleNotFoundError(error) &&\n typeof window !== 'undefined' &&\n typeof sessionStorage !== 'undefined'\n ) {\n // Again, we want to reload one time on module not found error and not enter\n // a reload loop if there is some other issue besides an old deploy.\n // That's why we store our reload attempt in sessionStorage.\n // Use error.message as key because it contains the module path that failed.\n const storageKey = `tanstack_router_reload:${error.message}`\n if (!sessionStorage.getItem(storageKey)) {\n sessionStorage.setItem(storageKey, '1')\n window.location.reload()\n\n // Return empty component while we wait for window to reload\n return {\n default: () => null,\n }\n }\n }\n throw error\n }\n })\n\n ;(lazyComp as any).preload = load\n\n return lazyComp as any\n}\n"],"names":[],"mappings":";AAQA,SAAS,sBAAsB,OAAqB;AAClD,SACE,QAAO,+BAAO,aAAY,YAC1B,8CAA8C,KAAK,MAAM,OAAO;AAEpE;AAEgB,SAAA,mBAId,UACA,YAGQ;AACJ,MAAA;AAIJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAS,EAAE,MAAM,CAAC,UAAU;AACpC,YAAA,sBAAsB,KAAK,GAAG;AAMhC,sBAAY,sBAAsB;AAE3B,iBAAA;AAAA,QACT;AACM,cAAA;AAAA,MAAA,CACP;AAAA,IACH;AAEO,WAAA;AAAA,EAAA;AAGH,QAAA,WAAW,MAAM,KAAK,YAAY;AAClC,QAAA;AACF,YAAM,UAAU;AAIhB,UAAI,QAAQ,qBAAqB;AAC/B,cAAM,QAAQ;AAAA,MAChB;AACA,YAAM,gBAAgB,MAAM;AAEtB,YAAA,OAAO,cAAc,cAAc,SAAS;AAC3C,aAAA;AAAA,QACL,SAAS;AAAA,MAAA;AAAA,aAEJ,OAAO;AAEZ,UAAA,iBAAiB,SACjB,sBAAsB,KAAK,KAC3B,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKM,cAAA,aAAa,0BAA0B,MAAM,OAAO;AAC1D,YAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACxB,yBAAA,QAAQ,YAAY,GAAG;AACtC,iBAAO,SAAS;AAGT,iBAAA;AAAA,YACL,SAAS,MAAM;AAAA,UAAA;AAAA,QAEnB;AAAA,MACF;AACM,YAAA;AAAA,IACR;AAAA,EAAA,CACD;AAEC,WAAiB,UAAU;AAEtB,SAAA;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.12.5",
3
+ "version": "1.12.7",
4
4
  "description": "",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -1,6 +1,18 @@
1
1
  import * as React from 'react'
2
2
  import { AsyncRouteComponent } from './route'
3
3
 
4
+ // If the load fails due to module not found, it may mean a new version of
5
+ // the build was deployed and the user's browser is still using an old version.
6
+ // If this happens, the old version in the user's browser would have an outdated
7
+ // URL to the lazy module.
8
+ // In that case, we want to attempt one window refresh to get the latest.
9
+ function isModuleNotFoundError(error: any): boolean {
10
+ return (
11
+ typeof error?.message === 'string' &&
12
+ /Failed to fetch dynamically imported module/.test(error.message)
13
+ )
14
+ }
15
+
4
16
  export function lazyRouteComponent<
5
17
  T extends Record<string, any>,
6
18
  TKey extends keyof T = 'default',
@@ -10,23 +22,71 @@ export function lazyRouteComponent<
10
22
  ): T[TKey] extends (props: infer TProps) => any
11
23
  ? AsyncRouteComponent<TProps>
12
24
  : never {
13
- let loadPromise: Promise<any>
25
+ let loadPromise: Promise<any> & {
26
+ moduleNotFoundError?: Error
27
+ }
14
28
 
15
29
  const load = () => {
16
30
  if (!loadPromise) {
17
- loadPromise = importer()
31
+ loadPromise = importer().catch((error) => {
32
+ if (isModuleNotFoundError(error)) {
33
+ // We don't want an error thrown from preload in this case, because
34
+ // there's nothing we want to do about module not found during preload.
35
+ // Record the error, recover the promise with a null return,
36
+ // and we will attempt module not found resolution during the render path.
37
+
38
+ loadPromise.moduleNotFoundError = error
39
+
40
+ return null
41
+ }
42
+ throw error
43
+ })
18
44
  }
19
45
 
20
46
  return loadPromise
21
47
  }
22
48
 
23
49
  const lazyComp = React.lazy(async () => {
24
- const moduleExports = await load()
25
- const comp = moduleExports[exportName ?? 'default']
26
- return {
27
- default: comp,
50
+ try {
51
+ const promise = load()
52
+
53
+ // Now that we're out of preload and into actual render path,
54
+ // throw the error if it was a module not found error during preload
55
+ if (promise.moduleNotFoundError) {
56
+ throw promise.moduleNotFoundError
57
+ }
58
+ const moduleExports = await promise
59
+
60
+ const comp = moduleExports[exportName ?? 'default']
61
+ return {
62
+ default: comp,
63
+ }
64
+ } catch (error) {
65
+ if (
66
+ error instanceof Error &&
67
+ isModuleNotFoundError(error) &&
68
+ typeof window !== 'undefined' &&
69
+ typeof sessionStorage !== 'undefined'
70
+ ) {
71
+ // Again, we want to reload one time on module not found error and not enter
72
+ // a reload loop if there is some other issue besides an old deploy.
73
+ // That's why we store our reload attempt in sessionStorage.
74
+ // Use error.message as key because it contains the module path that failed.
75
+ const storageKey = `tanstack_router_reload:${error.message}`
76
+ if (!sessionStorage.getItem(storageKey)) {
77
+ sessionStorage.setItem(storageKey, '1')
78
+ window.location.reload()
79
+
80
+ // Return empty component while we wait for window to reload
81
+ return {
82
+ default: () => null,
83
+ }
84
+ }
85
+ }
86
+ throw error
28
87
  }
29
88
  })
89
+
30
90
  ;(lazyComp as any).preload = load
31
91
 
32
92
  return lazyComp as any