@tanstack/react-router 1.40.0 → 1.41.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/dist/cjs/CatchBoundary.d.cts +2 -2
- package/dist/cjs/Match.cjs +238 -0
- package/dist/cjs/Match.cjs.map +1 -0
- package/dist/cjs/Match.d.cts +5 -0
- package/dist/cjs/Matches.cjs +8 -249
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -11
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +2 -2
- package/dist/cjs/SafeFragment.cjs +8 -0
- package/dist/cjs/SafeFragment.cjs.map +1 -0
- package/dist/cjs/SafeFragment.d.cts +1 -0
- package/dist/cjs/ScriptOnce.cjs +28 -0
- package/dist/cjs/ScriptOnce.cjs.map +1 -0
- package/dist/cjs/ScriptOnce.d.cts +5 -0
- package/dist/cjs/Transitioner.cjs +2 -1
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/awaited.cjs +14 -71
- package/dist/cjs/awaited.cjs.map +1 -1
- package/dist/cjs/awaited.d.cts +3 -6
- package/dist/cjs/defer.cjs +7 -13
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/defer.d.cts +2 -6
- package/dist/cjs/index.cjs +11 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +8 -3
- package/dist/cjs/isServerSideError.cjs +22 -0
- package/dist/cjs/isServerSideError.cjs.map +1 -0
- package/dist/cjs/isServerSideError.d.cts +5 -0
- package/dist/cjs/link.cjs +1 -0
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/matchContext.cjs +23 -0
- package/dist/cjs/matchContext.cjs.map +1 -0
- package/dist/cjs/matchContext.d.cts +2 -0
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/not-found.d.cts +2 -2
- package/dist/cjs/qss.cjs.map +1 -1
- package/dist/cjs/qss.d.cts +1 -1
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/renderRouteNotFound.cjs +22 -0
- package/dist/cjs/renderRouteNotFound.cjs.map +1 -0
- package/dist/cjs/renderRouteNotFound.d.cts +4 -0
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/router.cjs +26 -22
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +14 -9
- package/dist/cjs/useMatch.cjs +2 -2
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/utils.cjs +4 -3
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +3 -2
- package/dist/esm/CatchBoundary.d.ts +2 -2
- package/dist/esm/Match.d.ts +5 -0
- package/dist/esm/Match.js +221 -0
- package/dist/esm/Match.js.map +1 -0
- package/dist/esm/Matches.d.ts +2 -11
- package/dist/esm/Matches.js +5 -246
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +2 -2
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/SafeFragment.d.ts +1 -0
- package/dist/esm/SafeFragment.js +8 -0
- package/dist/esm/SafeFragment.js.map +1 -0
- package/dist/esm/ScriptOnce.d.ts +5 -0
- package/dist/esm/ScriptOnce.js +28 -0
- package/dist/esm/ScriptOnce.js.map +1 -0
- package/dist/esm/Transitioner.js +2 -1
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/awaited.d.ts +3 -6
- package/dist/esm/awaited.js +16 -73
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/defer.d.ts +2 -6
- package/dist/esm/defer.js +8 -14
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/index.d.ts +8 -3
- package/dist/esm/index.js +9 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/isServerSideError.d.ts +5 -0
- package/dist/esm/isServerSideError.js +22 -0
- package/dist/esm/isServerSideError.js.map +1 -0
- package/dist/esm/link.js +1 -0
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/matchContext.d.ts +2 -0
- package/dist/esm/matchContext.js +6 -0
- package/dist/esm/matchContext.js.map +1 -0
- package/dist/esm/not-found.d.ts +2 -2
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/qss.d.ts +1 -1
- package/dist/esm/qss.js.map +1 -1
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/renderRouteNotFound.d.ts +4 -0
- package/dist/esm/renderRouteNotFound.js +22 -0
- package/dist/esm/renderRouteNotFound.js.map +1 -0
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +14 -9
- package/dist/esm/router.js +26 -22
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useMatch.js +1 -1
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/utils.d.ts +3 -2
- package/dist/esm/utils.js +4 -3
- package/dist/esm/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/Match.tsx +296 -0
- package/src/Matches.tsx +4 -333
- package/src/RouterProvider.tsx +1 -1
- package/src/SafeFragment.tsx +5 -0
- package/src/ScriptOnce.tsx +27 -0
- package/src/Transitioner.tsx +1 -1
- package/src/awaited.tsx +17 -89
- package/src/defer.ts +9 -26
- package/src/index.tsx +7 -13
- package/src/isServerSideError.tsx +23 -0
- package/src/link.tsx +2 -0
- package/src/matchContext.tsx +3 -0
- package/src/not-found.tsx +1 -1
- package/src/qss.ts +5 -6
- package/src/redirects.ts +0 -1
- package/src/renderRouteNotFound.tsx +28 -0
- package/src/route.ts +1 -1
- package/src/router.ts +50 -39
- package/src/useMatch.tsx +1 -1
- package/src/utils.ts +11 -9
|
@@ -6,7 +6,7 @@ export declare function CatchBoundary(props: {
|
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
errorComponent?: ErrorRouteComponent;
|
|
8
8
|
onCatch?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
9
|
-
}):
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
export declare function ErrorComponent({ error }: {
|
|
11
11
|
error: any;
|
|
12
|
-
}):
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const invariant = require("tiny-invariant");
|
|
7
|
+
const warning = require("tiny-warning");
|
|
8
|
+
const CatchBoundary = require("./CatchBoundary.cjs");
|
|
9
|
+
const useRouterState = require("./useRouterState.cjs");
|
|
10
|
+
const useRouter = require("./useRouter.cjs");
|
|
11
|
+
const utils = require("./utils.cjs");
|
|
12
|
+
const notFound = require("./not-found.cjs");
|
|
13
|
+
const redirects = require("./redirects.cjs");
|
|
14
|
+
const matchContext = require("./matchContext.cjs");
|
|
15
|
+
const isServerSideError = require("./isServerSideError.cjs");
|
|
16
|
+
const SafeFragment = require("./SafeFragment.cjs");
|
|
17
|
+
const renderRouteNotFound = require("./renderRouteNotFound.cjs");
|
|
18
|
+
const root = require("./root.cjs");
|
|
19
|
+
function _interopNamespaceDefault(e) {
|
|
20
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
21
|
+
if (e) {
|
|
22
|
+
for (const k in e) {
|
|
23
|
+
if (k !== "default") {
|
|
24
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: () => e[k]
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
n.default = e;
|
|
33
|
+
return Object.freeze(n);
|
|
34
|
+
}
|
|
35
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
36
|
+
function Match({ matchId }) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const router = useRouter.useRouter();
|
|
39
|
+
const routeId = useRouterState.useRouterState({
|
|
40
|
+
select: (s) => {
|
|
41
|
+
var _a2;
|
|
42
|
+
return (_a2 = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a2.routeId;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
invariant(
|
|
46
|
+
routeId,
|
|
47
|
+
`Could not find routeId for matchId "${matchId}". Please file an issue!`
|
|
48
|
+
);
|
|
49
|
+
const route = router.routesById[routeId];
|
|
50
|
+
const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
|
|
51
|
+
const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntime.jsx(PendingComponent, {}) : null;
|
|
52
|
+
const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent;
|
|
53
|
+
const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch;
|
|
54
|
+
const routeNotFoundComponent = route.isRoot ? (
|
|
55
|
+
// If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
|
|
56
|
+
route.options.notFoundComponent ?? ((_a = router.options.notFoundRoute) == null ? void 0 : _a.options.component)
|
|
57
|
+
) : route.options.notFoundComponent;
|
|
58
|
+
const ResolvedSuspenseBoundary = (
|
|
59
|
+
// If we're on the root route, allow forcefully wrapping in suspense
|
|
60
|
+
(!route.isRoot || route.options.wrapInSuspense) && (route.options.wrapInSuspense ?? PendingComponent ?? ((_b = route.options.errorComponent) == null ? void 0 : _b.preload)) ? React__namespace.Suspense : SafeFragment.SafeFragment
|
|
61
|
+
);
|
|
62
|
+
const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary.CatchBoundary : SafeFragment.SafeFragment;
|
|
63
|
+
const ResolvedNotFoundBoundary = routeNotFoundComponent ? notFound.CatchNotFound : SafeFragment.SafeFragment;
|
|
64
|
+
const resetKey = useRouterState.useRouterState({
|
|
65
|
+
select: (s) => s.resolvedLocation.state.key
|
|
66
|
+
});
|
|
67
|
+
return /* @__PURE__ */ jsxRuntime.jsx(matchContext.matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsxRuntime.jsx(ResolvedSuspenseBoundary, { fallback: pendingElement, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
68
|
+
ResolvedCatchBoundary,
|
|
69
|
+
{
|
|
70
|
+
getResetKey: () => resetKey,
|
|
71
|
+
errorComponent: routeErrorComponent || CatchBoundary.ErrorComponent,
|
|
72
|
+
onCatch: (error, errorInfo) => {
|
|
73
|
+
if (notFound.isNotFound(error)) throw error;
|
|
74
|
+
warning(false, `Error in route match: ${matchId}`);
|
|
75
|
+
routeOnCatch == null ? void 0 : routeOnCatch(error, errorInfo);
|
|
76
|
+
},
|
|
77
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
78
|
+
ResolvedNotFoundBoundary,
|
|
79
|
+
{
|
|
80
|
+
fallback: (error) => {
|
|
81
|
+
if (!routeNotFoundComponent || error.routeId && error.routeId !== routeId || !error.routeId && !route.isRoot)
|
|
82
|
+
throw error;
|
|
83
|
+
return React__namespace.createElement(routeNotFoundComponent, error);
|
|
84
|
+
},
|
|
85
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(MatchInner, { matchId })
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
) }) });
|
|
90
|
+
}
|
|
91
|
+
function MatchInner({ matchId }) {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
const router = useRouter.useRouter();
|
|
94
|
+
const routeId = useRouterState.useRouterState({
|
|
95
|
+
select: (s) => {
|
|
96
|
+
var _a2;
|
|
97
|
+
return (_a2 = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a2.routeId;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const route = router.routesById[routeId];
|
|
101
|
+
const [match, matchIndex] = useRouterState.useRouterState({
|
|
102
|
+
select: (s) => {
|
|
103
|
+
const matchIndex2 = s.matches.findIndex((d) => d.id === matchId);
|
|
104
|
+
const match2 = s.matches[matchIndex2];
|
|
105
|
+
return [
|
|
106
|
+
utils.pick(match2, [
|
|
107
|
+
"id",
|
|
108
|
+
"status",
|
|
109
|
+
"error",
|
|
110
|
+
"loadPromise",
|
|
111
|
+
"minPendingPromise"
|
|
112
|
+
]),
|
|
113
|
+
matchIndex2
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || CatchBoundary.ErrorComponent;
|
|
118
|
+
if (match.status === "notFound") {
|
|
119
|
+
let error;
|
|
120
|
+
if (isServerSideError.isServerSideError(match.error)) {
|
|
121
|
+
const deserializeError = ((_a = router.options.errorSerializer) == null ? void 0 : _a.deserialize) ?? isServerSideError.defaultDeserializeError;
|
|
122
|
+
error = deserializeError(match.error.data);
|
|
123
|
+
} else {
|
|
124
|
+
error = match.error;
|
|
125
|
+
}
|
|
126
|
+
invariant(notFound.isNotFound(error), "Expected a notFound error");
|
|
127
|
+
return renderRouteNotFound.renderRouteNotFound(router, route, error);
|
|
128
|
+
}
|
|
129
|
+
if (match.status === "redirected") {
|
|
130
|
+
invariant(redirects.isRedirect(match.error), "Expected a redirect error");
|
|
131
|
+
throw match.loadPromise;
|
|
132
|
+
}
|
|
133
|
+
if (match.status === "error") {
|
|
134
|
+
if (router.isServer) {
|
|
135
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
136
|
+
RouteErrorComponent,
|
|
137
|
+
{
|
|
138
|
+
error: match.error,
|
|
139
|
+
info: {
|
|
140
|
+
componentStack: ""
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (isServerSideError.isServerSideError(match.error)) {
|
|
146
|
+
const deserializeError = ((_b = router.options.errorSerializer) == null ? void 0 : _b.deserialize) ?? isServerSideError.defaultDeserializeError;
|
|
147
|
+
throw deserializeError(match.error.data);
|
|
148
|
+
} else {
|
|
149
|
+
throw match.error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (match.status === "pending") {
|
|
153
|
+
const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
|
|
154
|
+
if (pendingMinMs && !match.minPendingPromise) {
|
|
155
|
+
match.minPendingPromise = utils.createControlledPromise();
|
|
156
|
+
if (!router.isServer) {
|
|
157
|
+
Promise.resolve().then(() => {
|
|
158
|
+
router.__store.setState((s) => ({
|
|
159
|
+
...s,
|
|
160
|
+
matches: s.matches.map(
|
|
161
|
+
(d) => d.id === match.id ? { ...d, minPendingPromise: utils.createControlledPromise() } : d
|
|
162
|
+
)
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
setTimeout(() => {
|
|
166
|
+
router.__store.setState((s) => {
|
|
167
|
+
return {
|
|
168
|
+
...s,
|
|
169
|
+
matches: s.matches.map(
|
|
170
|
+
(d) => {
|
|
171
|
+
var _a2;
|
|
172
|
+
return d.id === match.id ? {
|
|
173
|
+
...d,
|
|
174
|
+
minPendingPromise: ((_a2 = d.minPendingPromise) == null ? void 0 : _a2.resolve(), void 0)
|
|
175
|
+
} : d;
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
}, pendingMinMs);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
throw match.loadPromise;
|
|
184
|
+
}
|
|
185
|
+
const Comp = route.options.component ?? router.options.defaultComponent;
|
|
186
|
+
const out = Comp ? /* @__PURE__ */ jsxRuntime.jsx(Comp, {}) : /* @__PURE__ */ jsxRuntime.jsx(Outlet, {});
|
|
187
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
188
|
+
router.AfterEachMatch ? /* @__PURE__ */ jsxRuntime.jsx(router.AfterEachMatch, { match, matchIndex }) : null,
|
|
189
|
+
out
|
|
190
|
+
] });
|
|
191
|
+
}
|
|
192
|
+
const Outlet = React__namespace.memo(function Outlet2() {
|
|
193
|
+
const router = useRouter.useRouter();
|
|
194
|
+
const matchId = React__namespace.useContext(matchContext.matchContext);
|
|
195
|
+
const routeId = useRouterState.useRouterState({
|
|
196
|
+
select: (s) => {
|
|
197
|
+
var _a;
|
|
198
|
+
return (_a = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a.routeId;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
const route = router.routesById[routeId];
|
|
202
|
+
const { parentGlobalNotFound } = useRouterState.useRouterState({
|
|
203
|
+
select: (s) => {
|
|
204
|
+
const matches = s.matches;
|
|
205
|
+
const parentMatch = matches.find((d) => d.id === matchId);
|
|
206
|
+
invariant(
|
|
207
|
+
parentMatch,
|
|
208
|
+
`Could not find parent match for matchId "${matchId}"`
|
|
209
|
+
);
|
|
210
|
+
return {
|
|
211
|
+
parentGlobalNotFound: parentMatch.globalNotFound
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const childMatchId = useRouterState.useRouterState({
|
|
216
|
+
select: (s) => {
|
|
217
|
+
var _a;
|
|
218
|
+
const matches = s.matches;
|
|
219
|
+
const index = matches.findIndex((d) => d.id === matchId);
|
|
220
|
+
return (_a = matches[index + 1]) == null ? void 0 : _a.id;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
if (parentGlobalNotFound) {
|
|
224
|
+
return renderRouteNotFound.renderRouteNotFound(router, route, void 0);
|
|
225
|
+
}
|
|
226
|
+
if (!childMatchId) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
const nextMatch = /* @__PURE__ */ jsxRuntime.jsx(Match, { matchId: childMatchId });
|
|
230
|
+
const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsxRuntime.jsx(router.options.defaultPendingComponent, {}) : null;
|
|
231
|
+
if (matchId === root.rootRouteId) {
|
|
232
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React__namespace.Suspense, { fallback: pendingElement, children: nextMatch });
|
|
233
|
+
}
|
|
234
|
+
return nextMatch;
|
|
235
|
+
});
|
|
236
|
+
exports.Match = Match;
|
|
237
|
+
exports.Outlet = Outlet;
|
|
238
|
+
//# sourceMappingURL=Match.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Match.cjs","sources":["../../src/Match.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { createControlledPromise, pick } from './utils'\nimport { CatchNotFound, isNotFound } from './not-found'\nimport { isRedirect } from './redirects'\nimport { type AnyRoute } from './route'\nimport { matchContext } from './matchContext'\nimport { defaultDeserializeError, isServerSideError } from './isServerSideError'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { rootRouteId } from './root'\n\nexport function Match({ matchId }: { matchId: string }) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route: AnyRoute = router.routesById[routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component\n : route.options.notFoundComponent\n\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n (route.options.errorComponent as any)?.preload)\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const resetKey = useRouterState({\n select: (s) => s.resolvedLocation.state.key!,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n <MatchInner matchId={matchId} />\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n}\nfunction MatchInner({ matchId }: { matchId: string }): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const [match, matchIndex] = useRouterState({\n select: (s) => {\n const matchIndex = s.matches.findIndex((d) => d.id === matchId)\n const match = s.matches[matchIndex]!\n return [\n pick(match, [\n 'id',\n 'status',\n 'error',\n 'loadPromise',\n 'minPendingPromise',\n ]),\n matchIndex,\n ] as const\n },\n })\n\n const RouteErrorComponent =\n (route.options.errorComponent ?? router.options.defaultErrorComponent) ||\n ErrorComponent\n\n if (match.status === 'notFound') {\n let error: unknown\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n\n error = deserializeError(match.error.data)\n } else {\n error = match.error\n }\n\n invariant(isNotFound(error), 'Expected a notFound error')\n\n return renderRouteNotFound(router, route, error)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n invariant(isRedirect(match.error), 'Expected a redirect error')\n\n // warning(\n // false,\n // 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n // )\n throw match.loadPromise\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (router.isServer) {\n return (\n <RouteErrorComponent\n error={match.error}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n throw deserializeError(match.error.data)\n } else {\n throw match.error\n }\n }\n\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n\n if (pendingMinMs && !match.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n match.minPendingPromise = createControlledPromise()\n\n if (!router.isServer) {\n Promise.resolve().then(() => {\n router.__store.setState((s) => ({\n ...s,\n matches: s.matches.map((d) =>\n d.id === match.id\n ? { ...d, minPendingPromise: createControlledPromise() }\n : d,\n ),\n }))\n })\n\n setTimeout(() => {\n // We've handled the minPendingPromise, so we can delete it\n router.__store.setState((s) => {\n return {\n ...s,\n matches: s.matches.map((d) =>\n d.id === match.id\n ? {\n ...d,\n minPendingPromise:\n (d.minPendingPromise?.resolve(), undefined),\n }\n : d,\n ),\n }\n })\n }, pendingMinMs)\n }\n }\n\n throw match.loadPromise\n }\n\n const Comp = route.options.component ?? router.options.defaultComponent\n\n const out = Comp ? <Comp /> : <Outlet />\n\n return (\n <>\n {router.AfterEachMatch ? (\n <router.AfterEachMatch match={match} matchIndex={matchIndex} />\n ) : null}\n {out}\n </>\n )\n}\n\nexport const Outlet = React.memo(function Outlet() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const { parentGlobalNotFound } = useRouterState({\n select: (s) => {\n const matches = s.matches\n const parentMatch = matches.find((d) => d.id === matchId)\n invariant(\n parentMatch,\n `Could not find parent match for matchId \"${matchId}\"`,\n )\n return {\n parentGlobalNotFound: parentMatch.globalNotFound,\n }\n },\n })\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = s.matches\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (parentGlobalNotFound) {\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (matchId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"names":["matchIndex","match"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBgB;;AACd;AACA;AAA+B;;AACd;AAAyC;AAAA;AAG1D;AAAA;AACE;AAC8C;AAG1C;AAEN;AAGA;AAEA;AAGA;AAEA;AAAqC;AAAA;AAGK;AAGpC;AAAA;AAAA;AAOA;AAEA;AAIA;AAIN;AAAgC;AACU;AAIxC;AAEI;AAAC;AAAA;AACoB;AACoB;AAGjC;AACI;AACR;AAAsB;AACxB;AAEA;AAAC;AAAA;AAKK;AAIM;AAED;AAAwD;AACjE;AAE8B;AAAA;AAChC;AAAA;AAKV;AACA;;AACE;AACA;AAA+B;;AACd;AAAyC;AAAA;AAGpD;AAEN;AAA2C;AAEjCA;AACAC;AACC;AAAA;AACO;AACV;AACA;AACA;AACA;AACA;AACD;AACDD;AAAA;AAEJ;AAGF;AAII;AACE;AACA;AACF;AAGQ;AAAiC;AAEzC;AAAc;AAGN;AAEH;AAAwC;AAG7C;AAGF;AAMA;AAAY;AAGV;AAMF;AAEI;AAAA;AAAC;AAAA;AACc;AACP;AACY;AAClB;AAAA;AAAA;AAKF;AACF;AAEM;AAAiC;AAEvC;AAAY;AACd;AAGE;AAEF;AAGI;AAEF;AAEI;AACM;AACC;AAAyB;AAC3B;AACgB;AAGb;AACN;AACA;AAGJ;AAES;AACE;AAAA;AACF;AACgB;;AACjB;AACI;AACK;AAEgC;AAErC;AAAA;AACN;AAAA;AAEH;AACY;AACjB;AAGF;AAAY;AAGd;AAEA;AAEA;AAEK;AAEG;AACH;AAGP;AAEO;AACL;AACM;AACN;AAA+B;;AACd;AAAyC;AAAA;AAGpD;AAEA;AAA0C;AAE5C;AACA;AACA;AAAA;AACE;AACmD;AAE9C;AAAA;AAC6B;AAAA;AAEtC;AAGF;AAAoC;;AAEhC;AACA;AACO;AAAoB;AAC7B;AAGF;AACS;AAA4C;AAGrD;AACS;AAAA;AAGT;AAEM;AAIN;AACE;AACuD;AAIlD;AACT;;;"}
|
package/dist/cjs/Matches.cjs
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
|
-
const invariant = require("tiny-invariant");
|
|
6
5
|
const warning = require("tiny-warning");
|
|
7
6
|
const CatchBoundary = require("./CatchBoundary.cjs");
|
|
8
7
|
const useRouterState = require("./useRouterState.cjs");
|
|
9
8
|
const useRouter = require("./useRouter.cjs");
|
|
10
|
-
const utils = require("./utils.cjs");
|
|
11
|
-
const notFound = require("./not-found.cjs");
|
|
12
|
-
const redirects = require("./redirects.cjs");
|
|
13
9
|
const Transitioner = require("./Transitioner.cjs");
|
|
14
|
-
const
|
|
10
|
+
const matchContext = require("./matchContext.cjs");
|
|
11
|
+
const Match = require("./Match.cjs");
|
|
12
|
+
const SafeFragment = require("./SafeFragment.cjs");
|
|
15
13
|
function _interopNamespaceDefault(e) {
|
|
16
14
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
17
15
|
if (e) {
|
|
@@ -29,11 +27,10 @@ function _interopNamespaceDefault(e) {
|
|
|
29
27
|
return Object.freeze(n);
|
|
30
28
|
}
|
|
31
29
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
32
|
-
const matchContext = React__namespace.createContext(void 0);
|
|
33
30
|
function Matches() {
|
|
34
31
|
const router = useRouter.useRouter();
|
|
35
32
|
const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsxRuntime.jsx(router.options.defaultPendingComponent, {}) : null;
|
|
36
|
-
const ResolvedSuspense = !router.state.matches.length ? React__namespace.Suspense : SafeFragment;
|
|
33
|
+
const ResolvedSuspense = !router.state.matches.length ? React__namespace.Suspense : SafeFragment.SafeFragment;
|
|
37
34
|
const inner = /* @__PURE__ */ jsxRuntime.jsxs(ResolvedSuspense, { fallback: pendingElement, children: [
|
|
38
35
|
/* @__PURE__ */ jsxRuntime.jsx(Transitioner.Transitioner, {}),
|
|
39
36
|
/* @__PURE__ */ jsxRuntime.jsx(MatchesInner, {})
|
|
@@ -50,7 +47,7 @@ function MatchesInner() {
|
|
|
50
47
|
const resetKey = useRouterState.useRouterState({
|
|
51
48
|
select: (s) => s.resolvedLocation.state.key
|
|
52
49
|
});
|
|
53
|
-
return /* @__PURE__ */ jsxRuntime.jsx(matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
50
|
+
return /* @__PURE__ */ jsxRuntime.jsx(matchContext.matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
54
51
|
CatchBoundary.CatchBoundary,
|
|
55
52
|
{
|
|
56
53
|
getResetKey: () => resetKey,
|
|
@@ -62,226 +59,10 @@ function MatchesInner() {
|
|
|
62
59
|
);
|
|
63
60
|
warning(false, error.message || error.toString());
|
|
64
61
|
},
|
|
65
|
-
children: matchId ? /* @__PURE__ */ jsxRuntime.jsx(Match, { matchId }) : null
|
|
62
|
+
children: matchId ? /* @__PURE__ */ jsxRuntime.jsx(Match.Match, { matchId }) : null
|
|
66
63
|
}
|
|
67
64
|
) });
|
|
68
65
|
}
|
|
69
|
-
function SafeFragment(props) {
|
|
70
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.children });
|
|
71
|
-
}
|
|
72
|
-
function Match({ matchId }) {
|
|
73
|
-
var _a, _b;
|
|
74
|
-
const router = useRouter.useRouter();
|
|
75
|
-
const routeId = useRouterState.useRouterState({
|
|
76
|
-
select: (s) => {
|
|
77
|
-
var _a2;
|
|
78
|
-
return (_a2 = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a2.routeId;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
invariant(
|
|
82
|
-
routeId,
|
|
83
|
-
`Could not find routeId for matchId "${matchId}". Please file an issue!`
|
|
84
|
-
);
|
|
85
|
-
const route = router.routesById[routeId];
|
|
86
|
-
const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
|
|
87
|
-
const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntime.jsx(PendingComponent, {}) : null;
|
|
88
|
-
const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent;
|
|
89
|
-
const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch;
|
|
90
|
-
const routeNotFoundComponent = route.isRoot ? (
|
|
91
|
-
// If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
|
|
92
|
-
route.options.notFoundComponent ?? ((_a = router.options.notFoundRoute) == null ? void 0 : _a.options.component)
|
|
93
|
-
) : route.options.notFoundComponent;
|
|
94
|
-
const ResolvedSuspenseBoundary = (
|
|
95
|
-
// If we're on the root route, allow forcefully wrapping in suspense
|
|
96
|
-
(!route.isRoot || route.options.wrapInSuspense) && (route.options.wrapInSuspense ?? PendingComponent ?? ((_b = route.options.errorComponent) == null ? void 0 : _b.preload)) ? React__namespace.Suspense : SafeFragment
|
|
97
|
-
);
|
|
98
|
-
const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary.CatchBoundary : SafeFragment;
|
|
99
|
-
const ResolvedNotFoundBoundary = routeNotFoundComponent ? notFound.CatchNotFound : SafeFragment;
|
|
100
|
-
const resetKey = useRouterState.useRouterState({
|
|
101
|
-
select: (s) => s.resolvedLocation.state.key
|
|
102
|
-
});
|
|
103
|
-
return /* @__PURE__ */ jsxRuntime.jsx(matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsxRuntime.jsx(ResolvedSuspenseBoundary, { fallback: pendingElement, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
104
|
-
ResolvedCatchBoundary,
|
|
105
|
-
{
|
|
106
|
-
getResetKey: () => resetKey,
|
|
107
|
-
errorComponent: routeErrorComponent || CatchBoundary.ErrorComponent,
|
|
108
|
-
onCatch: (error, errorInfo) => {
|
|
109
|
-
if (notFound.isNotFound(error)) throw error;
|
|
110
|
-
warning(false, `Error in route match: ${matchId}`);
|
|
111
|
-
routeOnCatch == null ? void 0 : routeOnCatch(error, errorInfo);
|
|
112
|
-
},
|
|
113
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
114
|
-
ResolvedNotFoundBoundary,
|
|
115
|
-
{
|
|
116
|
-
fallback: (error) => {
|
|
117
|
-
if (!routeNotFoundComponent || error.routeId && error.routeId !== routeId || !error.routeId && !route.isRoot)
|
|
118
|
-
throw error;
|
|
119
|
-
return React__namespace.createElement(routeNotFoundComponent, error);
|
|
120
|
-
},
|
|
121
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(MatchInner, { matchId })
|
|
122
|
-
}
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
) }) });
|
|
126
|
-
}
|
|
127
|
-
function MatchInner({ matchId }) {
|
|
128
|
-
var _a, _b;
|
|
129
|
-
const router = useRouter.useRouter();
|
|
130
|
-
const routeId = useRouterState.useRouterState({
|
|
131
|
-
select: (s) => {
|
|
132
|
-
var _a2;
|
|
133
|
-
return (_a2 = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a2.routeId;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
const route = router.routesById[routeId];
|
|
137
|
-
const match = useRouterState.useRouterState({
|
|
138
|
-
select: (s) => utils.pick(s.matches.find((d) => d.id === matchId), [
|
|
139
|
-
"id",
|
|
140
|
-
"status",
|
|
141
|
-
"error",
|
|
142
|
-
"loadPromise",
|
|
143
|
-
"minPendingPromise"
|
|
144
|
-
])
|
|
145
|
-
});
|
|
146
|
-
const RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || CatchBoundary.ErrorComponent;
|
|
147
|
-
if (match.status === "notFound") {
|
|
148
|
-
let error;
|
|
149
|
-
if (isServerSideError(match.error)) {
|
|
150
|
-
const deserializeError = ((_a = router.options.errorSerializer) == null ? void 0 : _a.deserialize) ?? defaultDeserializeError;
|
|
151
|
-
error = deserializeError(match.error.data);
|
|
152
|
-
} else {
|
|
153
|
-
error = match.error;
|
|
154
|
-
}
|
|
155
|
-
invariant(notFound.isNotFound(error), "Expected a notFound error");
|
|
156
|
-
return renderRouteNotFound(router, route, error);
|
|
157
|
-
}
|
|
158
|
-
if (match.status === "redirected") {
|
|
159
|
-
invariant(redirects.isRedirect(match.error), "Expected a redirect error");
|
|
160
|
-
throw match.loadPromise;
|
|
161
|
-
}
|
|
162
|
-
if (match.status === "error") {
|
|
163
|
-
if (router.isServer) {
|
|
164
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
165
|
-
RouteErrorComponent,
|
|
166
|
-
{
|
|
167
|
-
error: match.error,
|
|
168
|
-
info: {
|
|
169
|
-
componentStack: ""
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
if (isServerSideError(match.error)) {
|
|
175
|
-
const deserializeError = ((_b = router.options.errorSerializer) == null ? void 0 : _b.deserialize) ?? defaultDeserializeError;
|
|
176
|
-
throw deserializeError(match.error.data);
|
|
177
|
-
} else {
|
|
178
|
-
throw match.error;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (match.status === "pending") {
|
|
182
|
-
const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
|
|
183
|
-
if (pendingMinMs && !match.minPendingPromise) {
|
|
184
|
-
match.minPendingPromise = utils.createControlledPromise();
|
|
185
|
-
if (!router.isServer) {
|
|
186
|
-
Promise.resolve().then(() => {
|
|
187
|
-
router.__store.setState((s) => ({
|
|
188
|
-
...s,
|
|
189
|
-
matches: s.matches.map(
|
|
190
|
-
(d) => d.id === match.id ? { ...d, minPendingPromise: utils.createControlledPromise() } : d
|
|
191
|
-
)
|
|
192
|
-
}));
|
|
193
|
-
});
|
|
194
|
-
setTimeout(() => {
|
|
195
|
-
router.__store.setState((s) => {
|
|
196
|
-
return {
|
|
197
|
-
...s,
|
|
198
|
-
matches: s.matches.map(
|
|
199
|
-
(d) => {
|
|
200
|
-
var _a2;
|
|
201
|
-
return d.id === match.id ? {
|
|
202
|
-
...d,
|
|
203
|
-
minPendingPromise: ((_a2 = d.minPendingPromise) == null ? void 0 : _a2.resolve(), void 0)
|
|
204
|
-
} : d;
|
|
205
|
-
}
|
|
206
|
-
)
|
|
207
|
-
};
|
|
208
|
-
});
|
|
209
|
-
}, pendingMinMs);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
throw match.loadPromise;
|
|
213
|
-
}
|
|
214
|
-
if (match.status === "success") {
|
|
215
|
-
const Comp = route.options.component ?? router.options.defaultComponent;
|
|
216
|
-
if (Comp) {
|
|
217
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Comp, {});
|
|
218
|
-
}
|
|
219
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Outlet, {});
|
|
220
|
-
}
|
|
221
|
-
invariant(
|
|
222
|
-
false,
|
|
223
|
-
"Idle routeMatch status encountered during rendering! You should never see this. File an issue!"
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
const Outlet = React__namespace.memo(function Outlet2() {
|
|
227
|
-
const router = useRouter.useRouter();
|
|
228
|
-
const matchId = React__namespace.useContext(matchContext);
|
|
229
|
-
const routeId = useRouterState.useRouterState({
|
|
230
|
-
select: (s) => {
|
|
231
|
-
var _a;
|
|
232
|
-
return (_a = s.matches.find((d) => d.id === matchId)) == null ? void 0 : _a.routeId;
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
const route = router.routesById[routeId];
|
|
236
|
-
const { parentGlobalNotFound } = useRouterState.useRouterState({
|
|
237
|
-
select: (s) => {
|
|
238
|
-
const matches = s.matches;
|
|
239
|
-
const parentMatch = matches.find((d) => d.id === matchId);
|
|
240
|
-
invariant(
|
|
241
|
-
parentMatch,
|
|
242
|
-
`Could not find parent match for matchId "${matchId}"`
|
|
243
|
-
);
|
|
244
|
-
return {
|
|
245
|
-
parentGlobalNotFound: parentMatch.globalNotFound
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
const childMatchId = useRouterState.useRouterState({
|
|
250
|
-
select: (s) => {
|
|
251
|
-
var _a;
|
|
252
|
-
const matches = s.matches;
|
|
253
|
-
const index = matches.findIndex((d) => d.id === matchId);
|
|
254
|
-
return (_a = matches[index + 1]) == null ? void 0 : _a.id;
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
if (parentGlobalNotFound) {
|
|
258
|
-
return renderRouteNotFound(router, route, void 0);
|
|
259
|
-
}
|
|
260
|
-
if (!childMatchId) {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
const nextMatch = /* @__PURE__ */ jsxRuntime.jsx(Match, { matchId: childMatchId });
|
|
264
|
-
const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsxRuntime.jsx(router.options.defaultPendingComponent, {}) : null;
|
|
265
|
-
if (matchId === root.rootRouteId) {
|
|
266
|
-
return /* @__PURE__ */ jsxRuntime.jsx(React__namespace.Suspense, { fallback: pendingElement, children: nextMatch });
|
|
267
|
-
}
|
|
268
|
-
return nextMatch;
|
|
269
|
-
});
|
|
270
|
-
function renderRouteNotFound(router, route, data) {
|
|
271
|
-
if (!route.options.notFoundComponent) {
|
|
272
|
-
if (router.options.defaultNotFoundComponent) {
|
|
273
|
-
return /* @__PURE__ */ jsxRuntime.jsx(router.options.defaultNotFoundComponent, { data });
|
|
274
|
-
}
|
|
275
|
-
if (process.env.NODE_ENV === "development") {
|
|
276
|
-
warning(
|
|
277
|
-
route.options.notFoundComponent,
|
|
278
|
-
`A notFoundError was encountered on the route with ID "${route.id}", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)`
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
return /* @__PURE__ */ jsxRuntime.jsx(notFound.DefaultGlobalNotFound, {});
|
|
282
|
-
}
|
|
283
|
-
return /* @__PURE__ */ jsxRuntime.jsx(route.options.notFoundComponent, { data });
|
|
284
|
-
}
|
|
285
66
|
function useMatchRoute() {
|
|
286
67
|
const router = useRouter.useRouter();
|
|
287
68
|
return React__namespace.useCallback(
|
|
@@ -314,7 +95,7 @@ function useMatches(opts) {
|
|
|
314
95
|
});
|
|
315
96
|
}
|
|
316
97
|
function useParentMatches(opts) {
|
|
317
|
-
const contextMatchId = React__namespace.useContext(matchContext);
|
|
98
|
+
const contextMatchId = React__namespace.useContext(matchContext.matchContext);
|
|
318
99
|
return useMatches({
|
|
319
100
|
select: (matches) => {
|
|
320
101
|
matches = matches.slice(
|
|
@@ -326,7 +107,7 @@ function useParentMatches(opts) {
|
|
|
326
107
|
});
|
|
327
108
|
}
|
|
328
109
|
function useChildMatches(opts) {
|
|
329
|
-
const contextMatchId = React__namespace.useContext(matchContext);
|
|
110
|
+
const contextMatchId = React__namespace.useContext(matchContext.matchContext);
|
|
330
111
|
return useMatches({
|
|
331
112
|
select: (matches) => {
|
|
332
113
|
matches = matches.slice(
|
|
@@ -336,30 +117,8 @@ function useChildMatches(opts) {
|
|
|
336
117
|
}
|
|
337
118
|
});
|
|
338
119
|
}
|
|
339
|
-
function isServerSideError(error) {
|
|
340
|
-
if (!(typeof error === "object" && error && "data" in error)) return false;
|
|
341
|
-
if (!("__isServerError" in error && error.__isServerError)) return false;
|
|
342
|
-
if (!(typeof error.data === "object" && error.data)) return false;
|
|
343
|
-
return error.__isServerError === true;
|
|
344
|
-
}
|
|
345
|
-
function defaultDeserializeError(serializedData) {
|
|
346
|
-
if ("name" in serializedData && "message" in serializedData) {
|
|
347
|
-
const error = new Error(serializedData.message);
|
|
348
|
-
error.name = serializedData.name;
|
|
349
|
-
if (process.env.NODE_ENV === "development") {
|
|
350
|
-
error.stack = serializedData.stack;
|
|
351
|
-
}
|
|
352
|
-
return error;
|
|
353
|
-
}
|
|
354
|
-
return serializedData.data;
|
|
355
|
-
}
|
|
356
|
-
exports.Match = Match;
|
|
357
120
|
exports.MatchRoute = MatchRoute;
|
|
358
121
|
exports.Matches = Matches;
|
|
359
|
-
exports.Outlet = Outlet;
|
|
360
|
-
exports.defaultDeserializeError = defaultDeserializeError;
|
|
361
|
-
exports.isServerSideError = isServerSideError;
|
|
362
|
-
exports.matchContext = matchContext;
|
|
363
122
|
exports.useChildMatches = useChildMatches;
|
|
364
123
|
exports.useMatchRoute = useMatchRoute;
|
|
365
124
|
exports.useMatches = useMatches;
|