react-router 0.0.0-experimental-e16afd9b7 → 0.0.0-experimental-52e9b8eb3
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/CHANGELOG.md +8 -0
- package/README.md +10 -1
- package/dist/index.d.ts +16 -33
- package/dist/index.js +1114 -9501
- package/dist/index.js.map +1 -1
- package/dist/lib/components.d.ts +19 -189
- package/dist/lib/context.d.ts +4 -4
- package/dist/lib/hooks.d.ts +17 -46
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +1152 -10370
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router.development.js +1259 -10541
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +4 -19
- package/dist/lib/dom/dom.d.ts +0 -104
- package/dist/lib/dom/global.d.ts +0 -38
- package/dist/lib/dom/lib.d.ts +0 -572
- package/dist/lib/dom/server.d.ts +0 -32
- package/dist/lib/dom/ssr/browser.d.ts +0 -3
- package/dist/lib/dom/ssr/components.d.ts +0 -94
- package/dist/lib/dom/ssr/create-remix-stub.d.ts +0 -56
- package/dist/lib/dom/ssr/data.d.ts +0 -7
- package/dist/lib/dom/ssr/errorBoundaries.d.ts +0 -33
- package/dist/lib/dom/ssr/errors.d.ts +0 -2
- package/dist/lib/dom/ssr/fallback.d.ts +0 -2
- package/dist/lib/dom/ssr/invariant.d.ts +0 -2
- package/dist/lib/dom/ssr/links.d.ts +0 -126
- package/dist/lib/dom/ssr/markup.d.ts +0 -5
- package/dist/lib/dom/ssr/routeModules.d.ts +0 -141
- package/dist/lib/dom/ssr/routes.d.ts +0 -32
- package/dist/lib/dom/ssr/server.d.ts +0 -13
- package/dist/lib/dom/ssr/single-fetch.d.ts +0 -37
- package/dist/lib/router/history.d.ts +0 -249
- package/dist/lib/router/index.d.ts +0 -9
- package/dist/lib/router/router.d.ts +0 -521
- package/dist/lib/router/utils.d.ts +0 -520
- package/dist/rsc.js +0 -1641
package/dist/rsc.js
DELETED
|
@@ -1,1641 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/react-router/rsc.ts
|
|
31
|
-
var rsc_exports = {};
|
|
32
|
-
__export(rsc_exports, {
|
|
33
|
-
UNSAFE_DEFERRED_SYMBOL: () => UNSAFE_DEFERRED_SYMBOL,
|
|
34
|
-
UNSAFE_ErrorResponseImpl: () => ErrorResponseImpl,
|
|
35
|
-
UNSAFE_SingleFetchRedirectSymbol: () => SingleFetchRedirectSymbol,
|
|
36
|
-
createStaticHandler: () => createStaticHandler2,
|
|
37
|
-
defer: () => defer,
|
|
38
|
-
getStaticContextFromError: () => getStaticContextFromError,
|
|
39
|
-
isRouteErrorResponse: () => isRouteErrorResponse,
|
|
40
|
-
json: () => json,
|
|
41
|
-
matchRoutes: () => matchRoutes,
|
|
42
|
-
redirect: () => redirect,
|
|
43
|
-
redirectDocument: () => redirectDocument,
|
|
44
|
-
stripBasename: () => stripBasename
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(rsc_exports);
|
|
47
|
-
|
|
48
|
-
// packages/react-router/lib/router/history.ts
|
|
49
|
-
function invariant(value, message) {
|
|
50
|
-
if (value === false || value === null || typeof value === "undefined") {
|
|
51
|
-
throw new Error(message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function warning(cond, message) {
|
|
55
|
-
if (!cond) {
|
|
56
|
-
if (typeof console !== "undefined") console.warn(message);
|
|
57
|
-
try {
|
|
58
|
-
throw new Error(message);
|
|
59
|
-
} catch (e) {
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function createKey() {
|
|
64
|
-
return Math.random().toString(36).substr(2, 8);
|
|
65
|
-
}
|
|
66
|
-
function createLocation(current, to, state = null, key) {
|
|
67
|
-
let location = {
|
|
68
|
-
pathname: typeof current === "string" ? current : current.pathname,
|
|
69
|
-
search: "",
|
|
70
|
-
hash: "",
|
|
71
|
-
...typeof to === "string" ? parsePath(to) : to,
|
|
72
|
-
state,
|
|
73
|
-
// TODO: This could be cleaned up. push/replace should probably just take
|
|
74
|
-
// full Locations now and avoid the need to run through this flow at all
|
|
75
|
-
// But that's a pretty big refactor to the current test suite so going to
|
|
76
|
-
// keep as is for the time being and just let any incoming keys take precedence
|
|
77
|
-
key: to && to.key || key || createKey()
|
|
78
|
-
};
|
|
79
|
-
return location;
|
|
80
|
-
}
|
|
81
|
-
function createPath({
|
|
82
|
-
pathname = "/",
|
|
83
|
-
search = "",
|
|
84
|
-
hash = ""
|
|
85
|
-
}) {
|
|
86
|
-
if (search && search !== "?")
|
|
87
|
-
pathname += search.charAt(0) === "?" ? search : "?" + search;
|
|
88
|
-
if (hash && hash !== "#")
|
|
89
|
-
pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
|
|
90
|
-
return pathname;
|
|
91
|
-
}
|
|
92
|
-
function parsePath(path) {
|
|
93
|
-
let parsedPath = {};
|
|
94
|
-
if (path) {
|
|
95
|
-
let hashIndex = path.indexOf("#");
|
|
96
|
-
if (hashIndex >= 0) {
|
|
97
|
-
parsedPath.hash = path.substr(hashIndex);
|
|
98
|
-
path = path.substr(0, hashIndex);
|
|
99
|
-
}
|
|
100
|
-
let searchIndex = path.indexOf("?");
|
|
101
|
-
if (searchIndex >= 0) {
|
|
102
|
-
parsedPath.search = path.substr(searchIndex);
|
|
103
|
-
path = path.substr(0, searchIndex);
|
|
104
|
-
}
|
|
105
|
-
if (path) {
|
|
106
|
-
parsedPath.pathname = path;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return parsedPath;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// packages/react-router/lib/router/utils.ts
|
|
113
|
-
var immutableRouteKeys = /* @__PURE__ */ new Set([
|
|
114
|
-
"lazy",
|
|
115
|
-
"caseSensitive",
|
|
116
|
-
"path",
|
|
117
|
-
"id",
|
|
118
|
-
"index",
|
|
119
|
-
"children"
|
|
120
|
-
]);
|
|
121
|
-
function isIndexRoute(route) {
|
|
122
|
-
return route.index === true;
|
|
123
|
-
}
|
|
124
|
-
function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [], manifest = {}) {
|
|
125
|
-
return routes.map((route, index) => {
|
|
126
|
-
let treePath = [...parentPath, index];
|
|
127
|
-
let id = typeof route.id === "string" ? route.id : treePath.join("-");
|
|
128
|
-
invariant(
|
|
129
|
-
route.index !== true || !route.children,
|
|
130
|
-
`Cannot specify children on an index route`
|
|
131
|
-
);
|
|
132
|
-
invariant(
|
|
133
|
-
!manifest[id],
|
|
134
|
-
`Found a route id collision on id "${id}". Route id's must be globally unique within Data Router usages`
|
|
135
|
-
);
|
|
136
|
-
if (isIndexRoute(route)) {
|
|
137
|
-
let indexRoute = {
|
|
138
|
-
...route,
|
|
139
|
-
...mapRouteProperties2(route),
|
|
140
|
-
id
|
|
141
|
-
};
|
|
142
|
-
manifest[id] = indexRoute;
|
|
143
|
-
return indexRoute;
|
|
144
|
-
} else {
|
|
145
|
-
let pathOrLayoutRoute = {
|
|
146
|
-
...route,
|
|
147
|
-
...mapRouteProperties2(route),
|
|
148
|
-
id,
|
|
149
|
-
children: void 0
|
|
150
|
-
};
|
|
151
|
-
manifest[id] = pathOrLayoutRoute;
|
|
152
|
-
if (route.children) {
|
|
153
|
-
pathOrLayoutRoute.children = convertRoutesToDataRoutes(
|
|
154
|
-
route.children,
|
|
155
|
-
mapRouteProperties2,
|
|
156
|
-
treePath,
|
|
157
|
-
manifest
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
return pathOrLayoutRoute;
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
function matchRoutes(routes, locationArg, basename = "/") {
|
|
165
|
-
let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
|
166
|
-
let pathname = stripBasename(location.pathname || "/", basename);
|
|
167
|
-
if (pathname == null) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
let branches = flattenRoutes(routes);
|
|
171
|
-
rankRouteBranches(branches);
|
|
172
|
-
let matches = null;
|
|
173
|
-
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
174
|
-
let decoded = decodePath(pathname);
|
|
175
|
-
matches = matchRouteBranch(branches[i], decoded);
|
|
176
|
-
}
|
|
177
|
-
return matches;
|
|
178
|
-
}
|
|
179
|
-
function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "") {
|
|
180
|
-
let flattenRoute = (route, index, relativePath) => {
|
|
181
|
-
let meta = {
|
|
182
|
-
relativePath: relativePath === void 0 ? route.path || "" : relativePath,
|
|
183
|
-
caseSensitive: route.caseSensitive === true,
|
|
184
|
-
childrenIndex: index,
|
|
185
|
-
route
|
|
186
|
-
};
|
|
187
|
-
if (meta.relativePath.startsWith("/")) {
|
|
188
|
-
invariant(
|
|
189
|
-
meta.relativePath.startsWith(parentPath),
|
|
190
|
-
`Absolute route path "${meta.relativePath}" nested under path "${parentPath}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
|
|
191
|
-
);
|
|
192
|
-
meta.relativePath = meta.relativePath.slice(parentPath.length);
|
|
193
|
-
}
|
|
194
|
-
let path = joinPaths([parentPath, meta.relativePath]);
|
|
195
|
-
let routesMeta = parentsMeta.concat(meta);
|
|
196
|
-
if (route.children && route.children.length > 0) {
|
|
197
|
-
invariant(
|
|
198
|
-
// Our types know better, but runtime JS may not!
|
|
199
|
-
// @ts-expect-error
|
|
200
|
-
route.index !== true,
|
|
201
|
-
`Index routes must not have child routes. Please remove all child routes from route path "${path}".`
|
|
202
|
-
);
|
|
203
|
-
flattenRoutes(route.children, branches, routesMeta, path);
|
|
204
|
-
}
|
|
205
|
-
if (route.path == null && !route.index) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
branches.push({
|
|
209
|
-
path,
|
|
210
|
-
score: computeScore(path, route.index),
|
|
211
|
-
routesMeta
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
routes.forEach((route, index) => {
|
|
215
|
-
if (route.path === "" || !route.path?.includes("?")) {
|
|
216
|
-
flattenRoute(route, index);
|
|
217
|
-
} else {
|
|
218
|
-
for (let exploded of explodeOptionalSegments(route.path)) {
|
|
219
|
-
flattenRoute(route, index, exploded);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
return branches;
|
|
224
|
-
}
|
|
225
|
-
function explodeOptionalSegments(path) {
|
|
226
|
-
let segments = path.split("/");
|
|
227
|
-
if (segments.length === 0) return [];
|
|
228
|
-
let [first, ...rest] = segments;
|
|
229
|
-
let isOptional = first.endsWith("?");
|
|
230
|
-
let required = first.replace(/\?$/, "");
|
|
231
|
-
if (rest.length === 0) {
|
|
232
|
-
return isOptional ? [required, ""] : [required];
|
|
233
|
-
}
|
|
234
|
-
let restExploded = explodeOptionalSegments(rest.join("/"));
|
|
235
|
-
let result = [];
|
|
236
|
-
result.push(
|
|
237
|
-
...restExploded.map(
|
|
238
|
-
(subpath) => subpath === "" ? required : [required, subpath].join("/")
|
|
239
|
-
)
|
|
240
|
-
);
|
|
241
|
-
if (isOptional) {
|
|
242
|
-
result.push(...restExploded);
|
|
243
|
-
}
|
|
244
|
-
return result.map(
|
|
245
|
-
(exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
function rankRouteBranches(branches) {
|
|
249
|
-
branches.sort(
|
|
250
|
-
(a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(
|
|
251
|
-
a.routesMeta.map((meta) => meta.childrenIndex),
|
|
252
|
-
b.routesMeta.map((meta) => meta.childrenIndex)
|
|
253
|
-
)
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
var paramRe = /^:[\w-]+$/;
|
|
257
|
-
var dynamicSegmentValue = 3;
|
|
258
|
-
var indexRouteValue = 2;
|
|
259
|
-
var emptySegmentValue = 1;
|
|
260
|
-
var staticSegmentValue = 10;
|
|
261
|
-
var splatPenalty = -2;
|
|
262
|
-
var isSplat = (s) => s === "*";
|
|
263
|
-
function computeScore(path, index) {
|
|
264
|
-
let segments = path.split("/");
|
|
265
|
-
let initialScore = segments.length;
|
|
266
|
-
if (segments.some(isSplat)) {
|
|
267
|
-
initialScore += splatPenalty;
|
|
268
|
-
}
|
|
269
|
-
if (index) {
|
|
270
|
-
initialScore += indexRouteValue;
|
|
271
|
-
}
|
|
272
|
-
return segments.filter((s) => !isSplat(s)).reduce(
|
|
273
|
-
(score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue),
|
|
274
|
-
initialScore
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
function compareIndexes(a, b) {
|
|
278
|
-
let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
|
|
279
|
-
return siblings ? (
|
|
280
|
-
// If two routes are siblings, we should try to match the earlier sibling
|
|
281
|
-
// first. This allows people to have fine-grained control over the matching
|
|
282
|
-
// behavior by simply putting routes with identical paths in the order they
|
|
283
|
-
// want them tried.
|
|
284
|
-
a[a.length - 1] - b[b.length - 1]
|
|
285
|
-
) : (
|
|
286
|
-
// Otherwise, it doesn't really make sense to rank non-siblings by index,
|
|
287
|
-
// so they sort equally.
|
|
288
|
-
0
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
function matchRouteBranch(branch, pathname) {
|
|
292
|
-
let { routesMeta } = branch;
|
|
293
|
-
let matchedParams = {};
|
|
294
|
-
let matchedPathname = "/";
|
|
295
|
-
let matches = [];
|
|
296
|
-
for (let i = 0; i < routesMeta.length; ++i) {
|
|
297
|
-
let meta = routesMeta[i];
|
|
298
|
-
let end = i === routesMeta.length - 1;
|
|
299
|
-
let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
|
|
300
|
-
let match = matchPath(
|
|
301
|
-
{ path: meta.relativePath, caseSensitive: meta.caseSensitive, end },
|
|
302
|
-
remainingPathname
|
|
303
|
-
);
|
|
304
|
-
if (!match) return null;
|
|
305
|
-
Object.assign(matchedParams, match.params);
|
|
306
|
-
let route = meta.route;
|
|
307
|
-
matches.push({
|
|
308
|
-
// TODO: Can this as be avoided?
|
|
309
|
-
params: matchedParams,
|
|
310
|
-
pathname: joinPaths([matchedPathname, match.pathname]),
|
|
311
|
-
pathnameBase: normalizePathname(
|
|
312
|
-
joinPaths([matchedPathname, match.pathnameBase])
|
|
313
|
-
),
|
|
314
|
-
route
|
|
315
|
-
});
|
|
316
|
-
if (match.pathnameBase !== "/") {
|
|
317
|
-
matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return matches;
|
|
321
|
-
}
|
|
322
|
-
function matchPath(pattern, pathname) {
|
|
323
|
-
if (typeof pattern === "string") {
|
|
324
|
-
pattern = { path: pattern, caseSensitive: false, end: true };
|
|
325
|
-
}
|
|
326
|
-
let [matcher, compiledParams] = compilePath(
|
|
327
|
-
pattern.path,
|
|
328
|
-
pattern.caseSensitive,
|
|
329
|
-
pattern.end
|
|
330
|
-
);
|
|
331
|
-
let match = pathname.match(matcher);
|
|
332
|
-
if (!match) return null;
|
|
333
|
-
let matchedPathname = match[0];
|
|
334
|
-
let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
|
|
335
|
-
let captureGroups = match.slice(1);
|
|
336
|
-
let params = compiledParams.reduce(
|
|
337
|
-
(memo, { paramName, isOptional }, index) => {
|
|
338
|
-
if (paramName === "*") {
|
|
339
|
-
let splatValue = captureGroups[index] || "";
|
|
340
|
-
pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
|
|
341
|
-
}
|
|
342
|
-
const value = captureGroups[index];
|
|
343
|
-
if (isOptional && !value) {
|
|
344
|
-
memo[paramName] = void 0;
|
|
345
|
-
} else {
|
|
346
|
-
memo[paramName] = (value || "").replace(/%2F/g, "/");
|
|
347
|
-
}
|
|
348
|
-
return memo;
|
|
349
|
-
},
|
|
350
|
-
{}
|
|
351
|
-
);
|
|
352
|
-
return {
|
|
353
|
-
params,
|
|
354
|
-
pathname: matchedPathname,
|
|
355
|
-
pathnameBase,
|
|
356
|
-
pattern
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
function compilePath(path, caseSensitive = false, end = true) {
|
|
360
|
-
warning(
|
|
361
|
-
path === "*" || !path.endsWith("*") || path.endsWith("/*"),
|
|
362
|
-
`Route path "${path}" will be treated as if it were "${path.replace(/\*$/, "/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${path.replace(/\*$/, "/*")}".`
|
|
363
|
-
);
|
|
364
|
-
let params = [];
|
|
365
|
-
let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
|
|
366
|
-
/\/:([\w-]+)(\?)?/g,
|
|
367
|
-
(_, paramName, isOptional) => {
|
|
368
|
-
params.push({ paramName, isOptional: isOptional != null });
|
|
369
|
-
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
|
370
|
-
}
|
|
371
|
-
);
|
|
372
|
-
if (path.endsWith("*")) {
|
|
373
|
-
params.push({ paramName: "*" });
|
|
374
|
-
regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
|
|
375
|
-
} else if (end) {
|
|
376
|
-
regexpSource += "\\/*$";
|
|
377
|
-
} else if (path !== "" && path !== "/") {
|
|
378
|
-
regexpSource += "(?:(?=\\/|$))";
|
|
379
|
-
} else {
|
|
380
|
-
}
|
|
381
|
-
let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
|
|
382
|
-
return [matcher, params];
|
|
383
|
-
}
|
|
384
|
-
function decodePath(value) {
|
|
385
|
-
try {
|
|
386
|
-
return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
|
|
387
|
-
} catch (error) {
|
|
388
|
-
warning(
|
|
389
|
-
false,
|
|
390
|
-
`The URL path "${value}" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent encoding (${error}).`
|
|
391
|
-
);
|
|
392
|
-
return value;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
function stripBasename(pathname, basename) {
|
|
396
|
-
if (basename === "/") return pathname;
|
|
397
|
-
if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
|
|
398
|
-
return null;
|
|
399
|
-
}
|
|
400
|
-
let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
|
|
401
|
-
let nextChar = pathname.charAt(startIndex);
|
|
402
|
-
if (nextChar && nextChar !== "/") {
|
|
403
|
-
return null;
|
|
404
|
-
}
|
|
405
|
-
return pathname.slice(startIndex) || "/";
|
|
406
|
-
}
|
|
407
|
-
function resolvePath(to, fromPathname = "/") {
|
|
408
|
-
let {
|
|
409
|
-
pathname: toPathname,
|
|
410
|
-
search = "",
|
|
411
|
-
hash = ""
|
|
412
|
-
} = typeof to === "string" ? parsePath(to) : to;
|
|
413
|
-
let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
|
|
414
|
-
return {
|
|
415
|
-
pathname,
|
|
416
|
-
search: normalizeSearch(search),
|
|
417
|
-
hash: normalizeHash(hash)
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
function resolvePathname(relativePath, fromPathname) {
|
|
421
|
-
let segments = fromPathname.replace(/\/+$/, "").split("/");
|
|
422
|
-
let relativeSegments = relativePath.split("/");
|
|
423
|
-
relativeSegments.forEach((segment) => {
|
|
424
|
-
if (segment === "..") {
|
|
425
|
-
if (segments.length > 1) segments.pop();
|
|
426
|
-
} else if (segment !== ".") {
|
|
427
|
-
segments.push(segment);
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
return segments.length > 1 ? segments.join("/") : "/";
|
|
431
|
-
}
|
|
432
|
-
function getInvalidPathError(char, field, dest, path) {
|
|
433
|
-
return `Cannot include a '${char}' character in a manually specified \`to.${field}\` field [${JSON.stringify(
|
|
434
|
-
path
|
|
435
|
-
)}]. Please separate it out to the \`to.${dest}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`;
|
|
436
|
-
}
|
|
437
|
-
function getPathContributingMatches(matches) {
|
|
438
|
-
return matches.filter(
|
|
439
|
-
(match, index) => index === 0 || match.route.path && match.route.path.length > 0
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
function getResolveToMatches(matches, v7_relativeSplatPath) {
|
|
443
|
-
let pathMatches = getPathContributingMatches(matches);
|
|
444
|
-
if (v7_relativeSplatPath) {
|
|
445
|
-
return pathMatches.map(
|
|
446
|
-
(match, idx) => idx === matches.length - 1 ? match.pathname : match.pathnameBase
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
return pathMatches.map((match) => match.pathnameBase);
|
|
450
|
-
}
|
|
451
|
-
function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = false) {
|
|
452
|
-
let to;
|
|
453
|
-
if (typeof toArg === "string") {
|
|
454
|
-
to = parsePath(toArg);
|
|
455
|
-
} else {
|
|
456
|
-
to = { ...toArg };
|
|
457
|
-
invariant(
|
|
458
|
-
!to.pathname || !to.pathname.includes("?"),
|
|
459
|
-
getInvalidPathError("?", "pathname", "search", to)
|
|
460
|
-
);
|
|
461
|
-
invariant(
|
|
462
|
-
!to.pathname || !to.pathname.includes("#"),
|
|
463
|
-
getInvalidPathError("#", "pathname", "hash", to)
|
|
464
|
-
);
|
|
465
|
-
invariant(
|
|
466
|
-
!to.search || !to.search.includes("#"),
|
|
467
|
-
getInvalidPathError("#", "search", "hash", to)
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
let isEmptyPath = toArg === "" || to.pathname === "";
|
|
471
|
-
let toPathname = isEmptyPath ? "/" : to.pathname;
|
|
472
|
-
let from;
|
|
473
|
-
if (toPathname == null) {
|
|
474
|
-
from = locationPathname;
|
|
475
|
-
} else {
|
|
476
|
-
let routePathnameIndex = routePathnames.length - 1;
|
|
477
|
-
if (!isPathRelative && toPathname.startsWith("..")) {
|
|
478
|
-
let toSegments = toPathname.split("/");
|
|
479
|
-
while (toSegments[0] === "..") {
|
|
480
|
-
toSegments.shift();
|
|
481
|
-
routePathnameIndex -= 1;
|
|
482
|
-
}
|
|
483
|
-
to.pathname = toSegments.join("/");
|
|
484
|
-
}
|
|
485
|
-
from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
|
486
|
-
}
|
|
487
|
-
let path = resolvePath(to, from);
|
|
488
|
-
let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
|
|
489
|
-
let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
|
|
490
|
-
if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
|
|
491
|
-
path.pathname += "/";
|
|
492
|
-
}
|
|
493
|
-
return path;
|
|
494
|
-
}
|
|
495
|
-
var joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
|
|
496
|
-
var normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
|
|
497
|
-
var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
|
|
498
|
-
var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
|
|
499
|
-
var json = (data, init = {}) => {
|
|
500
|
-
let responseInit = typeof init === "number" ? { status: init } : init;
|
|
501
|
-
let headers = new Headers(responseInit.headers);
|
|
502
|
-
if (!headers.has("Content-Type")) {
|
|
503
|
-
headers.set("Content-Type", "application/json; charset=utf-8");
|
|
504
|
-
}
|
|
505
|
-
return new Response(JSON.stringify(data), {
|
|
506
|
-
...responseInit,
|
|
507
|
-
headers
|
|
508
|
-
});
|
|
509
|
-
};
|
|
510
|
-
var AbortedDeferredError = class extends Error {
|
|
511
|
-
};
|
|
512
|
-
var DeferredData = class {
|
|
513
|
-
constructor(data, responseInit) {
|
|
514
|
-
this.pendingKeysSet = /* @__PURE__ */ new Set();
|
|
515
|
-
this.subscribers = /* @__PURE__ */ new Set();
|
|
516
|
-
this.deferredKeys = [];
|
|
517
|
-
invariant(
|
|
518
|
-
data && typeof data === "object" && !Array.isArray(data),
|
|
519
|
-
"defer() only accepts plain objects"
|
|
520
|
-
);
|
|
521
|
-
let reject;
|
|
522
|
-
this.abortPromise = new Promise((_, r) => reject = r);
|
|
523
|
-
this.controller = new AbortController();
|
|
524
|
-
let onAbort = () => reject(new AbortedDeferredError("Deferred data aborted"));
|
|
525
|
-
this.unlistenAbortSignal = () => this.controller.signal.removeEventListener("abort", onAbort);
|
|
526
|
-
this.controller.signal.addEventListener("abort", onAbort);
|
|
527
|
-
this.data = Object.entries(data).reduce(
|
|
528
|
-
(acc, [key, value]) => Object.assign(acc, {
|
|
529
|
-
[key]: this.trackPromise(key, value)
|
|
530
|
-
}),
|
|
531
|
-
{}
|
|
532
|
-
);
|
|
533
|
-
if (this.done) {
|
|
534
|
-
this.unlistenAbortSignal();
|
|
535
|
-
}
|
|
536
|
-
this.init = responseInit;
|
|
537
|
-
}
|
|
538
|
-
trackPromise(key, value) {
|
|
539
|
-
if (!(value instanceof Promise)) {
|
|
540
|
-
return value;
|
|
541
|
-
}
|
|
542
|
-
this.deferredKeys.push(key);
|
|
543
|
-
this.pendingKeysSet.add(key);
|
|
544
|
-
let promise = Promise.race([value, this.abortPromise]).then(
|
|
545
|
-
(data) => this.onSettle(promise, key, void 0, data),
|
|
546
|
-
(error) => this.onSettle(promise, key, error)
|
|
547
|
-
);
|
|
548
|
-
promise.catch(() => {
|
|
549
|
-
});
|
|
550
|
-
Object.defineProperty(promise, "_tracked", { get: () => true });
|
|
551
|
-
return promise;
|
|
552
|
-
}
|
|
553
|
-
onSettle(promise, key, error, data) {
|
|
554
|
-
if (this.controller.signal.aborted && error instanceof AbortedDeferredError) {
|
|
555
|
-
this.unlistenAbortSignal();
|
|
556
|
-
Object.defineProperty(promise, "_error", { get: () => error });
|
|
557
|
-
return Promise.reject(error);
|
|
558
|
-
}
|
|
559
|
-
this.pendingKeysSet.delete(key);
|
|
560
|
-
if (this.done) {
|
|
561
|
-
this.unlistenAbortSignal();
|
|
562
|
-
}
|
|
563
|
-
if (error === void 0 && data === void 0) {
|
|
564
|
-
let undefinedError = new Error(
|
|
565
|
-
`Deferred data for key "${key}" resolved/rejected with \`undefined\`, you must resolve/reject with a value or \`null\`.`
|
|
566
|
-
);
|
|
567
|
-
Object.defineProperty(promise, "_error", { get: () => undefinedError });
|
|
568
|
-
this.emit(false, key);
|
|
569
|
-
return Promise.reject(undefinedError);
|
|
570
|
-
}
|
|
571
|
-
if (data === void 0) {
|
|
572
|
-
Object.defineProperty(promise, "_error", { get: () => error });
|
|
573
|
-
this.emit(false, key);
|
|
574
|
-
return Promise.reject(error);
|
|
575
|
-
}
|
|
576
|
-
Object.defineProperty(promise, "_data", { get: () => data });
|
|
577
|
-
this.emit(false, key);
|
|
578
|
-
return data;
|
|
579
|
-
}
|
|
580
|
-
emit(aborted, settledKey) {
|
|
581
|
-
this.subscribers.forEach((subscriber) => subscriber(aborted, settledKey));
|
|
582
|
-
}
|
|
583
|
-
subscribe(fn) {
|
|
584
|
-
this.subscribers.add(fn);
|
|
585
|
-
return () => this.subscribers.delete(fn);
|
|
586
|
-
}
|
|
587
|
-
cancel() {
|
|
588
|
-
this.controller.abort();
|
|
589
|
-
this.pendingKeysSet.forEach((v, k) => this.pendingKeysSet.delete(k));
|
|
590
|
-
this.emit(true);
|
|
591
|
-
}
|
|
592
|
-
async resolveData(signal) {
|
|
593
|
-
let aborted = false;
|
|
594
|
-
if (!this.done) {
|
|
595
|
-
let onAbort = () => this.cancel();
|
|
596
|
-
signal.addEventListener("abort", onAbort);
|
|
597
|
-
aborted = await new Promise((resolve) => {
|
|
598
|
-
this.subscribe((aborted2) => {
|
|
599
|
-
signal.removeEventListener("abort", onAbort);
|
|
600
|
-
if (aborted2 || this.done) {
|
|
601
|
-
resolve(aborted2);
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
return aborted;
|
|
607
|
-
}
|
|
608
|
-
get done() {
|
|
609
|
-
return this.pendingKeysSet.size === 0;
|
|
610
|
-
}
|
|
611
|
-
get unwrappedData() {
|
|
612
|
-
invariant(
|
|
613
|
-
this.data !== null && this.done,
|
|
614
|
-
"Can only unwrap data on initialized and settled deferreds"
|
|
615
|
-
);
|
|
616
|
-
return Object.entries(this.data).reduce(
|
|
617
|
-
(acc, [key, value]) => Object.assign(acc, {
|
|
618
|
-
[key]: unwrapTrackedPromise(value)
|
|
619
|
-
}),
|
|
620
|
-
{}
|
|
621
|
-
);
|
|
622
|
-
}
|
|
623
|
-
get pendingKeys() {
|
|
624
|
-
return Array.from(this.pendingKeysSet);
|
|
625
|
-
}
|
|
626
|
-
};
|
|
627
|
-
function isTrackedPromise(value) {
|
|
628
|
-
return value instanceof Promise && value._tracked === true;
|
|
629
|
-
}
|
|
630
|
-
function unwrapTrackedPromise(value) {
|
|
631
|
-
if (!isTrackedPromise(value)) {
|
|
632
|
-
return value;
|
|
633
|
-
}
|
|
634
|
-
if (value._error) {
|
|
635
|
-
throw value._error;
|
|
636
|
-
}
|
|
637
|
-
return value._data;
|
|
638
|
-
}
|
|
639
|
-
var defer = (data, init = {}) => {
|
|
640
|
-
let responseInit = typeof init === "number" ? { status: init } : init;
|
|
641
|
-
return new DeferredData(data, responseInit);
|
|
642
|
-
};
|
|
643
|
-
var redirect = (url, init = 302) => {
|
|
644
|
-
let responseInit = init;
|
|
645
|
-
if (typeof responseInit === "number") {
|
|
646
|
-
responseInit = { status: responseInit };
|
|
647
|
-
} else if (typeof responseInit.status === "undefined") {
|
|
648
|
-
responseInit.status = 302;
|
|
649
|
-
}
|
|
650
|
-
let headers = new Headers(responseInit.headers);
|
|
651
|
-
headers.set("Location", url);
|
|
652
|
-
return new Response(null, {
|
|
653
|
-
...responseInit,
|
|
654
|
-
headers
|
|
655
|
-
});
|
|
656
|
-
};
|
|
657
|
-
var redirectDocument = (url, init) => {
|
|
658
|
-
let response = redirect(url, init);
|
|
659
|
-
response.headers.set("X-Remix-Reload-Document", "true");
|
|
660
|
-
return response;
|
|
661
|
-
};
|
|
662
|
-
var ErrorResponseImpl = class {
|
|
663
|
-
constructor(status, statusText, data, internal = false) {
|
|
664
|
-
this.status = status;
|
|
665
|
-
this.statusText = statusText || "";
|
|
666
|
-
this.internal = internal;
|
|
667
|
-
if (data instanceof Error) {
|
|
668
|
-
this.data = data.toString();
|
|
669
|
-
this.error = data;
|
|
670
|
-
} else {
|
|
671
|
-
this.data = data;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
function isRouteErrorResponse(error) {
|
|
676
|
-
return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// packages/react-router/lib/router/router.ts
|
|
680
|
-
var validMutationMethodsArr = [
|
|
681
|
-
"post",
|
|
682
|
-
"put",
|
|
683
|
-
"patch",
|
|
684
|
-
"delete"
|
|
685
|
-
];
|
|
686
|
-
var validMutationMethods = new Set(
|
|
687
|
-
validMutationMethodsArr
|
|
688
|
-
);
|
|
689
|
-
var validRequestMethodsArr = [
|
|
690
|
-
"get",
|
|
691
|
-
...validMutationMethodsArr
|
|
692
|
-
];
|
|
693
|
-
var validRequestMethods = new Set(validRequestMethodsArr);
|
|
694
|
-
var redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
695
|
-
var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
696
|
-
var defaultMapRouteProperties = (route) => ({
|
|
697
|
-
hasErrorBoundary: Boolean(route.hasErrorBoundary)
|
|
698
|
-
});
|
|
699
|
-
var UNSAFE_DEFERRED_SYMBOL = Symbol("deferred");
|
|
700
|
-
function createStaticHandler(routes, opts) {
|
|
701
|
-
invariant(
|
|
702
|
-
routes.length > 0,
|
|
703
|
-
"You must provide a non-empty routes array to createStaticHandler"
|
|
704
|
-
);
|
|
705
|
-
let manifest = {};
|
|
706
|
-
let basename = (opts ? opts.basename : null) || "/";
|
|
707
|
-
let mapRouteProperties2;
|
|
708
|
-
if (opts?.mapRouteProperties) {
|
|
709
|
-
mapRouteProperties2 = opts.mapRouteProperties;
|
|
710
|
-
} else if (opts?.detectErrorBoundary) {
|
|
711
|
-
let detectErrorBoundary = opts.detectErrorBoundary;
|
|
712
|
-
mapRouteProperties2 = (route) => ({
|
|
713
|
-
hasErrorBoundary: detectErrorBoundary(route)
|
|
714
|
-
});
|
|
715
|
-
} else {
|
|
716
|
-
mapRouteProperties2 = defaultMapRouteProperties;
|
|
717
|
-
}
|
|
718
|
-
let future = {
|
|
719
|
-
v7_relativeSplatPath: false,
|
|
720
|
-
v7_throwAbortReason: false,
|
|
721
|
-
...opts ? opts.future : null
|
|
722
|
-
};
|
|
723
|
-
let dataRoutes = convertRoutesToDataRoutes(
|
|
724
|
-
routes,
|
|
725
|
-
mapRouteProperties2,
|
|
726
|
-
void 0,
|
|
727
|
-
manifest
|
|
728
|
-
);
|
|
729
|
-
async function query(request, {
|
|
730
|
-
requestContext,
|
|
731
|
-
skipLoaderErrorBubbling,
|
|
732
|
-
unstable_dataStrategy
|
|
733
|
-
} = {}) {
|
|
734
|
-
let url = new URL(request.url);
|
|
735
|
-
let method = request.method;
|
|
736
|
-
let location = createLocation("", createPath(url), null, "default");
|
|
737
|
-
let matches = matchRoutes(dataRoutes, location, basename);
|
|
738
|
-
if (!isValidMethod(method) && method !== "HEAD") {
|
|
739
|
-
let error = getInternalRouterError(405, { method });
|
|
740
|
-
let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
741
|
-
return {
|
|
742
|
-
basename,
|
|
743
|
-
location,
|
|
744
|
-
matches: methodNotAllowedMatches,
|
|
745
|
-
loaderData: {},
|
|
746
|
-
actionData: null,
|
|
747
|
-
errors: {
|
|
748
|
-
[route.id]: error
|
|
749
|
-
},
|
|
750
|
-
statusCode: error.status,
|
|
751
|
-
loaderHeaders: {},
|
|
752
|
-
actionHeaders: {},
|
|
753
|
-
activeDeferreds: null
|
|
754
|
-
};
|
|
755
|
-
} else if (!matches) {
|
|
756
|
-
let error = getInternalRouterError(404, { pathname: location.pathname });
|
|
757
|
-
let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
|
758
|
-
return {
|
|
759
|
-
basename,
|
|
760
|
-
location,
|
|
761
|
-
matches: notFoundMatches,
|
|
762
|
-
loaderData: {},
|
|
763
|
-
actionData: null,
|
|
764
|
-
errors: {
|
|
765
|
-
[route.id]: error
|
|
766
|
-
},
|
|
767
|
-
statusCode: error.status,
|
|
768
|
-
loaderHeaders: {},
|
|
769
|
-
actionHeaders: {},
|
|
770
|
-
activeDeferreds: null
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
let result = await queryImpl(
|
|
774
|
-
request,
|
|
775
|
-
location,
|
|
776
|
-
matches,
|
|
777
|
-
requestContext,
|
|
778
|
-
unstable_dataStrategy || null,
|
|
779
|
-
skipLoaderErrorBubbling === true,
|
|
780
|
-
null
|
|
781
|
-
);
|
|
782
|
-
if (isResponse(result)) {
|
|
783
|
-
return result;
|
|
784
|
-
}
|
|
785
|
-
return { location, basename, ...result };
|
|
786
|
-
}
|
|
787
|
-
async function queryRoute(request, {
|
|
788
|
-
routeId,
|
|
789
|
-
requestContext
|
|
790
|
-
} = {}) {
|
|
791
|
-
let url = new URL(request.url);
|
|
792
|
-
let method = request.method;
|
|
793
|
-
let location = createLocation("", createPath(url), null, "default");
|
|
794
|
-
let matches = matchRoutes(dataRoutes, location, basename);
|
|
795
|
-
if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
|
796
|
-
throw getInternalRouterError(405, { method });
|
|
797
|
-
} else if (!matches) {
|
|
798
|
-
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
799
|
-
}
|
|
800
|
-
let match = routeId ? matches.find((m) => m.route.id === routeId) : getTargetMatch(matches, location);
|
|
801
|
-
if (routeId && !match) {
|
|
802
|
-
throw getInternalRouterError(403, {
|
|
803
|
-
pathname: location.pathname,
|
|
804
|
-
routeId
|
|
805
|
-
});
|
|
806
|
-
} else if (!match) {
|
|
807
|
-
throw getInternalRouterError(404, { pathname: location.pathname });
|
|
808
|
-
}
|
|
809
|
-
let result = await queryImpl(
|
|
810
|
-
request,
|
|
811
|
-
location,
|
|
812
|
-
matches,
|
|
813
|
-
requestContext,
|
|
814
|
-
null,
|
|
815
|
-
false,
|
|
816
|
-
match
|
|
817
|
-
);
|
|
818
|
-
if (isResponse(result)) {
|
|
819
|
-
return result;
|
|
820
|
-
}
|
|
821
|
-
let error = result.errors ? Object.values(result.errors)[0] : void 0;
|
|
822
|
-
if (error !== void 0) {
|
|
823
|
-
throw error;
|
|
824
|
-
}
|
|
825
|
-
if (result.actionData) {
|
|
826
|
-
return Object.values(result.actionData)[0];
|
|
827
|
-
}
|
|
828
|
-
if (result.loaderData) {
|
|
829
|
-
let data = Object.values(result.loaderData)[0];
|
|
830
|
-
if (result.activeDeferreds?.[match.route.id]) {
|
|
831
|
-
data[UNSAFE_DEFERRED_SYMBOL] = result.activeDeferreds[match.route.id];
|
|
832
|
-
}
|
|
833
|
-
return data;
|
|
834
|
-
}
|
|
835
|
-
return void 0;
|
|
836
|
-
}
|
|
837
|
-
async function queryImpl(request, location, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch) {
|
|
838
|
-
invariant(
|
|
839
|
-
request.signal,
|
|
840
|
-
"query()/queryRoute() requests must contain an AbortController signal"
|
|
841
|
-
);
|
|
842
|
-
try {
|
|
843
|
-
if (isMutationMethod(request.method.toLowerCase())) {
|
|
844
|
-
let result2 = await submit(
|
|
845
|
-
request,
|
|
846
|
-
matches,
|
|
847
|
-
routeMatch || getTargetMatch(matches, location),
|
|
848
|
-
requestContext,
|
|
849
|
-
unstable_dataStrategy,
|
|
850
|
-
skipLoaderErrorBubbling,
|
|
851
|
-
routeMatch != null
|
|
852
|
-
);
|
|
853
|
-
return result2;
|
|
854
|
-
}
|
|
855
|
-
let result = await loadRouteData(
|
|
856
|
-
request,
|
|
857
|
-
matches,
|
|
858
|
-
requestContext,
|
|
859
|
-
unstable_dataStrategy,
|
|
860
|
-
skipLoaderErrorBubbling,
|
|
861
|
-
routeMatch
|
|
862
|
-
);
|
|
863
|
-
return isResponse(result) ? result : {
|
|
864
|
-
...result,
|
|
865
|
-
actionData: null,
|
|
866
|
-
actionHeaders: {}
|
|
867
|
-
};
|
|
868
|
-
} catch (e) {
|
|
869
|
-
if (isHandlerResult(e) && isResponse(e.result)) {
|
|
870
|
-
if (e.type === "error" /* error */) {
|
|
871
|
-
throw e.result;
|
|
872
|
-
}
|
|
873
|
-
return e.result;
|
|
874
|
-
}
|
|
875
|
-
if (isRedirectResponse(e)) {
|
|
876
|
-
return e;
|
|
877
|
-
}
|
|
878
|
-
throw e;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
async function submit(request, matches, actionMatch, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, isRouteRequest) {
|
|
882
|
-
let result;
|
|
883
|
-
if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
|
884
|
-
let error = getInternalRouterError(405, {
|
|
885
|
-
method: request.method,
|
|
886
|
-
pathname: new URL(request.url).pathname,
|
|
887
|
-
routeId: actionMatch.route.id
|
|
888
|
-
});
|
|
889
|
-
if (isRouteRequest) {
|
|
890
|
-
throw error;
|
|
891
|
-
}
|
|
892
|
-
result = {
|
|
893
|
-
type: "error" /* error */,
|
|
894
|
-
error
|
|
895
|
-
};
|
|
896
|
-
} else {
|
|
897
|
-
let results = await callDataStrategy(
|
|
898
|
-
"action",
|
|
899
|
-
request,
|
|
900
|
-
[actionMatch],
|
|
901
|
-
matches,
|
|
902
|
-
isRouteRequest,
|
|
903
|
-
requestContext,
|
|
904
|
-
unstable_dataStrategy
|
|
905
|
-
);
|
|
906
|
-
result = results[0];
|
|
907
|
-
if (request.signal.aborted) {
|
|
908
|
-
throwStaticHandlerAbortedError(request, isRouteRequest, future);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
if (isRedirectResult(result)) {
|
|
912
|
-
throw new Response(null, {
|
|
913
|
-
status: result.response.status,
|
|
914
|
-
headers: {
|
|
915
|
-
Location: result.response.headers.get("Location")
|
|
916
|
-
}
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
if (isDeferredResult(result)) {
|
|
920
|
-
let error = getInternalRouterError(400, { type: "defer-action" });
|
|
921
|
-
if (isRouteRequest) {
|
|
922
|
-
throw error;
|
|
923
|
-
}
|
|
924
|
-
result = {
|
|
925
|
-
type: "error" /* error */,
|
|
926
|
-
error
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
if (isRouteRequest) {
|
|
930
|
-
if (isErrorResult(result)) {
|
|
931
|
-
throw result.error;
|
|
932
|
-
}
|
|
933
|
-
return {
|
|
934
|
-
matches: [actionMatch],
|
|
935
|
-
loaderData: {},
|
|
936
|
-
actionData: { [actionMatch.route.id]: result.data },
|
|
937
|
-
errors: null,
|
|
938
|
-
// Note: statusCode + headers are unused here since queryRoute will
|
|
939
|
-
// return the raw Response or value
|
|
940
|
-
statusCode: 200,
|
|
941
|
-
loaderHeaders: {},
|
|
942
|
-
actionHeaders: {},
|
|
943
|
-
activeDeferreds: null
|
|
944
|
-
};
|
|
945
|
-
}
|
|
946
|
-
let loaderRequest = new Request(request.url, {
|
|
947
|
-
headers: request.headers,
|
|
948
|
-
redirect: request.redirect,
|
|
949
|
-
signal: request.signal
|
|
950
|
-
});
|
|
951
|
-
if (isErrorResult(result)) {
|
|
952
|
-
let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
|
953
|
-
let context2 = await loadRouteData(
|
|
954
|
-
loaderRequest,
|
|
955
|
-
matches,
|
|
956
|
-
requestContext,
|
|
957
|
-
unstable_dataStrategy,
|
|
958
|
-
skipLoaderErrorBubbling,
|
|
959
|
-
null,
|
|
960
|
-
[boundaryMatch.route.id, result]
|
|
961
|
-
);
|
|
962
|
-
return {
|
|
963
|
-
...context2,
|
|
964
|
-
statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
|
965
|
-
actionData: null,
|
|
966
|
-
actionHeaders: {
|
|
967
|
-
...result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
let context = await loadRouteData(
|
|
972
|
-
loaderRequest,
|
|
973
|
-
matches,
|
|
974
|
-
requestContext,
|
|
975
|
-
unstable_dataStrategy,
|
|
976
|
-
skipLoaderErrorBubbling,
|
|
977
|
-
null
|
|
978
|
-
);
|
|
979
|
-
return {
|
|
980
|
-
...context,
|
|
981
|
-
actionData: {
|
|
982
|
-
[actionMatch.route.id]: result.data
|
|
983
|
-
},
|
|
984
|
-
// action status codes take precedence over loader status codes
|
|
985
|
-
...result.statusCode ? { statusCode: result.statusCode } : {},
|
|
986
|
-
actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
async function loadRouteData(request, matches, requestContext, unstable_dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) {
|
|
990
|
-
let isRouteRequest = routeMatch != null;
|
|
991
|
-
if (isRouteRequest && !routeMatch?.route.loader && !routeMatch?.route.lazy) {
|
|
992
|
-
throw getInternalRouterError(400, {
|
|
993
|
-
method: request.method,
|
|
994
|
-
pathname: new URL(request.url).pathname,
|
|
995
|
-
routeId: routeMatch?.route.id
|
|
996
|
-
});
|
|
997
|
-
}
|
|
998
|
-
let requestMatches = routeMatch ? [routeMatch] : pendingActionResult && isErrorResult(pendingActionResult[1]) ? getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]) : matches;
|
|
999
|
-
let matchesToLoad = requestMatches.filter(
|
|
1000
|
-
(m) => m.route.loader || m.route.lazy
|
|
1001
|
-
);
|
|
1002
|
-
if (matchesToLoad.length === 0) {
|
|
1003
|
-
return {
|
|
1004
|
-
matches,
|
|
1005
|
-
// Add a null for all matched routes for proper revalidation on the client
|
|
1006
|
-
loaderData: matches.reduce(
|
|
1007
|
-
(acc, m) => Object.assign(acc, { [m.route.id]: null }),
|
|
1008
|
-
{}
|
|
1009
|
-
),
|
|
1010
|
-
errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? {
|
|
1011
|
-
[pendingActionResult[0]]: pendingActionResult[1].error
|
|
1012
|
-
} : null,
|
|
1013
|
-
statusCode: 200,
|
|
1014
|
-
loaderHeaders: {},
|
|
1015
|
-
activeDeferreds: null
|
|
1016
|
-
};
|
|
1017
|
-
}
|
|
1018
|
-
let results = await callDataStrategy(
|
|
1019
|
-
"loader",
|
|
1020
|
-
request,
|
|
1021
|
-
matchesToLoad,
|
|
1022
|
-
matches,
|
|
1023
|
-
isRouteRequest,
|
|
1024
|
-
requestContext,
|
|
1025
|
-
unstable_dataStrategy
|
|
1026
|
-
);
|
|
1027
|
-
if (request.signal.aborted) {
|
|
1028
|
-
throwStaticHandlerAbortedError(request, isRouteRequest, future);
|
|
1029
|
-
}
|
|
1030
|
-
let activeDeferreds = /* @__PURE__ */ new Map();
|
|
1031
|
-
let context = processRouteLoaderData(
|
|
1032
|
-
matches,
|
|
1033
|
-
matchesToLoad,
|
|
1034
|
-
results,
|
|
1035
|
-
pendingActionResult,
|
|
1036
|
-
activeDeferreds,
|
|
1037
|
-
skipLoaderErrorBubbling
|
|
1038
|
-
);
|
|
1039
|
-
let executedLoaders = new Set(
|
|
1040
|
-
matchesToLoad.map((match) => match.route.id)
|
|
1041
|
-
);
|
|
1042
|
-
matches.forEach((match) => {
|
|
1043
|
-
if (!executedLoaders.has(match.route.id)) {
|
|
1044
|
-
context.loaderData[match.route.id] = null;
|
|
1045
|
-
}
|
|
1046
|
-
});
|
|
1047
|
-
return {
|
|
1048
|
-
...context,
|
|
1049
|
-
matches,
|
|
1050
|
-
activeDeferreds: activeDeferreds.size > 0 ? Object.fromEntries(activeDeferreds.entries()) : null
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
async function callDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, unstable_dataStrategy) {
|
|
1054
|
-
let results = await callDataStrategyImpl(
|
|
1055
|
-
unstable_dataStrategy || defaultDataStrategy,
|
|
1056
|
-
type,
|
|
1057
|
-
request,
|
|
1058
|
-
matchesToLoad,
|
|
1059
|
-
matches,
|
|
1060
|
-
manifest,
|
|
1061
|
-
mapRouteProperties2,
|
|
1062
|
-
requestContext
|
|
1063
|
-
);
|
|
1064
|
-
return await Promise.all(
|
|
1065
|
-
results.map((result, i) => {
|
|
1066
|
-
if (isRedirectHandlerResult(result)) {
|
|
1067
|
-
let response = result.result;
|
|
1068
|
-
throw normalizeRelativeRoutingRedirectResponse(
|
|
1069
|
-
response,
|
|
1070
|
-
request,
|
|
1071
|
-
matchesToLoad[i].route.id,
|
|
1072
|
-
matches,
|
|
1073
|
-
basename,
|
|
1074
|
-
future.v7_relativeSplatPath
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1077
|
-
if (isResponse(result.result) && isRouteRequest) {
|
|
1078
|
-
throw result;
|
|
1079
|
-
}
|
|
1080
|
-
return convertHandlerResultToDataResult(result);
|
|
1081
|
-
})
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
return {
|
|
1085
|
-
dataRoutes,
|
|
1086
|
-
query,
|
|
1087
|
-
queryRoute
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
function getStaticContextFromError(routes, context, error) {
|
|
1091
|
-
let newContext = {
|
|
1092
|
-
...context,
|
|
1093
|
-
statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
|
1094
|
-
errors: {
|
|
1095
|
-
[context._deepestRenderedBoundaryId || routes[0].id]: error
|
|
1096
|
-
}
|
|
1097
|
-
};
|
|
1098
|
-
return newContext;
|
|
1099
|
-
}
|
|
1100
|
-
function throwStaticHandlerAbortedError(request, isRouteRequest, future) {
|
|
1101
|
-
if (future.v7_throwAbortReason && request.signal.reason !== void 0) {
|
|
1102
|
-
throw request.signal.reason;
|
|
1103
|
-
}
|
|
1104
|
-
let method = isRouteRequest ? "queryRoute" : "query";
|
|
1105
|
-
throw new Error(`${method}() call aborted: ${request.method} ${request.url}`);
|
|
1106
|
-
}
|
|
1107
|
-
function normalizeTo(location, matches, basename, prependBasename, to, v7_relativeSplatPath, fromRouteId, relative) {
|
|
1108
|
-
let contextualMatches;
|
|
1109
|
-
let activeRouteMatch;
|
|
1110
|
-
if (fromRouteId) {
|
|
1111
|
-
contextualMatches = [];
|
|
1112
|
-
for (let match of matches) {
|
|
1113
|
-
contextualMatches.push(match);
|
|
1114
|
-
if (match.route.id === fromRouteId) {
|
|
1115
|
-
activeRouteMatch = match;
|
|
1116
|
-
break;
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
} else {
|
|
1120
|
-
contextualMatches = matches;
|
|
1121
|
-
activeRouteMatch = matches[matches.length - 1];
|
|
1122
|
-
}
|
|
1123
|
-
let path = resolveTo(
|
|
1124
|
-
to ? to : ".",
|
|
1125
|
-
getResolveToMatches(contextualMatches, v7_relativeSplatPath),
|
|
1126
|
-
stripBasename(location.pathname, basename) || location.pathname,
|
|
1127
|
-
relative === "path"
|
|
1128
|
-
);
|
|
1129
|
-
if (to == null) {
|
|
1130
|
-
path.search = location.search;
|
|
1131
|
-
path.hash = location.hash;
|
|
1132
|
-
}
|
|
1133
|
-
if ((to == null || to === "" || to === ".") && activeRouteMatch && activeRouteMatch.route.index && !hasNakedIndexQuery(path.search)) {
|
|
1134
|
-
path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
|
1135
|
-
}
|
|
1136
|
-
if (prependBasename && basename !== "/") {
|
|
1137
|
-
path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
1138
|
-
}
|
|
1139
|
-
return createPath(path);
|
|
1140
|
-
}
|
|
1141
|
-
function getLoaderMatchesUntilBoundary(matches, boundaryId) {
|
|
1142
|
-
let boundaryMatches = matches;
|
|
1143
|
-
if (boundaryId) {
|
|
1144
|
-
let index = matches.findIndex((m) => m.route.id === boundaryId);
|
|
1145
|
-
if (index >= 0) {
|
|
1146
|
-
boundaryMatches = matches.slice(0, index);
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
return boundaryMatches;
|
|
1150
|
-
}
|
|
1151
|
-
async function loadLazyRouteModule(route, mapRouteProperties2, manifest) {
|
|
1152
|
-
if (!route.lazy) {
|
|
1153
|
-
return;
|
|
1154
|
-
}
|
|
1155
|
-
let lazyRoute = await route.lazy();
|
|
1156
|
-
if (!route.lazy) {
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
let routeToUpdate = manifest[route.id];
|
|
1160
|
-
invariant(routeToUpdate, "No route found in manifest");
|
|
1161
|
-
let routeUpdates = {};
|
|
1162
|
-
for (let lazyRouteProperty in lazyRoute) {
|
|
1163
|
-
let staticRouteValue = routeToUpdate[lazyRouteProperty];
|
|
1164
|
-
let isPropertyStaticallyDefined = staticRouteValue !== void 0 && // This property isn't static since it should always be updated based
|
|
1165
|
-
// on the route updates
|
|
1166
|
-
lazyRouteProperty !== "hasErrorBoundary";
|
|
1167
|
-
warning(
|
|
1168
|
-
!isPropertyStaticallyDefined,
|
|
1169
|
-
`Route "${routeToUpdate.id}" has a static property "${lazyRouteProperty}" defined but its lazy function is also returning a value for this property. The lazy route property "${lazyRouteProperty}" will be ignored.`
|
|
1170
|
-
);
|
|
1171
|
-
if (!isPropertyStaticallyDefined && !immutableRouteKeys.has(lazyRouteProperty)) {
|
|
1172
|
-
routeUpdates[lazyRouteProperty] = lazyRoute[lazyRouteProperty];
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
Object.assign(routeToUpdate, routeUpdates);
|
|
1176
|
-
Object.assign(routeToUpdate, {
|
|
1177
|
-
// To keep things framework agnostic, we use the provided
|
|
1178
|
-
// `mapRouteProperties` (or wrapped `detectErrorBoundary`) function to
|
|
1179
|
-
// set the framework-aware properties (`element`/`hasErrorBoundary`) since
|
|
1180
|
-
// the logic will differ between frameworks.
|
|
1181
|
-
...mapRouteProperties2(routeToUpdate),
|
|
1182
|
-
lazy: void 0
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
function defaultDataStrategy(opts) {
|
|
1186
|
-
return Promise.all(opts.matches.map((m) => m.resolve()));
|
|
1187
|
-
}
|
|
1188
|
-
async function callDataStrategyImpl(dataStrategyImpl, type, request, matchesToLoad, matches, manifest, mapRouteProperties2, requestContext) {
|
|
1189
|
-
let routeIdsToLoad = matchesToLoad.reduce(
|
|
1190
|
-
(acc, m) => acc.add(m.route.id),
|
|
1191
|
-
/* @__PURE__ */ new Set()
|
|
1192
|
-
);
|
|
1193
|
-
let loadedMatches = /* @__PURE__ */ new Set();
|
|
1194
|
-
let results = await dataStrategyImpl({
|
|
1195
|
-
matches: matches.map((match) => {
|
|
1196
|
-
let shouldLoad = routeIdsToLoad.has(match.route.id);
|
|
1197
|
-
let resolve = (handlerOverride) => {
|
|
1198
|
-
loadedMatches.add(match.route.id);
|
|
1199
|
-
return shouldLoad ? callLoaderOrAction(
|
|
1200
|
-
type,
|
|
1201
|
-
request,
|
|
1202
|
-
match,
|
|
1203
|
-
manifest,
|
|
1204
|
-
mapRouteProperties2,
|
|
1205
|
-
handlerOverride,
|
|
1206
|
-
requestContext
|
|
1207
|
-
) : Promise.resolve({ type: "data" /* data */, result: void 0 });
|
|
1208
|
-
};
|
|
1209
|
-
return {
|
|
1210
|
-
...match,
|
|
1211
|
-
shouldLoad,
|
|
1212
|
-
resolve
|
|
1213
|
-
};
|
|
1214
|
-
}),
|
|
1215
|
-
request,
|
|
1216
|
-
params: matches[0].params,
|
|
1217
|
-
context: requestContext
|
|
1218
|
-
});
|
|
1219
|
-
matches.forEach(
|
|
1220
|
-
(m) => invariant(
|
|
1221
|
-
loadedMatches.has(m.route.id),
|
|
1222
|
-
`\`match.resolve()\` was not called for route id "${m.route.id}". You must call \`match.resolve()\` on every match passed to \`dataStrategy\` to ensure all routes are properly loaded.`
|
|
1223
|
-
)
|
|
1224
|
-
);
|
|
1225
|
-
return results.filter((_, i) => routeIdsToLoad.has(matches[i].route.id));
|
|
1226
|
-
}
|
|
1227
|
-
async function callLoaderOrAction(type, request, match, manifest, mapRouteProperties2, handlerOverride, staticContext) {
|
|
1228
|
-
let result;
|
|
1229
|
-
let onReject;
|
|
1230
|
-
let runHandler = (handler) => {
|
|
1231
|
-
let reject;
|
|
1232
|
-
let abortPromise = new Promise((_, r) => reject = r);
|
|
1233
|
-
onReject = () => reject();
|
|
1234
|
-
request.signal.addEventListener("abort", onReject);
|
|
1235
|
-
let actualHandler = (ctx) => {
|
|
1236
|
-
if (typeof handler !== "function") {
|
|
1237
|
-
return Promise.reject(
|
|
1238
|
-
new Error(
|
|
1239
|
-
`You cannot call the handler for a route which defines a boolean "${type}" [routeId: ${match.route.id}]`
|
|
1240
|
-
)
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
return handler(
|
|
1244
|
-
{
|
|
1245
|
-
request,
|
|
1246
|
-
params: match.params,
|
|
1247
|
-
context: staticContext
|
|
1248
|
-
},
|
|
1249
|
-
...ctx !== void 0 ? [ctx] : []
|
|
1250
|
-
);
|
|
1251
|
-
};
|
|
1252
|
-
let handlerPromise;
|
|
1253
|
-
if (handlerOverride) {
|
|
1254
|
-
handlerPromise = handlerOverride((ctx) => actualHandler(ctx));
|
|
1255
|
-
} else {
|
|
1256
|
-
handlerPromise = (async () => {
|
|
1257
|
-
try {
|
|
1258
|
-
let val = await actualHandler();
|
|
1259
|
-
return { type: "data", result: val };
|
|
1260
|
-
} catch (e) {
|
|
1261
|
-
return { type: "error", result: e };
|
|
1262
|
-
}
|
|
1263
|
-
})();
|
|
1264
|
-
}
|
|
1265
|
-
return Promise.race([handlerPromise, abortPromise]);
|
|
1266
|
-
};
|
|
1267
|
-
try {
|
|
1268
|
-
let handler = match.route[type];
|
|
1269
|
-
if (match.route.lazy) {
|
|
1270
|
-
if (handler) {
|
|
1271
|
-
let handlerError;
|
|
1272
|
-
let [value] = await Promise.all([
|
|
1273
|
-
// If the handler throws, don't let it immediately bubble out,
|
|
1274
|
-
// since we need to let the lazy() execution finish so we know if this
|
|
1275
|
-
// route has a boundary that can handle the error
|
|
1276
|
-
runHandler(handler).catch((e) => {
|
|
1277
|
-
handlerError = e;
|
|
1278
|
-
}),
|
|
1279
|
-
loadLazyRouteModule(match.route, mapRouteProperties2, manifest)
|
|
1280
|
-
]);
|
|
1281
|
-
if (handlerError !== void 0) {
|
|
1282
|
-
throw handlerError;
|
|
1283
|
-
}
|
|
1284
|
-
result = value;
|
|
1285
|
-
} else {
|
|
1286
|
-
await loadLazyRouteModule(match.route, mapRouteProperties2, manifest);
|
|
1287
|
-
handler = match.route[type];
|
|
1288
|
-
if (handler) {
|
|
1289
|
-
result = await runHandler(handler);
|
|
1290
|
-
} else if (type === "action") {
|
|
1291
|
-
let url = new URL(request.url);
|
|
1292
|
-
let pathname = url.pathname + url.search;
|
|
1293
|
-
throw getInternalRouterError(405, {
|
|
1294
|
-
method: request.method,
|
|
1295
|
-
pathname,
|
|
1296
|
-
routeId: match.route.id
|
|
1297
|
-
});
|
|
1298
|
-
} else {
|
|
1299
|
-
return { type: "data" /* data */, result: void 0 };
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
} else if (!handler) {
|
|
1303
|
-
let url = new URL(request.url);
|
|
1304
|
-
let pathname = url.pathname + url.search;
|
|
1305
|
-
throw getInternalRouterError(404, {
|
|
1306
|
-
pathname
|
|
1307
|
-
});
|
|
1308
|
-
} else {
|
|
1309
|
-
result = await runHandler(handler);
|
|
1310
|
-
}
|
|
1311
|
-
invariant(
|
|
1312
|
-
result.result !== void 0,
|
|
1313
|
-
`You defined ${type === "action" ? "an action" : "a loader"} for route "${match.route.id}" but didn't return anything from your \`${type}\` function. Please return a value or \`null\`.`
|
|
1314
|
-
);
|
|
1315
|
-
} catch (e) {
|
|
1316
|
-
return { type: "error" /* error */, result: e };
|
|
1317
|
-
} finally {
|
|
1318
|
-
if (onReject) {
|
|
1319
|
-
request.signal.removeEventListener("abort", onReject);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
return result;
|
|
1323
|
-
}
|
|
1324
|
-
async function convertHandlerResultToDataResult(handlerResult) {
|
|
1325
|
-
let { result, type, status } = handlerResult;
|
|
1326
|
-
if (isResponse(result)) {
|
|
1327
|
-
let data;
|
|
1328
|
-
try {
|
|
1329
|
-
let contentType = result.headers.get("Content-Type");
|
|
1330
|
-
if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
|
1331
|
-
if (result.body == null) {
|
|
1332
|
-
data = null;
|
|
1333
|
-
} else {
|
|
1334
|
-
data = await result.json();
|
|
1335
|
-
}
|
|
1336
|
-
} else {
|
|
1337
|
-
data = await result.text();
|
|
1338
|
-
}
|
|
1339
|
-
} catch (e) {
|
|
1340
|
-
return { type: "error" /* error */, error: e };
|
|
1341
|
-
}
|
|
1342
|
-
if (type === "error" /* error */) {
|
|
1343
|
-
return {
|
|
1344
|
-
type: "error" /* error */,
|
|
1345
|
-
error: new ErrorResponseImpl(result.status, result.statusText, data),
|
|
1346
|
-
statusCode: result.status,
|
|
1347
|
-
headers: result.headers
|
|
1348
|
-
};
|
|
1349
|
-
}
|
|
1350
|
-
return {
|
|
1351
|
-
type: "data" /* data */,
|
|
1352
|
-
data,
|
|
1353
|
-
statusCode: result.status,
|
|
1354
|
-
headers: result.headers
|
|
1355
|
-
};
|
|
1356
|
-
}
|
|
1357
|
-
if (type === "error" /* error */) {
|
|
1358
|
-
return {
|
|
1359
|
-
type: "error" /* error */,
|
|
1360
|
-
error: result,
|
|
1361
|
-
statusCode: isRouteErrorResponse(result) ? result.status : status
|
|
1362
|
-
};
|
|
1363
|
-
}
|
|
1364
|
-
if (isDeferredData(result)) {
|
|
1365
|
-
return {
|
|
1366
|
-
type: "deferred" /* deferred */,
|
|
1367
|
-
deferredData: result,
|
|
1368
|
-
statusCode: result.init?.status,
|
|
1369
|
-
headers: result.init?.headers && new Headers(result.init.headers)
|
|
1370
|
-
};
|
|
1371
|
-
}
|
|
1372
|
-
return { type: "data" /* data */, data: result, statusCode: status };
|
|
1373
|
-
}
|
|
1374
|
-
function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename, v7_relativeSplatPath) {
|
|
1375
|
-
let location = response.headers.get("Location");
|
|
1376
|
-
invariant(
|
|
1377
|
-
location,
|
|
1378
|
-
"Redirects returned/thrown from loaders/actions must have a Location header"
|
|
1379
|
-
);
|
|
1380
|
-
if (!ABSOLUTE_URL_REGEX.test(location)) {
|
|
1381
|
-
let trimmedMatches = matches.slice(
|
|
1382
|
-
0,
|
|
1383
|
-
matches.findIndex((m) => m.route.id === routeId) + 1
|
|
1384
|
-
);
|
|
1385
|
-
location = normalizeTo(
|
|
1386
|
-
new URL(request.url),
|
|
1387
|
-
trimmedMatches,
|
|
1388
|
-
basename,
|
|
1389
|
-
true,
|
|
1390
|
-
location,
|
|
1391
|
-
v7_relativeSplatPath
|
|
1392
|
-
);
|
|
1393
|
-
response.headers.set("Location", location);
|
|
1394
|
-
}
|
|
1395
|
-
return response;
|
|
1396
|
-
}
|
|
1397
|
-
function processRouteLoaderData(matches, matchesToLoad, results, pendingActionResult, activeDeferreds, skipLoaderErrorBubbling) {
|
|
1398
|
-
let loaderData = {};
|
|
1399
|
-
let errors = null;
|
|
1400
|
-
let statusCode;
|
|
1401
|
-
let foundError = false;
|
|
1402
|
-
let loaderHeaders = {};
|
|
1403
|
-
let pendingError = pendingActionResult && isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : void 0;
|
|
1404
|
-
results.forEach((result, index) => {
|
|
1405
|
-
let id = matchesToLoad[index].route.id;
|
|
1406
|
-
invariant(
|
|
1407
|
-
!isRedirectResult(result),
|
|
1408
|
-
"Cannot handle redirect results in processLoaderData"
|
|
1409
|
-
);
|
|
1410
|
-
if (isErrorResult(result)) {
|
|
1411
|
-
let error = result.error;
|
|
1412
|
-
if (pendingError !== void 0) {
|
|
1413
|
-
error = pendingError;
|
|
1414
|
-
pendingError = void 0;
|
|
1415
|
-
}
|
|
1416
|
-
errors = errors || {};
|
|
1417
|
-
if (skipLoaderErrorBubbling) {
|
|
1418
|
-
errors[id] = error;
|
|
1419
|
-
} else {
|
|
1420
|
-
let boundaryMatch = findNearestBoundary(matches, id);
|
|
1421
|
-
if (errors[boundaryMatch.route.id] == null) {
|
|
1422
|
-
errors[boundaryMatch.route.id] = error;
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
loaderData[id] = void 0;
|
|
1426
|
-
if (!foundError) {
|
|
1427
|
-
foundError = true;
|
|
1428
|
-
statusCode = isRouteErrorResponse(result.error) ? result.error.status : 500;
|
|
1429
|
-
}
|
|
1430
|
-
if (result.headers) {
|
|
1431
|
-
loaderHeaders[id] = result.headers;
|
|
1432
|
-
}
|
|
1433
|
-
} else {
|
|
1434
|
-
if (isDeferredResult(result)) {
|
|
1435
|
-
activeDeferreds.set(id, result.deferredData);
|
|
1436
|
-
loaderData[id] = result.deferredData.data;
|
|
1437
|
-
if (result.statusCode != null && result.statusCode !== 200 && !foundError) {
|
|
1438
|
-
statusCode = result.statusCode;
|
|
1439
|
-
}
|
|
1440
|
-
if (result.headers) {
|
|
1441
|
-
loaderHeaders[id] = result.headers;
|
|
1442
|
-
}
|
|
1443
|
-
} else {
|
|
1444
|
-
loaderData[id] = result.data;
|
|
1445
|
-
if (result.statusCode && result.statusCode !== 200 && !foundError) {
|
|
1446
|
-
statusCode = result.statusCode;
|
|
1447
|
-
}
|
|
1448
|
-
if (result.headers) {
|
|
1449
|
-
loaderHeaders[id] = result.headers;
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
});
|
|
1454
|
-
if (pendingError !== void 0 && pendingActionResult) {
|
|
1455
|
-
errors = { [pendingActionResult[0]]: pendingError };
|
|
1456
|
-
loaderData[pendingActionResult[0]] = void 0;
|
|
1457
|
-
}
|
|
1458
|
-
return {
|
|
1459
|
-
loaderData,
|
|
1460
|
-
errors,
|
|
1461
|
-
statusCode: statusCode || 200,
|
|
1462
|
-
loaderHeaders
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
|
-
function findNearestBoundary(matches, routeId) {
|
|
1466
|
-
let eligibleMatches = routeId ? matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1) : [...matches];
|
|
1467
|
-
return eligibleMatches.reverse().find((m) => m.route.hasErrorBoundary === true) || matches[0];
|
|
1468
|
-
}
|
|
1469
|
-
function getShortCircuitMatches(routes) {
|
|
1470
|
-
let route = routes.length === 1 ? routes[0] : routes.find((r) => r.index || !r.path || r.path === "/") || {
|
|
1471
|
-
id: `__shim-error-route__`
|
|
1472
|
-
};
|
|
1473
|
-
return {
|
|
1474
|
-
matches: [
|
|
1475
|
-
{
|
|
1476
|
-
params: {},
|
|
1477
|
-
pathname: "",
|
|
1478
|
-
pathnameBase: "",
|
|
1479
|
-
route
|
|
1480
|
-
}
|
|
1481
|
-
],
|
|
1482
|
-
route
|
|
1483
|
-
};
|
|
1484
|
-
}
|
|
1485
|
-
function getInternalRouterError(status, {
|
|
1486
|
-
pathname,
|
|
1487
|
-
routeId,
|
|
1488
|
-
method,
|
|
1489
|
-
type
|
|
1490
|
-
} = {}) {
|
|
1491
|
-
let statusText = "Unknown Server Error";
|
|
1492
|
-
let errorMessage = "Unknown @remix-run/router error";
|
|
1493
|
-
if (status === 400) {
|
|
1494
|
-
statusText = "Bad Request";
|
|
1495
|
-
if (method && pathname && routeId) {
|
|
1496
|
-
errorMessage = `You made a ${method} request to "${pathname}" but did not provide a \`loader\` for route "${routeId}", so there is no way to handle the request.`;
|
|
1497
|
-
} else if (type === "defer-action") {
|
|
1498
|
-
errorMessage = "defer() is not supported in actions";
|
|
1499
|
-
} else if (type === "invalid-body") {
|
|
1500
|
-
errorMessage = "Unable to encode submission body";
|
|
1501
|
-
}
|
|
1502
|
-
} else if (status === 403) {
|
|
1503
|
-
statusText = "Forbidden";
|
|
1504
|
-
errorMessage = `Route "${routeId}" does not match URL "${pathname}"`;
|
|
1505
|
-
} else if (status === 404) {
|
|
1506
|
-
statusText = "Not Found";
|
|
1507
|
-
errorMessage = `No route matches URL "${pathname}"`;
|
|
1508
|
-
} else if (status === 405) {
|
|
1509
|
-
statusText = "Method Not Allowed";
|
|
1510
|
-
if (method && pathname && routeId) {
|
|
1511
|
-
errorMessage = `You made a ${method.toUpperCase()} request to "${pathname}" but did not provide an \`action\` for route "${routeId}", so there is no way to handle the request.`;
|
|
1512
|
-
} else if (method) {
|
|
1513
|
-
errorMessage = `Invalid request method "${method.toUpperCase()}"`;
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
return new ErrorResponseImpl(
|
|
1517
|
-
status || 500,
|
|
1518
|
-
statusText,
|
|
1519
|
-
new Error(errorMessage),
|
|
1520
|
-
true
|
|
1521
|
-
);
|
|
1522
|
-
}
|
|
1523
|
-
function isHandlerResult(result) {
|
|
1524
|
-
return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === "data" /* data */ || result.type === "error" /* error */);
|
|
1525
|
-
}
|
|
1526
|
-
function isRedirectHandlerResult(result) {
|
|
1527
|
-
return isResponse(result.result) && redirectStatusCodes.has(result.result.status);
|
|
1528
|
-
}
|
|
1529
|
-
function isDeferredResult(result) {
|
|
1530
|
-
return result.type === "deferred" /* deferred */;
|
|
1531
|
-
}
|
|
1532
|
-
function isErrorResult(result) {
|
|
1533
|
-
return result.type === "error" /* error */;
|
|
1534
|
-
}
|
|
1535
|
-
function isRedirectResult(result) {
|
|
1536
|
-
return (result && result.type) === "redirect" /* redirect */;
|
|
1537
|
-
}
|
|
1538
|
-
function isDeferredData(value) {
|
|
1539
|
-
let deferred = value;
|
|
1540
|
-
return deferred && typeof deferred === "object" && typeof deferred.data === "object" && typeof deferred.subscribe === "function" && typeof deferred.cancel === "function" && typeof deferred.resolveData === "function";
|
|
1541
|
-
}
|
|
1542
|
-
function isResponse(value) {
|
|
1543
|
-
return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
|
1544
|
-
}
|
|
1545
|
-
function isRedirectResponse(result) {
|
|
1546
|
-
if (!isResponse(result)) {
|
|
1547
|
-
return false;
|
|
1548
|
-
}
|
|
1549
|
-
let status = result.status;
|
|
1550
|
-
let location = result.headers.get("Location");
|
|
1551
|
-
return status >= 300 && status <= 399 && location != null;
|
|
1552
|
-
}
|
|
1553
|
-
function isValidMethod(method) {
|
|
1554
|
-
return validRequestMethods.has(method.toLowerCase());
|
|
1555
|
-
}
|
|
1556
|
-
function isMutationMethod(method) {
|
|
1557
|
-
return validMutationMethods.has(method.toLowerCase());
|
|
1558
|
-
}
|
|
1559
|
-
function hasNakedIndexQuery(search) {
|
|
1560
|
-
return new URLSearchParams(search).getAll("index").some((v) => v === "");
|
|
1561
|
-
}
|
|
1562
|
-
function getTargetMatch(matches, location) {
|
|
1563
|
-
let search = typeof location === "string" ? parsePath(location).search : location.search;
|
|
1564
|
-
if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
|
|
1565
|
-
return matches[matches.length - 1];
|
|
1566
|
-
}
|
|
1567
|
-
let pathMatches = getPathContributingMatches(matches);
|
|
1568
|
-
return pathMatches[pathMatches.length - 1];
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
// packages/react-router/lib/components.tsx
|
|
1572
|
-
var React = __toESM(require("react"));
|
|
1573
|
-
var ENABLE_DEV_WARNINGS = true;
|
|
1574
|
-
function mapRouteProperties(route) {
|
|
1575
|
-
let updates = {
|
|
1576
|
-
// Note: this check also occurs in createRoutesFromChildren so update
|
|
1577
|
-
// there if you change this -- please and thank you!
|
|
1578
|
-
hasErrorBoundary: route.hasErrorBoundary || route.ErrorBoundary != null || route.errorElement != null
|
|
1579
|
-
};
|
|
1580
|
-
if (route.Component) {
|
|
1581
|
-
if (ENABLE_DEV_WARNINGS) {
|
|
1582
|
-
if (route.element) {
|
|
1583
|
-
warning(
|
|
1584
|
-
false,
|
|
1585
|
-
"You should not include both `Component` and `element` on your route - `Component` will be used."
|
|
1586
|
-
);
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
Object.assign(updates, {
|
|
1590
|
-
element: React.createElement(route.Component),
|
|
1591
|
-
Component: void 0
|
|
1592
|
-
});
|
|
1593
|
-
}
|
|
1594
|
-
if (route.HydrateFallback) {
|
|
1595
|
-
if (ENABLE_DEV_WARNINGS) {
|
|
1596
|
-
if (route.hydrateFallbackElement) {
|
|
1597
|
-
warning(
|
|
1598
|
-
false,
|
|
1599
|
-
"You should not include both `HydrateFallback` and `hydrateFallbackElement` on your route - `HydrateFallback` will be used."
|
|
1600
|
-
);
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
Object.assign(updates, {
|
|
1604
|
-
hydrateFallbackElement: React.createElement(route.HydrateFallback),
|
|
1605
|
-
HydrateFallback: void 0
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1608
|
-
if (route.ErrorBoundary) {
|
|
1609
|
-
if (ENABLE_DEV_WARNINGS) {
|
|
1610
|
-
if (route.errorElement) {
|
|
1611
|
-
warning(
|
|
1612
|
-
false,
|
|
1613
|
-
"You should not include both `ErrorBoundary` and `errorElement` on your route - `ErrorBoundary` will be used."
|
|
1614
|
-
);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
Object.assign(updates, {
|
|
1618
|
-
errorElement: React.createElement(route.ErrorBoundary),
|
|
1619
|
-
ErrorBoundary: void 0
|
|
1620
|
-
});
|
|
1621
|
-
}
|
|
1622
|
-
return updates;
|
|
1623
|
-
}
|
|
1624
|
-
var START_TRANSITION = "startTransition";
|
|
1625
|
-
var startTransitionImpl = React[START_TRANSITION];
|
|
1626
|
-
var neverSettledPromise = new Promise(() => {
|
|
1627
|
-
});
|
|
1628
|
-
|
|
1629
|
-
// packages/react-router/lib/dom/ssr/single-fetch.tsx
|
|
1630
|
-
var React2 = __toESM(require("react"));
|
|
1631
|
-
var import_turbo_stream = require("turbo-stream");
|
|
1632
|
-
var SingleFetchRedirectSymbol = Symbol("SingleFetchRedirect");
|
|
1633
|
-
|
|
1634
|
-
// packages/react-router/lib/dom/server.tsx
|
|
1635
|
-
var React3 = __toESM(require("react"));
|
|
1636
|
-
function createStaticHandler2(routes, opts) {
|
|
1637
|
-
return createStaticHandler(routes, {
|
|
1638
|
-
...opts,
|
|
1639
|
-
mapRouteProperties
|
|
1640
|
-
});
|
|
1641
|
-
}
|