@depup/tanstack__react-router 1.167.0-depup.0 → 1.167.3-depup.0
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.
- package/README.md +2 -2
- package/dist/cjs/Asset.cjs +115 -174
- package/dist/cjs/Asset.cjs.map +1 -1
- package/dist/cjs/CatchBoundary.cjs +92 -108
- package/dist/cjs/CatchBoundary.cjs.map +1 -1
- package/dist/cjs/ClientOnly.cjs +47 -13
- package/dist/cjs/ClientOnly.cjs.map +1 -1
- package/dist/cjs/HeadContent.cjs +23 -12
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/HeadContent.dev.cjs +33 -38
- package/dist/cjs/HeadContent.dev.cjs.map +1 -1
- package/dist/cjs/Match.cjs +190 -247
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +131 -118
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/RouterProvider.cjs +43 -27
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/SafeFragment.cjs +9 -5
- package/dist/cjs/SafeFragment.cjs.map +1 -1
- package/dist/cjs/ScriptOnce.cjs +17 -19
- package/dist/cjs/ScriptOnce.cjs.map +1 -1
- package/dist/cjs/Scripts.cjs +56 -54
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/ScrollRestoration.cjs +26 -30
- package/dist/cjs/ScrollRestoration.cjs.map +1 -1
- package/dist/cjs/Transitioner.cjs +109 -116
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/awaited.cjs +28 -43
- package/dist/cjs/awaited.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs +133 -95
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/headContentUtils.cjs +144 -181
- package/dist/cjs/headContentUtils.cjs.map +1 -1
- package/dist/cjs/index.cjs +249 -178
- package/dist/cjs/index.dev.cjs +249 -178
- package/dist/cjs/lazyRouteComponent.cjs +52 -67
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
- package/dist/cjs/link.cjs +462 -556
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/matchContext.cjs +9 -25
- package/dist/cjs/matchContext.cjs.map +1 -1
- package/dist/cjs/not-found.cjs +25 -32
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/renderRouteNotFound.cjs +25 -19
- package/dist/cjs/renderRouteNotFound.cjs.map +1 -1
- package/dist/cjs/route.cjs +258 -178
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/router.cjs +29 -16
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/routerContext.cjs +8 -22
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.cjs +23 -36
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/ssr/RouterClient.cjs +16 -22
- package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
- package/dist/cjs/ssr/RouterServer.cjs +10 -6
- package/dist/cjs/ssr/RouterServer.cjs.map +1 -1
- package/dist/cjs/ssr/client.cjs +10 -10
- package/dist/cjs/ssr/defaultRenderHandler.cjs +13 -14
- package/dist/cjs/ssr/defaultRenderHandler.cjs.map +1 -1
- package/dist/cjs/ssr/defaultStreamHandler.cjs +14 -15
- package/dist/cjs/ssr/defaultStreamHandler.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToStream.cjs +51 -71
- package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs +26 -29
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
- package/dist/cjs/ssr/server.cjs +18 -18
- package/dist/cjs/useBlocker.cjs +126 -162
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useCanGoBack.cjs +6 -5
- package/dist/cjs/useCanGoBack.cjs.map +1 -1
- package/dist/cjs/useLoaderData.cjs +24 -12
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.cjs +23 -11
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLocation.cjs +17 -7
- package/dist/cjs/useLocation.cjs.map +1 -1
- package/dist/cjs/useMatch.cjs +25 -44
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +53 -43
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useParams.cjs +27 -14
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useRouteContext.cjs +9 -8
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouter.cjs +23 -29
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouterState.cjs +40 -35
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/useSearch.cjs +26 -13
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/utils.cjs +81 -51
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/Asset.js +112 -156
- package/dist/esm/Asset.js.map +1 -1
- package/dist/esm/CatchBoundary.js +90 -92
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/ClientOnly.js +45 -14
- package/dist/esm/ClientOnly.js.map +1 -1
- package/dist/esm/HeadContent.dev.js +31 -21
- package/dist/esm/HeadContent.dev.js.map +1 -1
- package/dist/esm/HeadContent.js +20 -11
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/Match.js +181 -226
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +125 -103
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.js +41 -28
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/SafeFragment.js +8 -6
- package/dist/esm/SafeFragment.js.map +1 -1
- package/dist/esm/ScriptOnce.js +15 -18
- package/dist/esm/ScriptOnce.js.map +1 -1
- package/dist/esm/Scripts.js +55 -54
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/ScrollRestoration.js +25 -31
- package/dist/esm/ScrollRestoration.js.map +1 -1
- package/dist/esm/Transitioner.js +106 -98
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/awaited.js +26 -27
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/fileRoute.js +127 -96
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/headContentUtils.js +141 -163
- package/dist/esm/headContentUtils.js.map +1 -1
- package/dist/esm/index.dev.js +16 -117
- package/dist/esm/index.js +18 -118
- package/dist/esm/lazyRouteComponent.js +50 -50
- package/dist/esm/lazyRouteComponent.js.map +1 -1
- package/dist/esm/link.js +459 -541
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/matchContext.js +8 -10
- package/dist/esm/matchContext.js.map +1 -1
- package/dist/esm/not-found.js +22 -32
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/renderRouteNotFound.js +21 -18
- package/dist/esm/renderRouteNotFound.js.map +1 -1
- package/dist/esm/route.js +249 -180
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.js +28 -17
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.js +7 -6
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/scroll-restoration.js +21 -35
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/ssr/RouterClient.js +14 -21
- package/dist/esm/ssr/RouterClient.js.map +1 -1
- package/dist/esm/ssr/RouterServer.js +8 -6
- package/dist/esm/ssr/RouterServer.js.map +1 -1
- package/dist/esm/ssr/client.js +1 -4
- package/dist/esm/ssr/defaultRenderHandler.js +12 -13
- package/dist/esm/ssr/defaultRenderHandler.js.map +1 -1
- package/dist/esm/ssr/defaultStreamHandler.js +13 -14
- package/dist/esm/ssr/defaultStreamHandler.js.map +1 -1
- package/dist/esm/ssr/renderRouterToStream.js +48 -70
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.js +24 -29
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/dist/esm/ssr/server.js +3 -10
- package/dist/esm/useBlocker.js +124 -146
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useCanGoBack.js +6 -5
- package/dist/esm/useCanGoBack.js.map +1 -1
- package/dist/esm/useLoaderData.js +24 -12
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.js +23 -11
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useLocation.js +17 -7
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.js +21 -26
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.js +50 -26
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.js +27 -14
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.js +9 -8
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useRouter.js +20 -12
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.js +38 -34
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.js +26 -13
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.js +80 -39
- package/dist/esm/utils.js.map +1 -1
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +2 -2
- package/package.json +5 -5
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.dev.cjs.map +0 -1
- package/dist/cjs/ssr/client.cjs.map +0 -1
- package/dist/cjs/ssr/server.cjs.map +0 -1
- package/dist/esm/index.dev.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/ssr/client.js.map +0 -1
- package/dist/esm/ssr/server.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/tanstack__react-router
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@tanstack/react-router](https://www.npmjs.com/package/@tanstack/react-router) @ 1.167.
|
|
17
|
-
| Processed | 2026-03-
|
|
16
|
+
| Original | [@tanstack/react-router](https://www.npmjs.com/package/@tanstack/react-router) @ 1.167.3 |
|
|
17
|
+
| Processed | 2026-03-16 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
19
|
| Deps updated | 2 |
|
|
20
20
|
|
package/dist/cjs/Asset.cjs
CHANGED
|
@@ -1,177 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_ClientOnly = require("./ClientOnly.cjs");
|
|
3
|
+
const require_useRouter = require("./useRouter.cjs");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
react = require_runtime.__toESM(react);
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let _tanstack_router_core_isServer = require("@tanstack/router-core/isServer");
|
|
8
|
+
//#region src/Asset.tsx
|
|
9
|
+
function Asset({ tag, attrs, children, nonce }) {
|
|
10
|
+
switch (tag) {
|
|
11
|
+
case "title": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("title", {
|
|
12
|
+
...attrs,
|
|
13
|
+
suppressHydrationWarning: true,
|
|
14
|
+
children
|
|
15
|
+
});
|
|
16
|
+
case "meta": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
|
|
17
|
+
...attrs,
|
|
18
|
+
suppressHydrationWarning: true
|
|
19
|
+
});
|
|
20
|
+
case "link": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("link", {
|
|
21
|
+
...attrs,
|
|
22
|
+
nonce,
|
|
23
|
+
suppressHydrationWarning: true
|
|
24
|
+
});
|
|
25
|
+
case "style": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", {
|
|
26
|
+
...attrs,
|
|
27
|
+
dangerouslySetInnerHTML: { __html: children },
|
|
28
|
+
nonce
|
|
29
|
+
});
|
|
30
|
+
case "script": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Script, {
|
|
31
|
+
attrs,
|
|
32
|
+
children
|
|
33
|
+
});
|
|
34
|
+
default: return null;
|
|
35
|
+
}
|
|
23
36
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const existingScript = Array.from(
|
|
102
|
-
document.querySelectorAll("script:not([src])")
|
|
103
|
-
).find((el) => {
|
|
104
|
-
if (!(el instanceof HTMLScriptElement)) return false;
|
|
105
|
-
const sType = el.getAttribute("type") ?? "text/javascript";
|
|
106
|
-
const sNonce = el.getAttribute("nonce") ?? void 0;
|
|
107
|
-
return el.textContent === children && sType === typeAttr && sNonce === nonceAttr;
|
|
108
|
-
});
|
|
109
|
-
if (existingScript) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const script = document.createElement("script");
|
|
113
|
-
script.textContent = children;
|
|
114
|
-
if (attrs) {
|
|
115
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
116
|
-
if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) {
|
|
117
|
-
script.setAttribute(
|
|
118
|
-
key,
|
|
119
|
-
typeof value === "boolean" ? "" : String(value)
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
document.head.appendChild(script);
|
|
125
|
-
return () => {
|
|
126
|
-
if (script.parentNode) {
|
|
127
|
-
script.parentNode.removeChild(script);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return void 0;
|
|
132
|
-
}, [attrs, children, dataScript]);
|
|
133
|
-
if (isServer.isServer ?? router.isServer) {
|
|
134
|
-
if (attrs?.src) {
|
|
135
|
-
return /* @__PURE__ */ jsxRuntime.jsx("script", { ...attrs, suppressHydrationWarning: true });
|
|
136
|
-
}
|
|
137
|
-
if (typeof children === "string") {
|
|
138
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
139
|
-
"script",
|
|
140
|
-
{
|
|
141
|
-
...attrs,
|
|
142
|
-
dangerouslySetInnerHTML: { __html: children },
|
|
143
|
-
suppressHydrationWarning: true
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
if (dataScript && typeof children === "string") {
|
|
150
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
151
|
-
"script",
|
|
152
|
-
{
|
|
153
|
-
...attrs,
|
|
154
|
-
suppressHydrationWarning: true,
|
|
155
|
-
dangerouslySetInnerHTML: { __html: children }
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
if (!hydrated) {
|
|
160
|
-
if (attrs?.src) {
|
|
161
|
-
return /* @__PURE__ */ jsxRuntime.jsx("script", { ...attrs, suppressHydrationWarning: true });
|
|
162
|
-
}
|
|
163
|
-
if (typeof children === "string") {
|
|
164
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
165
|
-
"script",
|
|
166
|
-
{
|
|
167
|
-
...attrs,
|
|
168
|
-
dangerouslySetInnerHTML: { __html: children },
|
|
169
|
-
suppressHydrationWarning: true
|
|
170
|
-
}
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return null;
|
|
37
|
+
function Script({ attrs, children }) {
|
|
38
|
+
const router = require_useRouter.useRouter();
|
|
39
|
+
const hydrated = require_ClientOnly.useHydrated();
|
|
40
|
+
const dataScript = typeof attrs?.type === "string" && attrs.type !== "" && attrs.type !== "text/javascript" && attrs.type !== "module";
|
|
41
|
+
if (process.env.NODE_ENV !== "production" && attrs?.src && typeof children === "string" && children.trim().length) console.warn("[TanStack Router] <Script> received both `src` and `children`. The `children` content will be ignored. Remove `children` or remove `src`.");
|
|
42
|
+
react.useEffect(() => {
|
|
43
|
+
if (dataScript) return;
|
|
44
|
+
if (attrs?.src) {
|
|
45
|
+
const normSrc = (() => {
|
|
46
|
+
try {
|
|
47
|
+
const base = document.baseURI || window.location.href;
|
|
48
|
+
return new URL(attrs.src, base).href;
|
|
49
|
+
} catch {
|
|
50
|
+
return attrs.src;
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
if (Array.from(document.querySelectorAll("script[src]")).find((el) => el.src === normSrc)) return;
|
|
54
|
+
const script = document.createElement("script");
|
|
55
|
+
for (const [key, value] of Object.entries(attrs)) if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) script.setAttribute(key, typeof value === "boolean" ? "" : String(value));
|
|
56
|
+
document.head.appendChild(script);
|
|
57
|
+
return () => {
|
|
58
|
+
if (script.parentNode) script.parentNode.removeChild(script);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (typeof children === "string") {
|
|
62
|
+
const typeAttr = typeof attrs?.type === "string" ? attrs.type : "text/javascript";
|
|
63
|
+
const nonceAttr = typeof attrs?.nonce === "string" ? attrs.nonce : void 0;
|
|
64
|
+
if (Array.from(document.querySelectorAll("script:not([src])")).find((el) => {
|
|
65
|
+
if (!(el instanceof HTMLScriptElement)) return false;
|
|
66
|
+
const sType = el.getAttribute("type") ?? "text/javascript";
|
|
67
|
+
const sNonce = el.getAttribute("nonce") ?? void 0;
|
|
68
|
+
return el.textContent === children && sType === typeAttr && sNonce === nonceAttr;
|
|
69
|
+
})) return;
|
|
70
|
+
const script = document.createElement("script");
|
|
71
|
+
script.textContent = children;
|
|
72
|
+
if (attrs) {
|
|
73
|
+
for (const [key, value] of Object.entries(attrs)) if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) script.setAttribute(key, typeof value === "boolean" ? "" : String(value));
|
|
74
|
+
}
|
|
75
|
+
document.head.appendChild(script);
|
|
76
|
+
return () => {
|
|
77
|
+
if (script.parentNode) script.parentNode.removeChild(script);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}, [
|
|
81
|
+
attrs,
|
|
82
|
+
children,
|
|
83
|
+
dataScript
|
|
84
|
+
]);
|
|
85
|
+
if (_tanstack_router_core_isServer.isServer ?? router.isServer) {
|
|
86
|
+
if (attrs?.src) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
87
|
+
...attrs,
|
|
88
|
+
suppressHydrationWarning: true
|
|
89
|
+
});
|
|
90
|
+
if (typeof children === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
91
|
+
...attrs,
|
|
92
|
+
dangerouslySetInnerHTML: { __html: children },
|
|
93
|
+
suppressHydrationWarning: true
|
|
94
|
+
});
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (dataScript && typeof children === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
98
|
+
...attrs,
|
|
99
|
+
suppressHydrationWarning: true,
|
|
100
|
+
dangerouslySetInnerHTML: { __html: children }
|
|
101
|
+
});
|
|
102
|
+
if (!hydrated) {
|
|
103
|
+
if (attrs?.src) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
104
|
+
...attrs,
|
|
105
|
+
suppressHydrationWarning: true
|
|
106
|
+
});
|
|
107
|
+
if (typeof children === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
108
|
+
...attrs,
|
|
109
|
+
dangerouslySetInnerHTML: { __html: children },
|
|
110
|
+
suppressHydrationWarning: true
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
175
114
|
}
|
|
115
|
+
//#endregion
|
|
176
116
|
exports.Asset = Asset;
|
|
177
|
-
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=Asset.cjs.map
|
package/dist/cjs/Asset.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.cjs","sources":["../../src/Asset.tsx"],"sourcesContent":["import * as React from 'react'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport { useHydrated } from './ClientOnly'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\ninterface ScriptAttrs {\n [key: string]: string | boolean | undefined\n src?: string\n suppressHydrationWarning?: boolean\n}\n\nexport function Asset({\n tag,\n attrs,\n children,\n nonce,\n}: RouterManagedTag & { nonce?: string }): React.ReactElement | null {\n switch (tag) {\n case 'title':\n return (\n <title {...attrs} suppressHydrationWarning>\n {children}\n </title>\n )\n case 'meta':\n return <meta {...attrs} suppressHydrationWarning />\n case 'link':\n return <link {...attrs} nonce={nonce} suppressHydrationWarning />\n case 'style':\n return (\n <style\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children as string }}\n nonce={nonce}\n />\n )\n case 'script':\n return <Script attrs={attrs}>{children}</Script>\n default:\n return null\n }\n}\n\nfunction Script({\n attrs,\n children,\n}: {\n attrs?: ScriptAttrs\n children?: string\n}) {\n const router = useRouter()\n const hydrated = useHydrated()\n const dataScript =\n typeof attrs?.type === 'string' &&\n attrs.type !== '' &&\n attrs.type !== 'text/javascript' &&\n attrs.type !== 'module'\n\n if (\n process.env.NODE_ENV !== 'production' &&\n attrs?.src &&\n typeof children === 'string' &&\n children.trim().length\n ) {\n console.warn(\n '[TanStack Router] <Script> received both `src` and `children`. The `children` content will be ignored. Remove `children` or remove `src`.',\n )\n }\n\n React.useEffect(() => {\n if (dataScript) return\n\n if (attrs?.src) {\n const normSrc = (() => {\n try {\n const base = document.baseURI || window.location.href\n return new URL(attrs.src, base).href\n } catch {\n return attrs.src\n }\n })()\n const existingScript = Array.from(\n document.querySelectorAll('script[src]'),\n ).find((el) => (el as HTMLScriptElement).src === normSrc)\n\n if (existingScript) {\n return\n }\n\n const script = document.createElement('script')\n\n for (const [key, value] of Object.entries(attrs)) {\n if (\n key !== 'suppressHydrationWarning' &&\n value !== undefined &&\n value !== false\n ) {\n script.setAttribute(\n key,\n typeof value === 'boolean' ? '' : String(value),\n )\n }\n }\n\n document.head.appendChild(script)\n\n return () => {\n if (script.parentNode) {\n script.parentNode.removeChild(script)\n }\n }\n }\n\n if (typeof children === 'string') {\n const typeAttr =\n typeof attrs?.type === 'string' ? attrs.type : 'text/javascript'\n const nonceAttr =\n typeof attrs?.nonce === 'string' ? attrs.nonce : undefined\n const existingScript = Array.from(\n document.querySelectorAll('script:not([src])'),\n ).find((el) => {\n if (!(el instanceof HTMLScriptElement)) return false\n const sType = el.getAttribute('type') ?? 'text/javascript'\n const sNonce = el.getAttribute('nonce') ?? undefined\n return (\n el.textContent === children &&\n sType === typeAttr &&\n sNonce === nonceAttr\n )\n })\n\n if (existingScript) {\n return\n }\n\n const script = document.createElement('script')\n script.textContent = children\n\n if (attrs) {\n for (const [key, value] of Object.entries(attrs)) {\n if (\n key !== 'suppressHydrationWarning' &&\n value !== undefined &&\n value !== false\n ) {\n script.setAttribute(\n key,\n typeof value === 'boolean' ? '' : String(value),\n )\n }\n }\n }\n\n document.head.appendChild(script)\n\n return () => {\n if (script.parentNode) {\n script.parentNode.removeChild(script)\n }\n }\n }\n\n return undefined\n }, [attrs, children, dataScript])\n\n // --- Server rendering ---\n if (isServer ?? router.isServer) {\n if (attrs?.src) {\n return <script {...attrs} suppressHydrationWarning />\n }\n\n if (typeof children === 'string') {\n return (\n <script\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children }}\n suppressHydrationWarning\n />\n )\n }\n\n return null\n }\n\n // --- Client rendering ---\n\n // Data scripts (e.g. application/ld+json) are rendered in the tree;\n // the useEffect intentionally skips them.\n if (dataScript && typeof children === 'string') {\n return (\n <script\n {...attrs}\n suppressHydrationWarning\n dangerouslySetInnerHTML={{ __html: children }}\n />\n )\n }\n\n // During hydration (before useEffect has fired), render the script element\n // to match the server-rendered HTML and avoid structural hydration mismatches.\n // After hydration, return null — the useEffect handles imperative injection.\n if (!hydrated) {\n if (attrs?.src) {\n return <script {...attrs} suppressHydrationWarning />\n }\n if (typeof children === 'string') {\n return (\n <script\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children }}\n suppressHydrationWarning\n />\n )\n }\n }\n\n return null\n}\n"],"
|
|
1
|
+
{"version":3,"file":"Asset.cjs","names":[],"sources":["../../src/Asset.tsx"],"sourcesContent":["import * as React from 'react'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport { useHydrated } from './ClientOnly'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\ninterface ScriptAttrs {\n [key: string]: string | boolean | undefined\n src?: string\n suppressHydrationWarning?: boolean\n}\n\nexport function Asset({\n tag,\n attrs,\n children,\n nonce,\n}: RouterManagedTag & { nonce?: string }): React.ReactElement | null {\n switch (tag) {\n case 'title':\n return (\n <title {...attrs} suppressHydrationWarning>\n {children}\n </title>\n )\n case 'meta':\n return <meta {...attrs} suppressHydrationWarning />\n case 'link':\n return <link {...attrs} nonce={nonce} suppressHydrationWarning />\n case 'style':\n return (\n <style\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children as string }}\n nonce={nonce}\n />\n )\n case 'script':\n return <Script attrs={attrs}>{children}</Script>\n default:\n return null\n }\n}\n\nfunction Script({\n attrs,\n children,\n}: {\n attrs?: ScriptAttrs\n children?: string\n}) {\n const router = useRouter()\n const hydrated = useHydrated()\n const dataScript =\n typeof attrs?.type === 'string' &&\n attrs.type !== '' &&\n attrs.type !== 'text/javascript' &&\n attrs.type !== 'module'\n\n if (\n process.env.NODE_ENV !== 'production' &&\n attrs?.src &&\n typeof children === 'string' &&\n children.trim().length\n ) {\n console.warn(\n '[TanStack Router] <Script> received both `src` and `children`. The `children` content will be ignored. Remove `children` or remove `src`.',\n )\n }\n\n React.useEffect(() => {\n if (dataScript) return\n\n if (attrs?.src) {\n const normSrc = (() => {\n try {\n const base = document.baseURI || window.location.href\n return new URL(attrs.src, base).href\n } catch {\n return attrs.src\n }\n })()\n const existingScript = Array.from(\n document.querySelectorAll('script[src]'),\n ).find((el) => (el as HTMLScriptElement).src === normSrc)\n\n if (existingScript) {\n return\n }\n\n const script = document.createElement('script')\n\n for (const [key, value] of Object.entries(attrs)) {\n if (\n key !== 'suppressHydrationWarning' &&\n value !== undefined &&\n value !== false\n ) {\n script.setAttribute(\n key,\n typeof value === 'boolean' ? '' : String(value),\n )\n }\n }\n\n document.head.appendChild(script)\n\n return () => {\n if (script.parentNode) {\n script.parentNode.removeChild(script)\n }\n }\n }\n\n if (typeof children === 'string') {\n const typeAttr =\n typeof attrs?.type === 'string' ? attrs.type : 'text/javascript'\n const nonceAttr =\n typeof attrs?.nonce === 'string' ? attrs.nonce : undefined\n const existingScript = Array.from(\n document.querySelectorAll('script:not([src])'),\n ).find((el) => {\n if (!(el instanceof HTMLScriptElement)) return false\n const sType = el.getAttribute('type') ?? 'text/javascript'\n const sNonce = el.getAttribute('nonce') ?? undefined\n return (\n el.textContent === children &&\n sType === typeAttr &&\n sNonce === nonceAttr\n )\n })\n\n if (existingScript) {\n return\n }\n\n const script = document.createElement('script')\n script.textContent = children\n\n if (attrs) {\n for (const [key, value] of Object.entries(attrs)) {\n if (\n key !== 'suppressHydrationWarning' &&\n value !== undefined &&\n value !== false\n ) {\n script.setAttribute(\n key,\n typeof value === 'boolean' ? '' : String(value),\n )\n }\n }\n }\n\n document.head.appendChild(script)\n\n return () => {\n if (script.parentNode) {\n script.parentNode.removeChild(script)\n }\n }\n }\n\n return undefined\n }, [attrs, children, dataScript])\n\n // --- Server rendering ---\n if (isServer ?? router.isServer) {\n if (attrs?.src) {\n return <script {...attrs} suppressHydrationWarning />\n }\n\n if (typeof children === 'string') {\n return (\n <script\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children }}\n suppressHydrationWarning\n />\n )\n }\n\n return null\n }\n\n // --- Client rendering ---\n\n // Data scripts (e.g. application/ld+json) are rendered in the tree;\n // the useEffect intentionally skips them.\n if (dataScript && typeof children === 'string') {\n return (\n <script\n {...attrs}\n suppressHydrationWarning\n dangerouslySetInnerHTML={{ __html: children }}\n />\n )\n }\n\n // During hydration (before useEffect has fired), render the script element\n // to match the server-rendered HTML and avoid structural hydration mismatches.\n // After hydration, return null — the useEffect handles imperative injection.\n if (!hydrated) {\n if (attrs?.src) {\n return <script {...attrs} suppressHydrationWarning />\n }\n if (typeof children === 'string') {\n return (\n <script\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children }}\n suppressHydration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AO,aAAa,SACtB,QACE,iBAAA,GAAA,kBAAA,KAAC,UAAD;GACE,GAAI;GACJ,yBAAyB,EAAE,QAAQ,UAAU;GAC7C,0BAAA;GACA,CAAA;AAIN,SAAO;;AAOT,KAAI,cAAc,OAAO,aAAa,SACpC,QACE,iBAAA,GAAA,kBAAA,KAAC,UAAD;EACE,GAAI;EACJ,0BAAA;EACA,yBAAyB,EAAE,QAAQ,UAAU;EAC7C,CAAA;AAON,KAAI,CAAC,UAAU;AACb,MAAI,OAAO,IACT,QAAO,iBAAA,GAAA,kBAAA,KAAC,UAAD;GAAQ,GAAI;GAAO,0BAAA;GAA2B,CAAA;AAEvD,MAAI,OAAO,aAAa,SACtB,QACE,iBAAA,GAAA,kBAAA,KAAC,UAAD;GACE,GAAI;GACJ,yBAAyB,EAAE,QAAQ,UAAU;GAC7C,0BAAA;GACA,CAAA;;AAKR,QAAO"}
|
|
@@ -1,114 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
-
if (e) {
|
|
8
|
-
for (const k in e) {
|
|
9
|
-
if (k !== "default") {
|
|
10
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
react = require_runtime.__toESM(react);
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
//#region src/CatchBoundary.tsx
|
|
22
6
|
function CatchBoundary(props) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return props.children;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
class CatchBoundaryImpl extends React__namespace.Component {
|
|
42
|
-
constructor() {
|
|
43
|
-
super(...arguments);
|
|
44
|
-
this.state = { error: null };
|
|
45
|
-
}
|
|
46
|
-
static getDerivedStateFromProps(props) {
|
|
47
|
-
return { resetKey: props.getResetKey() };
|
|
48
|
-
}
|
|
49
|
-
static getDerivedStateFromError(error) {
|
|
50
|
-
return { error };
|
|
51
|
-
}
|
|
52
|
-
reset() {
|
|
53
|
-
this.setState({ error: null });
|
|
54
|
-
}
|
|
55
|
-
componentDidUpdate(prevProps, prevState) {
|
|
56
|
-
if (prevState.error && prevState.resetKey !== this.state.resetKey) {
|
|
57
|
-
this.reset();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
componentDidCatch(error, errorInfo) {
|
|
61
|
-
if (this.props.onCatch) {
|
|
62
|
-
this.props.onCatch(error, errorInfo);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
render() {
|
|
66
|
-
return this.props.children({
|
|
67
|
-
error: this.state.resetKey !== this.props.getResetKey() ? null : this.state.error,
|
|
68
|
-
reset: () => {
|
|
69
|
-
this.reset();
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
7
|
+
const errorComponent = props.errorComponent ?? ErrorComponent;
|
|
8
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CatchBoundaryImpl, {
|
|
9
|
+
getResetKey: props.getResetKey,
|
|
10
|
+
onCatch: props.onCatch,
|
|
11
|
+
children: ({ error, reset }) => {
|
|
12
|
+
if (error) return react.createElement(errorComponent, {
|
|
13
|
+
error,
|
|
14
|
+
reset
|
|
15
|
+
});
|
|
16
|
+
return props.children;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
73
19
|
}
|
|
20
|
+
var CatchBoundaryImpl = class extends react.Component {
|
|
21
|
+
constructor(..._args) {
|
|
22
|
+
super(..._args);
|
|
23
|
+
this.state = { error: null };
|
|
24
|
+
}
|
|
25
|
+
static getDerivedStateFromProps(props) {
|
|
26
|
+
return { resetKey: props.getResetKey() };
|
|
27
|
+
}
|
|
28
|
+
static getDerivedStateFromError(error) {
|
|
29
|
+
return { error };
|
|
30
|
+
}
|
|
31
|
+
reset() {
|
|
32
|
+
this.setState({ error: null });
|
|
33
|
+
}
|
|
34
|
+
componentDidUpdate(prevProps, prevState) {
|
|
35
|
+
if (prevState.error && prevState.resetKey !== this.state.resetKey) this.reset();
|
|
36
|
+
}
|
|
37
|
+
componentDidCatch(error, errorInfo) {
|
|
38
|
+
if (this.props.onCatch) this.props.onCatch(error, errorInfo);
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
return this.props.children({
|
|
42
|
+
error: this.state.resetKey !== this.props.getResetKey() ? null : this.state.error,
|
|
43
|
+
reset: () => {
|
|
44
|
+
this.reset();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
74
49
|
function ErrorComponent({ error }) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
50
|
+
const [show, setShow] = react.useState(process.env.NODE_ENV !== "production");
|
|
51
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
52
|
+
style: {
|
|
53
|
+
padding: ".5rem",
|
|
54
|
+
maxWidth: "100%"
|
|
55
|
+
},
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
58
|
+
style: {
|
|
59
|
+
display: "flex",
|
|
60
|
+
alignItems: "center",
|
|
61
|
+
gap: ".5rem"
|
|
62
|
+
},
|
|
63
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
|
|
64
|
+
style: { fontSize: "1rem" },
|
|
65
|
+
children: "Something went wrong!"
|
|
66
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
67
|
+
style: {
|
|
68
|
+
appearance: "none",
|
|
69
|
+
fontSize: ".6em",
|
|
70
|
+
border: "1px solid currentColor",
|
|
71
|
+
padding: ".1rem .2rem",
|
|
72
|
+
fontWeight: "bold",
|
|
73
|
+
borderRadius: ".25rem"
|
|
74
|
+
},
|
|
75
|
+
onClick: () => setShow((d) => !d),
|
|
76
|
+
children: show ? "Hide Error" : "Show Error"
|
|
77
|
+
})]
|
|
78
|
+
}),
|
|
79
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { height: ".25rem" } }),
|
|
80
|
+
show ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
81
|
+
style: {
|
|
82
|
+
fontSize: ".7em",
|
|
83
|
+
border: "1px solid red",
|
|
84
|
+
borderRadius: ".25rem",
|
|
85
|
+
padding: ".3rem",
|
|
86
|
+
color: "red",
|
|
87
|
+
overflow: "auto"
|
|
88
|
+
},
|
|
89
|
+
children: error.message ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: error.message }) : null
|
|
90
|
+
}) }) : null
|
|
91
|
+
]
|
|
92
|
+
});
|
|
111
93
|
}
|
|
94
|
+
//#endregion
|
|
112
95
|
exports.CatchBoundary = CatchBoundary;
|
|
113
96
|
exports.ErrorComponent = ErrorComponent;
|
|
114
|
-
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=CatchBoundary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CatchBoundary.cjs","sources":["../../src/CatchBoundary.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { ErrorRouteComponent } from './route'\nimport type { ErrorInfo } from 'react'\n\nexport function CatchBoundary(props: {\n getResetKey: () => number | string\n children: React.ReactNode\n errorComponent?: ErrorRouteComponent\n onCatch?: (error: Error, errorInfo: ErrorInfo) => void\n}) {\n const errorComponent = props.errorComponent ?? ErrorComponent\n\n return (\n <CatchBoundaryImpl\n getResetKey={props.getResetKey}\n onCatch={props.onCatch}\n children={({ error, reset }) => {\n if (error) {\n return React.createElement(errorComponent, {\n error,\n reset,\n })\n }\n\n return props.children\n }}\n />\n )\n}\n\nclass CatchBoundaryImpl extends React.Component<{\n getResetKey: () => number | string\n children: (props: {\n error: Error | null\n reset: () => void\n }) => React.ReactNode\n onCatch?: (error: Error, errorInfo: ErrorInfo) => void\n}> {\n state = { error: null } as { error: Error | null; resetKey: string }\n static getDerivedStateFromProps(props: any) {\n return { resetKey: props.getResetKey() }\n }\n static getDerivedStateFromError(error: Error) {\n return { error }\n }\n reset() {\n this.setState({ error: null })\n }\n componentDidUpdate(\n prevProps: Readonly<{\n getResetKey: () => string\n children: (props: { error: any; reset: () => void }) => any\n onCatch?: ((error: any, info: any) => void) | undefined\n }>,\n prevState: any,\n ): void {\n if (prevState.error && prevState.resetKey !== this.state.resetKey) {\n this.reset()\n }\n }\n componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n if (this.props.onCatch) {\n this.props.onCatch(error, errorInfo)\n }\n }\n render() {\n // If the resetKey has changed, don't render the error\n return this.props.children({\n error:\n this.state.resetKey !== this.props.getResetKey()\n ? null\n : this.state.error,\n reset: () => {\n this.reset()\n },\n })\n }\n}\n\nexport function ErrorComponent({ error }: { error: any }) {\n const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production')\n\n return (\n <div style={{ padding: '.5rem', maxWidth: '100%' }}>\n <div style={{ display: 'flex', alignItems: 'center', gap: '.5rem' }}>\n <strong style={{ fontSize: '1rem' }}>Something went wrong!</strong>\n <button\n style={{\n appearance: 'none',\n fontSize: '.6em',\n border: '1px solid currentColor',\n padding: '.1rem .2rem',\n fontWeight: 'bold',\n borderRadius: '.25rem',\n }}\n onClick={() => setShow((d) => !d)}\n >\n {show ? 'Hide Error' : 'Show Error'}\n </button>\n </div>\n <div style={{ height: '.25rem' }} />\n {show ? (\n <div>\n <pre\n style={{\n fontSize: '.7em',\n border: '1px solid red',\n borderRadius: '.25rem',\n padding: '.3rem',\n color: 'red',\n overflow: 'auto',\n }}\n >\n {error.message ? <code>{error.message}</code> : null}\n </pre>\n </div>\n ) : null}\n </div>\n )\n}\n"],"
|
|
1
|
+
{"version":3,"file":"CatchBoundary.cjs","names":[],"sources":["../../src/CatchBoundary.tsx"],"sourcesContent":["import * as React from 'react'\nimport type { ErrorRouteComponent } from './route'\nimport type { ErrorInfo } from 'react'\n\nexport function CatchBoundary(props: {\n getResetKey: () => number | string\n children: React.ReactNode\n errorComponent?: ErrorRouteComponent\n onCatch?: (error: Error, errorInfo: ErrorInfo) => void\n}) {\n const errorComponent = props.errorComponent ?? ErrorComponent\n\n return (\n <CatchBoundaryImpl\n getResetKey={props.getResetKey}\n onCatch={props.onCatch}\n children={({ error, reset }) => {\n if (error) {\n return React.createElement(errorComponent, {\n error,\n reset,\n })\n }\n\n return props.children\n }}\n />\n )\n}\n\nclass CatchBoundaryImpl extends React.Component<{\n getResetKey: () => number | string\n children: (props: {\n error: Error | null\n reset: () => void\n }) => React.ReactNode\n onCatch?: (error: Error, errorInfo: ErrorInfo) => void\n}> {\n state = { error: null } as { error: Error | null; resetKey: string }\n static getDerivedStateFromProps(props: any) {\n return { resetKey: props.getResetKey() }\n }\n static getDerivedStateFromError(error: Error) {\n return { error }\n }\n reset() {\n this.setState({ error: null })\n }\n componentDidUpdate(\n prevProps: Readonly<{\n getResetKey: () => string\n children: (props: { error: any; reset: () => void }) => any\n onCatch?: ((error: any, info: any) => void) | undefined\n }>,\n prevState: any,\n ): void {\n if (prevState.error && prevState.resetKey !== this.state.resetKey) {\n this.reset()\n }\n }\n componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n if (this.props.onCatch) {\n this.props.onCatch(error, errorInfo)\n }\n }\n render() {\n // If the resetKey has changed, don't render the error\n return this.props.children({\n error:\n this.state.resetKey !== this.props.getResetKey()\n ? null\n : this.state.error,\n reset: () => {\n this.reset()\n },\n })\n }\n}\n\nexport function ErrorComponent({ error }: { error: any }) {\n const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production')\n\n return (\n <div style={{ padding: '.5rem', maxWidth: '100%' }}>\n <div style={{ display: 'flex', alignItems: 'center', gap: '.5rem' }}>\n <strong style={{ fontSize: '1rem' }}>Something went wrong!</strong>\n <button\n style={{\n appearance: 'none',\n fontSize: '.6em',\n border: '1px solid currentColor',\n padding: '.1rem .2rem',\n fontWeight: 'bold',\n borderRadius: '.25rem',\n }}\n onClick={() => setShow((d) => !d)}\n >\n {show ? 'Hide Error' : 'Show Error'}\n </button>\n </div>\n <div style={{ height: '.25rem' }} />\n {show ? (\n <div>\n <pre\n style={{\n fontSize: '.7em',\n border: '1px solid red',\n borderRadius: '.25rem',\n padding: '.3rem',\n color: 'red',\n overflow: 'auto',\n }}\n >\n {error.message ? <code>{error.message}</code> : null}\n </pre>\n </div>\n ) : null}\n </div>\n )\n}\n"],"mappings":";;;;;AAIA,SAAgB,cAAc,OAK3B;CACD,MAAM,iBAAiB,MAAM,kBAAkB;AAE/C,QACE,iBAAA,GAAA,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