@tanstack/react-router 1.32.3 → 1.32.4
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.
|
@@ -28,6 +28,7 @@ function lazyRouteComponent(importer, exportName) {
|
|
|
28
28
|
const load = () => {
|
|
29
29
|
if (!loadPromise) {
|
|
30
30
|
loadPromise = importer().then((res) => {
|
|
31
|
+
loadPromise = void 0;
|
|
31
32
|
comp = res[exportName ?? "default"];
|
|
32
33
|
}).catch((err) => {
|
|
33
34
|
error = err;
|
|
@@ -36,24 +37,23 @@ function lazyRouteComponent(importer, exportName) {
|
|
|
36
37
|
return loadPromise;
|
|
37
38
|
};
|
|
38
39
|
const lazyComp = function Lazy(props) {
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
40
|
+
if (error) {
|
|
41
|
+
if (isModuleNotFoundError(error)) {
|
|
42
|
+
if (error instanceof Error && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
|
|
43
|
+
const storageKey = `tanstack_router_reload:${error.message}`;
|
|
44
|
+
if (!sessionStorage.getItem(storageKey)) {
|
|
45
|
+
sessionStorage.setItem(storageKey, "1");
|
|
46
|
+
window.location.reload();
|
|
47
|
+
return {
|
|
48
|
+
default: () => null
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
throw error;
|
|
54
54
|
}
|
|
55
55
|
if (!comp) {
|
|
56
|
-
throw
|
|
56
|
+
throw load();
|
|
57
57
|
}
|
|
58
58
|
return React__namespace.createElement(comp, props);
|
|
59
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyRouteComponent.cjs","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { 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> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n error = err\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\n
|
|
1
|
+
{"version":3,"file":"lazyRouteComponent.cjs","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { 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> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n loadPromise = undefined\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n error = err\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\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 (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 if (\n error instanceof 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 }\n\n // Otherwise, just throw the error\n throw error\n }\n\n if (!comp) {\n throw load()\n }\n\n return React.createElement(comp, props)\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;AACA,MAAA;AACA,MAAA;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAS,EACpB,KAAK,CAAC,QAAQ;AACC,sBAAA;AACP,eAAA,IAAI,cAAc,SAAS;AAAA,MAAA,CACnC,EACA,MAAM,CAAC,QAAQ;AACN,gBAAA;AAAA,MAAA,CACT;AAAA,IACL;AAEO,WAAA;AAAA,EAAA;AAGH,QAAA,WAAW,SAAS,KAAK,OAAY;AAGzC,QAAI,OAAO;AACL,UAAA,sBAAsB,KAAK,GAAG;AAMhC,YACE,iBAAiB,SACjB,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKM,gBAAA,aAAa,0BAA0B,MAAM,OAAO;AAC1D,cAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACxB,2BAAA,QAAQ,YAAY,GAAG;AACtC,mBAAO,SAAS;AAGT,mBAAA;AAAA,cACL,SAAS,MAAM;AAAA,YAAA;AAAA,UAEnB;AAAA,QACF;AAAA,MACF;AAGM,YAAA;AAAA,IACR;AAEA,QAAI,CAAC,MAAM;AACT,YAAM,KAAK;AAAA,IACb;AAEO,WAAAA,iBAAM,cAAc,MAAM,KAAK;AAAA,EAAA;AAGtC,WAAiB,UAAU;AAEtB,SAAA;AACT;;"}
|
|
@@ -9,6 +9,7 @@ function lazyRouteComponent(importer, exportName) {
|
|
|
9
9
|
const load = () => {
|
|
10
10
|
if (!loadPromise) {
|
|
11
11
|
loadPromise = importer().then((res) => {
|
|
12
|
+
loadPromise = void 0;
|
|
12
13
|
comp = res[exportName ?? "default"];
|
|
13
14
|
}).catch((err) => {
|
|
14
15
|
error = err;
|
|
@@ -17,24 +18,23 @@ function lazyRouteComponent(importer, exportName) {
|
|
|
17
18
|
return loadPromise;
|
|
18
19
|
};
|
|
19
20
|
const lazyComp = function Lazy(props) {
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
21
|
+
if (error) {
|
|
22
|
+
if (isModuleNotFoundError(error)) {
|
|
23
|
+
if (error instanceof Error && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
|
|
24
|
+
const storageKey = `tanstack_router_reload:${error.message}`;
|
|
25
|
+
if (!sessionStorage.getItem(storageKey)) {
|
|
26
|
+
sessionStorage.setItem(storageKey, "1");
|
|
27
|
+
window.location.reload();
|
|
28
|
+
return {
|
|
29
|
+
default: () => null
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
throw error;
|
|
35
35
|
}
|
|
36
36
|
if (!comp) {
|
|
37
|
-
throw
|
|
37
|
+
throw load();
|
|
38
38
|
}
|
|
39
39
|
return React.createElement(comp, props);
|
|
40
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { 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> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n error = err\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\n
|
|
1
|
+
{"version":3,"file":"lazyRouteComponent.js","sources":["../../src/lazyRouteComponent.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { 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> | undefined\n let comp: T[TKey] | T['default']\n let error: any\n\n const load = () => {\n if (!loadPromise) {\n loadPromise = importer()\n .then((res) => {\n loadPromise = undefined\n comp = res[exportName ?? 'default']\n })\n .catch((err) => {\n error = err\n })\n }\n\n return loadPromise\n }\n\n const lazyComp = function Lazy(props: any) {\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 (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 if (\n error instanceof 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 }\n\n // Otherwise, just throw the error\n throw error\n }\n\n if (!comp) {\n throw load()\n }\n\n return React.createElement(comp, props)\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;AACA,MAAA;AACA,MAAA;AAEJ,QAAM,OAAO,MAAM;AACjB,QAAI,CAAC,aAAa;AAChB,oBAAc,SAAS,EACpB,KAAK,CAAC,QAAQ;AACC,sBAAA;AACP,eAAA,IAAI,cAAc,SAAS;AAAA,MAAA,CACnC,EACA,MAAM,CAAC,QAAQ;AACN,gBAAA;AAAA,MAAA,CACT;AAAA,IACL;AAEO,WAAA;AAAA,EAAA;AAGH,QAAA,WAAW,SAAS,KAAK,OAAY;AAGzC,QAAI,OAAO;AACL,UAAA,sBAAsB,KAAK,GAAG;AAMhC,YACE,iBAAiB,SACjB,OAAO,WAAW,eAClB,OAAO,mBAAmB,aAC1B;AAKM,gBAAA,aAAa,0BAA0B,MAAM,OAAO;AAC1D,cAAI,CAAC,eAAe,QAAQ,UAAU,GAAG;AACxB,2BAAA,QAAQ,YAAY,GAAG;AACtC,mBAAO,SAAS;AAGT,mBAAA;AAAA,cACL,SAAS,MAAM;AAAA,YAAA;AAAA,UAEnB;AAAA,QACF;AAAA,MACF;AAGM,YAAA;AAAA,IACR;AAEA,QAAI,CAAC,MAAM;AACT,YAAM,KAAK;AAAA,IACb;AAEO,WAAA,MAAM,cAAc,MAAM,KAAK;AAAA,EAAA;AAGtC,WAAiB,UAAU;AAEtB,SAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -30,6 +30,7 @@ export function lazyRouteComponent<
|
|
|
30
30
|
if (!loadPromise) {
|
|
31
31
|
loadPromise = importer()
|
|
32
32
|
.then((res) => {
|
|
33
|
+
loadPromise = undefined
|
|
33
34
|
comp = res[exportName ?? 'default']
|
|
34
35
|
})
|
|
35
36
|
.catch((err) => {
|
|
@@ -41,35 +42,33 @@ export function lazyRouteComponent<
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const lazyComp = function Lazy(props: any) {
|
|
44
|
-
if (!loadPromise) {
|
|
45
|
-
load()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
45
|
// Now that we're out of preload and into actual render path,
|
|
49
46
|
// throw the error if it was a module not found error during preload
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
if (error) {
|
|
48
|
+
if (isModuleNotFoundError(error)) {
|
|
49
|
+
// We don't want an error thrown from preload in this case, because
|
|
50
|
+
// there's nothing we want to do about module not found during preload.
|
|
51
|
+
// Record the error, recover the promise with a null return,
|
|
52
|
+
// and we will attempt module not found resolution during the render path.
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
if (
|
|
55
|
+
error instanceof Error &&
|
|
56
|
+
typeof window !== 'undefined' &&
|
|
57
|
+
typeof sessionStorage !== 'undefined'
|
|
58
|
+
) {
|
|
59
|
+
// Again, we want to reload one time on module not found error and not enter
|
|
60
|
+
// a reload loop if there is some other issue besides an old deploy.
|
|
61
|
+
// That's why we store our reload attempt in sessionStorage.
|
|
62
|
+
// Use error.message as key because it contains the module path that failed.
|
|
63
|
+
const storageKey = `tanstack_router_reload:${error.message}`
|
|
64
|
+
if (!sessionStorage.getItem(storageKey)) {
|
|
65
|
+
sessionStorage.setItem(storageKey, '1')
|
|
66
|
+
window.location.reload()
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
// Return empty component while we wait for window to reload
|
|
69
|
+
return {
|
|
70
|
+
default: () => null,
|
|
71
|
+
}
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
}
|
|
@@ -79,7 +78,7 @@ export function lazyRouteComponent<
|
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
if (!comp) {
|
|
82
|
-
throw
|
|
81
|
+
throw load()
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
return React.createElement(comp, props)
|