| 1 | "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | var __typeError = (msg) => {
|
| 12 | throw TypeError(msg);
|
| 13 | };
|
| 14 | var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
| 15 | var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
| 16 | var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
| 17 |
|
| 18 |
|
| 19 | var Action = ((Action2) => {
|
| 20 | Action2["Pop"] = "POP";
|
| 21 | Action2["Push"] = "PUSH";
|
| 22 | Action2["Replace"] = "REPLACE";
|
| 23 | return Action2;
|
| 24 | })(Action || {});
|
| 25 | var PopStateEventType = "popstate";
|
| 26 | function isLocation(obj) {
|
| 27 | return typeof obj === "object" && obj != null && "pathname" in obj && "search" in obj && "hash" in obj && "state" in obj && "key" in obj;
|
| 28 | }
|
| 29 | function createMemoryHistory(options = {}) {
|
| 30 | let { initialEntries = ["/"], initialIndex, v5Compat = false } = options;
|
| 31 | let entries;
|
| 32 | entries = initialEntries.map(
|
| 33 | (entry, index2) => createMemoryLocation(
|
| 34 | entry,
|
| 35 | typeof entry === "string" ? null : entry.state,
|
| 36 | index2 === 0 ? "default" : void 0,
|
| 37 | typeof entry === "string" ? void 0 : entry.unstable_mask
|
| 38 | )
|
| 39 | );
|
| 40 | let index = clampIndex(
|
| 41 | initialIndex == null ? entries.length - 1 : initialIndex
|
| 42 | );
|
| 43 | let action = "POP" ;
|
| 44 | let listener = null;
|
| 45 | function clampIndex(n) {
|
| 46 | return Math.min(Math.max(n, 0), entries.length - 1);
|
| 47 | }
|
| 48 | function getCurrentLocation() {
|
| 49 | return entries[index];
|
| 50 | }
|
| 51 | function createMemoryLocation(to, state = null, key, unstable_mask) {
|
| 52 | let location = createLocation(
|
| 53 | entries ? getCurrentLocation().pathname : "/",
|
| 54 | to,
|
| 55 | state,
|
| 56 | key,
|
| 57 | unstable_mask
|
| 58 | );
|
| 59 | warning(
|
| 60 | location.pathname.charAt(0) === "/",
|
| 61 | `relative pathnames are not supported in memory history: ${JSON.stringify(
|
| 62 | to
|
| 63 | )}`
|
| 64 | );
|
| 65 | return location;
|
| 66 | }
|
| 67 | function createHref(to) {
|
| 68 | return typeof to === "string" ? to : createPath(to);
|
| 69 | }
|
| 70 | let history = {
|
| 71 | get index() {
|
| 72 | return index;
|
| 73 | },
|
| 74 | get action() {
|
| 75 | return action;
|
| 76 | },
|
| 77 | get location() {
|
| 78 | return getCurrentLocation();
|
| 79 | },
|
| 80 | createHref,
|
| 81 | createURL(to) {
|
| 82 | return new URL(createHref(to), "http://localhost");
|
| 83 | },
|
| 84 | encodeLocation(to) {
|
| 85 | let path = typeof to === "string" ? parsePath(to) : to;
|
| 86 | return {
|
| 87 | pathname: path.pathname || "",
|
| 88 | search: path.search || "",
|
| 89 | hash: path.hash || ""
|
| 90 | };
|
| 91 | },
|
| 92 | push(to, state) {
|
| 93 | action = "PUSH" ;
|
| 94 | let nextLocation = isLocation(to) ? to : createMemoryLocation(to, state);
|
| 95 | index += 1;
|
| 96 | entries.splice(index, entries.length, nextLocation);
|
| 97 | if (v5Compat && listener) {
|
| 98 | listener({ action, location: nextLocation, delta: 1 });
|
| 99 | }
|
| 100 | },
|
| 101 | replace(to, state) {
|
| 102 | action = "REPLACE" ;
|
| 103 | let nextLocation = isLocation(to) ? to : createMemoryLocation(to, state);
|
| 104 | entries[index] = nextLocation;
|
| 105 | if (v5Compat && listener) {
|
| 106 | listener({ action, location: nextLocation, delta: 0 });
|
| 107 | }
|
| 108 | },
|
| 109 | go(delta) {
|
| 110 | action = "POP" ;
|
| 111 | let nextIndex = clampIndex(index + delta);
|
| 112 | let nextLocation = entries[nextIndex];
|
| 113 | index = nextIndex;
|
| 114 | if (listener) {
|
| 115 | listener({ action, location: nextLocation, delta });
|
| 116 | }
|
| 117 | },
|
| 118 | listen(fn) {
|
| 119 | listener = fn;
|
| 120 | return () => {
|
| 121 | listener = null;
|
| 122 | };
|
| 123 | }
|
| 124 | };
|
| 125 | return history;
|
| 126 | }
|
| 127 | function createBrowserHistory(options = {}) {
|
| 128 | function createBrowserLocation(window2, globalHistory) {
|
| 129 | let maskedLocation = _optionalChain([globalHistory, 'access', _2 => _2.state, 'optionalAccess', _3 => _3.masked]);
|
| 130 | let { pathname, search, hash } = maskedLocation || window2.location;
|
| 131 | return createLocation(
|
| 132 | "",
|
| 133 | { pathname, search, hash },
|
| 134 |
|
| 135 | globalHistory.state && globalHistory.state.usr || null,
|
| 136 | globalHistory.state && globalHistory.state.key || "default",
|
| 137 | maskedLocation ? {
|
| 138 | pathname: window2.location.pathname,
|
| 139 | search: window2.location.search,
|
| 140 | hash: window2.location.hash
|
| 141 | } : void 0
|
| 142 | );
|
| 143 | }
|
| 144 | function createBrowserHref(window2, to) {
|
| 145 | return typeof to === "string" ? to : createPath(to);
|
| 146 | }
|
| 147 | return getUrlBasedHistory(
|
| 148 | createBrowserLocation,
|
| 149 | createBrowserHref,
|
| 150 | null,
|
| 151 | options
|
| 152 | );
|
| 153 | }
|
| 154 | function createHashHistory(options = {}) {
|
| 155 | function createHashLocation(window2, globalHistory) {
|
| 156 | let {
|
| 157 | pathname = "/",
|
| 158 | search = "",
|
| 159 | hash = ""
|
| 160 | } = parsePath(window2.location.hash.substring(1));
|
| 161 | if (!pathname.startsWith("/") && !pathname.startsWith(".")) {
|
| 162 | pathname = "/" + pathname;
|
| 163 | }
|
| 164 | return createLocation(
|
| 165 | "",
|
| 166 | { pathname, search, hash },
|
| 167 |
|
| 168 | globalHistory.state && globalHistory.state.usr || null,
|
| 169 | globalHistory.state && globalHistory.state.key || "default"
|
| 170 | );
|
| 171 | }
|
| 172 | function createHashHref(window2, to) {
|
| 173 | let base = window2.document.querySelector("base");
|
| 174 | let href = "";
|
| 175 | if (base && base.getAttribute("href")) {
|
| 176 | let url = window2.location.href;
|
| 177 | let hashIndex = url.indexOf("#");
|
| 178 | href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
| 179 | }
|
| 180 | return href + "#" + (typeof to === "string" ? to : createPath(to));
|
| 181 | }
|
| 182 | function validateHashLocation(location, to) {
|
| 183 | warning(
|
| 184 | location.pathname.charAt(0) === "/",
|
| 185 | `relative pathnames are not supported in hash history.push(${JSON.stringify(
|
| 186 | to
|
| 187 | )})`
|
| 188 | );
|
| 189 | }
|
| 190 | return getUrlBasedHistory(
|
| 191 | createHashLocation,
|
| 192 | createHashHref,
|
| 193 | validateHashLocation,
|
| 194 | options
|
| 195 | );
|
| 196 | }
|
| 197 | function invariant(value, message) {
|
| 198 | if (value === false || value === null || typeof value === "undefined") {
|
| 199 | throw new Error(message);
|
| 200 | }
|
| 201 | }
|
| 202 | function warning(cond, message) {
|
| 203 | if (!cond) {
|
| 204 | if (typeof console !== "undefined") console.warn(message);
|
| 205 | try {
|
| 206 | throw new Error(message);
|
| 207 | } catch (e) {
|
| 208 | }
|
| 209 | }
|
| 210 | }
|
| 211 | function createKey() {
|
| 212 | return Math.random().toString(36).substring(2, 10);
|
| 213 | }
|
| 214 | function getHistoryState(location, index) {
|
| 215 | return {
|
| 216 | usr: location.state,
|
| 217 | key: location.key,
|
| 218 | idx: index,
|
| 219 | masked: location.unstable_mask ? {
|
| 220 | pathname: location.pathname,
|
| 221 | search: location.search,
|
| 222 | hash: location.hash
|
| 223 | } : void 0
|
| 224 | };
|
| 225 | }
|
| 226 | function createLocation(current, to, state = null, key, unstable_mask) {
|
| 227 | let location = {
|
| 228 | pathname: typeof current === "string" ? current : current.pathname,
|
| 229 | search: "",
|
| 230 | hash: "",
|
| 231 | ...typeof to === "string" ? parsePath(to) : to,
|
| 232 | state,
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 | key: to && to.key || key || createKey(),
|
| 238 | unstable_mask
|
| 239 | };
|
| 240 | return location;
|
| 241 | }
|
| 242 | function createPath({
|
| 243 | pathname = "/",
|
| 244 | search = "",
|
| 245 | hash = ""
|
| 246 | }) {
|
| 247 | if (search && search !== "?")
|
| 248 | pathname += search.charAt(0) === "?" ? search : "?" + search;
|
| 249 | if (hash && hash !== "#")
|
| 250 | pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
|
| 251 | return pathname;
|
| 252 | }
|
| 253 | function parsePath(path) {
|
| 254 | let parsedPath = {};
|
| 255 | if (path) {
|
| 256 | let hashIndex = path.indexOf("#");
|
| 257 | if (hashIndex >= 0) {
|
| 258 | parsedPath.hash = path.substring(hashIndex);
|
| 259 | path = path.substring(0, hashIndex);
|
| 260 | }
|
| 261 | let searchIndex = path.indexOf("?");
|
| 262 | if (searchIndex >= 0) {
|
| 263 | parsedPath.search = path.substring(searchIndex);
|
| 264 | path = path.substring(0, searchIndex);
|
| 265 | }
|
| 266 | if (path) {
|
| 267 | parsedPath.pathname = path;
|
| 268 | }
|
| 269 | }
|
| 270 | return parsedPath;
|
| 271 | }
|
| 272 | function getUrlBasedHistory(getLocation, createHref, validateLocation, options = {}) {
|
| 273 | let { window: window2 = document.defaultView, v5Compat = false } = options;
|
| 274 | let globalHistory = window2.history;
|
| 275 | let action = "POP" ;
|
| 276 | let listener = null;
|
| 277 | let index = getIndex();
|
| 278 | if (index == null) {
|
| 279 | index = 0;
|
| 280 | globalHistory.replaceState({ ...globalHistory.state, idx: index }, "");
|
| 281 | }
|
| 282 | function getIndex() {
|
| 283 | let state = globalHistory.state || { idx: null };
|
| 284 | return state.idx;
|
| 285 | }
|
| 286 | function handlePop() {
|
| 287 | action = "POP" ;
|
| 288 | let nextIndex = getIndex();
|
| 289 | let delta = nextIndex == null ? null : nextIndex - index;
|
| 290 | index = nextIndex;
|
| 291 | if (listener) {
|
| 292 | listener({ action, location: history.location, delta });
|
| 293 | }
|
| 294 | }
|
| 295 | function push(to, state) {
|
| 296 | action = "PUSH" ;
|
| 297 | let location = isLocation(to) ? to : createLocation(history.location, to, state);
|
| 298 | if (validateLocation) validateLocation(location, to);
|
| 299 | index = getIndex() + 1;
|
| 300 | let historyState = getHistoryState(location, index);
|
| 301 | let url = history.createHref(location.unstable_mask || location);
|
| 302 | try {
|
| 303 | globalHistory.pushState(historyState, "", url);
|
| 304 | } catch (error) {
|
| 305 | if (error instanceof DOMException && error.name === "DataCloneError") {
|
| 306 | throw error;
|
| 307 | }
|
| 308 | window2.location.assign(url);
|
| 309 | }
|
| 310 | if (v5Compat && listener) {
|
| 311 | listener({ action, location: history.location, delta: 1 });
|
| 312 | }
|
| 313 | }
|
| 314 | function replace2(to, state) {
|
| 315 | action = "REPLACE" ;
|
| 316 | let location = isLocation(to) ? to : createLocation(history.location, to, state);
|
| 317 | if (validateLocation) validateLocation(location, to);
|
| 318 | index = getIndex();
|
| 319 | let historyState = getHistoryState(location, index);
|
| 320 | let url = history.createHref(location.unstable_mask || location);
|
| 321 | globalHistory.replaceState(historyState, "", url);
|
| 322 | if (v5Compat && listener) {
|
| 323 | listener({ action, location: history.location, delta: 0 });
|
| 324 | }
|
| 325 | }
|
| 326 | function createURL(to) {
|
| 327 | return createBrowserURLImpl(to);
|
| 328 | }
|
| 329 | let history = {
|
| 330 | get action() {
|
| 331 | return action;
|
| 332 | },
|
| 333 | get location() {
|
| 334 | return getLocation(window2, globalHistory);
|
| 335 | },
|
| 336 | listen(fn) {
|
| 337 | if (listener) {
|
| 338 | throw new Error("A history only accepts one active listener");
|
| 339 | }
|
| 340 | window2.addEventListener(PopStateEventType, handlePop);
|
| 341 | listener = fn;
|
| 342 | return () => {
|
| 343 | window2.removeEventListener(PopStateEventType, handlePop);
|
| 344 | listener = null;
|
| 345 | };
|
| 346 | },
|
| 347 | createHref(to) {
|
| 348 | return createHref(window2, to);
|
| 349 | },
|
| 350 | createURL,
|
| 351 | encodeLocation(to) {
|
| 352 | let url = createURL(to);
|
| 353 | return {
|
| 354 | pathname: url.pathname,
|
| 355 | search: url.search,
|
| 356 | hash: url.hash
|
| 357 | };
|
| 358 | },
|
| 359 | push,
|
| 360 | replace: replace2,
|
| 361 | go(n) {
|
| 362 | return globalHistory.go(n);
|
| 363 | }
|
| 364 | };
|
| 365 | return history;
|
| 366 | }
|
| 367 | function createBrowserURLImpl(to, isAbsolute = false) {
|
| 368 | let base = "http://localhost";
|
| 369 | if (typeof window !== "undefined") {
|
| 370 | base = window.location.origin !== "null" ? window.location.origin : window.location.href;
|
| 371 | }
|
| 372 | invariant(base, "No window.location.(origin|href) available to create URL");
|
| 373 | let href = typeof to === "string" ? to : createPath(to);
|
| 374 | href = href.replace(/ $/, "%20");
|
| 375 | if (!isAbsolute && href.startsWith("//")) {
|
| 376 | href = base + href;
|
| 377 | }
|
| 378 | return new URL(href, base);
|
| 379 | }
|
| 380 |
|
| 381 |
|
| 382 | function createContext(defaultValue) {
|
| 383 | return { defaultValue };
|
| 384 | }
|
| 385 | var _map;
|
| 386 | var RouterContextProvider = class {
|
| 387 | |
| 388 | |
| 389 | |
| 390 |
|
| 391 | constructor(init) {
|
| 392 | __privateAdd(this, _map, new Map());
|
| 393 | if (init) {
|
| 394 | for (let [context, value] of init) {
|
| 395 | this.set(context, value);
|
| 396 | }
|
| 397 | }
|
| 398 | }
|
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 |
|
| 407 | get(context) {
|
| 408 | if (__privateGet(this, _map).has(context)) {
|
| 409 | return __privateGet(this, _map).get(context);
|
| 410 | }
|
| 411 | if (context.defaultValue !== void 0) {
|
| 412 | return context.defaultValue;
|
| 413 | }
|
| 414 | throw new Error("No value found for context");
|
| 415 | }
|
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 |
|
| 424 | set(context, value) {
|
| 425 | __privateGet(this, _map).set(context, value);
|
| 426 | }
|
| 427 | };
|
| 428 | _map = new WeakMap();
|
| 429 | var unsupportedLazyRouteObjectKeys = new Set([
|
| 430 | "lazy",
|
| 431 | "caseSensitive",
|
| 432 | "path",
|
| 433 | "id",
|
| 434 | "index",
|
| 435 | "children"
|
| 436 | ]);
|
| 437 | function isUnsupportedLazyRouteObjectKey(key) {
|
| 438 | return unsupportedLazyRouteObjectKeys.has(
|
| 439 | key
|
| 440 | );
|
| 441 | }
|
| 442 | var unsupportedLazyRouteFunctionKeys = new Set([
|
| 443 | "lazy",
|
| 444 | "caseSensitive",
|
| 445 | "path",
|
| 446 | "id",
|
| 447 | "index",
|
| 448 | "middleware",
|
| 449 | "children"
|
| 450 | ]);
|
| 451 | function isUnsupportedLazyRouteFunctionKey(key) {
|
| 452 | return unsupportedLazyRouteFunctionKeys.has(
|
| 453 | key
|
| 454 | );
|
| 455 | }
|
| 456 | function isIndexRoute(route) {
|
| 457 | return route.index === true;
|
| 458 | }
|
| 459 | function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [], manifest = {}, allowInPlaceMutations = false) {
|
| 460 | return routes.map((route, index) => {
|
| 461 | let treePath = [...parentPath, String(index)];
|
| 462 | let id = typeof route.id === "string" ? route.id : treePath.join("-");
|
| 463 | invariant(
|
| 464 | route.index !== true || !route.children,
|
| 465 | `Cannot specify children on an index route`
|
| 466 | );
|
| 467 | invariant(
|
| 468 | allowInPlaceMutations || !manifest[id],
|
| 469 | `Found a route id collision on id "${id}". Route id's must be globally unique within Data Router usages`
|
| 470 | );
|
| 471 | if (isIndexRoute(route)) {
|
| 472 | let indexRoute = {
|
| 473 | ...route,
|
| 474 | id
|
| 475 | };
|
| 476 | manifest[id] = mergeRouteUpdates(
|
| 477 | indexRoute,
|
| 478 | mapRouteProperties2(indexRoute)
|
| 479 | );
|
| 480 | return indexRoute;
|
| 481 | } else {
|
| 482 | let pathOrLayoutRoute = {
|
| 483 | ...route,
|
| 484 | id,
|
| 485 | children: void 0
|
| 486 | };
|
| 487 | manifest[id] = mergeRouteUpdates(
|
| 488 | pathOrLayoutRoute,
|
| 489 | mapRouteProperties2(pathOrLayoutRoute)
|
| 490 | );
|
| 491 | if (route.children) {
|
| 492 | pathOrLayoutRoute.children = convertRoutesToDataRoutes(
|
| 493 | route.children,
|
| 494 | mapRouteProperties2,
|
| 495 | treePath,
|
| 496 | manifest,
|
| 497 | allowInPlaceMutations
|
| 498 | );
|
| 499 | }
|
| 500 | return pathOrLayoutRoute;
|
| 501 | }
|
| 502 | });
|
| 503 | }
|
| 504 | function mergeRouteUpdates(route, updates) {
|
| 505 | return Object.assign(route, {
|
| 506 | ...updates,
|
| 507 | ...typeof updates.lazy === "object" && updates.lazy != null ? {
|
| 508 | lazy: {
|
| 509 | ...route.lazy,
|
| 510 | ...updates.lazy
|
| 511 | }
|
| 512 | } : {}
|
| 513 | });
|
| 514 | }
|
| 515 | function matchRoutes(routes, locationArg, basename = "/") {
|
| 516 | return matchRoutesImpl(routes, locationArg, basename, false);
|
| 517 | }
|
| 518 | function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
|
| 519 | let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
| 520 | let pathname = stripBasename(location.pathname || "/", basename);
|
| 521 | if (pathname == null) {
|
| 522 | return null;
|
| 523 | }
|
| 524 | let branches = flattenRoutes(routes);
|
| 525 | rankRouteBranches(branches);
|
| 526 | let matches = null;
|
| 527 | for (let i = 0; matches == null && i < branches.length; ++i) {
|
| 528 | let decoded = decodePath(pathname);
|
| 529 | matches = matchRouteBranch(
|
| 530 | branches[i],
|
| 531 | decoded,
|
| 532 | allowPartial
|
| 533 | );
|
| 534 | }
|
| 535 | return matches;
|
| 536 | }
|
| 537 | function convertRouteMatchToUiMatch(match, loaderData) {
|
| 538 | let { route, pathname, params } = match;
|
| 539 | return {
|
| 540 | id: route.id,
|
| 541 | pathname,
|
| 542 | params,
|
| 543 | data: loaderData[route.id],
|
| 544 | loaderData: loaderData[route.id],
|
| 545 | handle: route.handle
|
| 546 | };
|
| 547 | }
|
| 548 | function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
|
| 549 | let flattenRoute = (route, index, hasParentOptionalSegments = _hasParentOptionalSegments, relativePath) => {
|
| 550 | let meta = {
|
| 551 | relativePath: relativePath === void 0 ? route.path || "" : relativePath,
|
| 552 | caseSensitive: route.caseSensitive === true,
|
| 553 | childrenIndex: index,
|
| 554 | route
|
| 555 | };
|
| 556 | if (meta.relativePath.startsWith("/")) {
|
| 557 | if (!meta.relativePath.startsWith(parentPath) && hasParentOptionalSegments) {
|
| 558 | return;
|
| 559 | }
|
| 560 | invariant(
|
| 561 | meta.relativePath.startsWith(parentPath),
|
| 562 | `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.`
|
| 563 | );
|
| 564 | meta.relativePath = meta.relativePath.slice(parentPath.length);
|
| 565 | }
|
| 566 | let path = joinPaths([parentPath, meta.relativePath]);
|
| 567 | let routesMeta = parentsMeta.concat(meta);
|
| 568 | if (route.children && route.children.length > 0) {
|
| 569 | invariant(
|
| 570 |
|
| 571 |
|
| 572 | route.index !== true,
|
| 573 | `Index routes must not have child routes. Please remove all child routes from route path "${path}".`
|
| 574 | );
|
| 575 | flattenRoutes(
|
| 576 | route.children,
|
| 577 | branches,
|
| 578 | routesMeta,
|
| 579 | path,
|
| 580 | hasParentOptionalSegments
|
| 581 | );
|
| 582 | }
|
| 583 | if (route.path == null && !route.index) {
|
| 584 | return;
|
| 585 | }
|
| 586 | branches.push({
|
| 587 | path,
|
| 588 | score: computeScore(path, route.index),
|
| 589 | routesMeta
|
| 590 | });
|
| 591 | };
|
| 592 | routes.forEach((route, index) => {
|
| 593 | if (route.path === "" || !_optionalChain([route, 'access', _4 => _4.path, 'optionalAccess', _5 => _5.includes, 'call', _6 => _6("?")])) {
|
| 594 | flattenRoute(route, index);
|
| 595 | } else {
|
| 596 | for (let exploded of explodeOptionalSegments(route.path)) {
|
| 597 | flattenRoute(route, index, true, exploded);
|
| 598 | }
|
| 599 | }
|
| 600 | });
|
| 601 | return branches;
|
| 602 | }
|
| 603 | function explodeOptionalSegments(path) {
|
| 604 | let segments = path.split("/");
|
| 605 | if (segments.length === 0) return [];
|
| 606 | let [first, ...rest] = segments;
|
| 607 | let isOptional = first.endsWith("?");
|
| 608 | let required = first.replace(/\?$/, "");
|
| 609 | if (rest.length === 0) {
|
| 610 | return isOptional ? [required, ""] : [required];
|
| 611 | }
|
| 612 | let restExploded = explodeOptionalSegments(rest.join("/"));
|
| 613 | let result = [];
|
| 614 | result.push(
|
| 615 | ...restExploded.map(
|
| 616 | (subpath) => subpath === "" ? required : [required, subpath].join("/")
|
| 617 | )
|
| 618 | );
|
| 619 | if (isOptional) {
|
| 620 | result.push(...restExploded);
|
| 621 | }
|
| 622 | return result.map(
|
| 623 | (exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded
|
| 624 | );
|
| 625 | }
|
| 626 | function rankRouteBranches(branches) {
|
| 627 | branches.sort(
|
| 628 | (a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(
|
| 629 | a.routesMeta.map((meta) => meta.childrenIndex),
|
| 630 | b.routesMeta.map((meta) => meta.childrenIndex)
|
| 631 | )
|
| 632 | );
|
| 633 | }
|
| 634 | var paramRe = /^:[\w-]+$/;
|
| 635 | var dynamicSegmentValue = 3;
|
| 636 | var indexRouteValue = 2;
|
| 637 | var emptySegmentValue = 1;
|
| 638 | var staticSegmentValue = 10;
|
| 639 | var splatPenalty = -2;
|
| 640 | var isSplat = (s) => s === "*";
|
| 641 | function computeScore(path, index) {
|
| 642 | let segments = path.split("/");
|
| 643 | let initialScore = segments.length;
|
| 644 | if (segments.some(isSplat)) {
|
| 645 | initialScore += splatPenalty;
|
| 646 | }
|
| 647 | if (index) {
|
| 648 | initialScore += indexRouteValue;
|
| 649 | }
|
| 650 | return segments.filter((s) => !isSplat(s)).reduce(
|
| 651 | (score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue),
|
| 652 | initialScore
|
| 653 | );
|
| 654 | }
|
| 655 | function compareIndexes(a, b) {
|
| 656 | let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
|
| 657 | return siblings ? (
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 | a[a.length - 1] - b[b.length - 1]
|
| 663 | ) : (
|
| 664 |
|
| 665 |
|
| 666 | 0
|
| 667 | );
|
| 668 | }
|
| 669 | function matchRouteBranch(branch, pathname, allowPartial = false) {
|
| 670 | let { routesMeta } = branch;
|
| 671 | let matchedParams = {};
|
| 672 | let matchedPathname = "/";
|
| 673 | let matches = [];
|
| 674 | for (let i = 0; i < routesMeta.length; ++i) {
|
| 675 | let meta = routesMeta[i];
|
| 676 | let end = i === routesMeta.length - 1;
|
| 677 | let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
|
| 678 | let match = matchPath(
|
| 679 | { path: meta.relativePath, caseSensitive: meta.caseSensitive, end },
|
| 680 | remainingPathname
|
| 681 | );
|
| 682 | let route = meta.route;
|
| 683 | if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
|
| 684 | match = matchPath(
|
| 685 | {
|
| 686 | path: meta.relativePath,
|
| 687 | caseSensitive: meta.caseSensitive,
|
| 688 | end: false
|
| 689 | },
|
| 690 | remainingPathname
|
| 691 | );
|
| 692 | }
|
| 693 | if (!match) {
|
| 694 | return null;
|
| 695 | }
|
| 696 | Object.assign(matchedParams, match.params);
|
| 697 | matches.push({
|
| 698 |
|
| 699 | params: matchedParams,
|
| 700 | pathname: joinPaths([matchedPathname, match.pathname]),
|
| 701 | pathnameBase: normalizePathname(
|
| 702 | joinPaths([matchedPathname, match.pathnameBase])
|
| 703 | ),
|
| 704 | route
|
| 705 | });
|
| 706 | if (match.pathnameBase !== "/") {
|
| 707 | matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
| 708 | }
|
| 709 | }
|
| 710 | return matches;
|
| 711 | }
|
| 712 | function generatePath(originalPath, params = {}) {
|
| 713 | let path = originalPath;
|
| 714 | if (path.endsWith("*") && path !== "*" && !path.endsWith("/*")) {
|
| 715 | warning(
|
| 716 | false,
|
| 717 | `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(/\*$/, "/*")}".`
|
| 718 | );
|
| 719 | path = path.replace(/\*$/, "/*");
|
| 720 | }
|
| 721 | const prefix = path.startsWith("/") ? "/" : "";
|
| 722 | const stringify2 = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
|
| 723 | const segments = path.split(/\/+/).map((segment, index, array) => {
|
| 724 | const isLastSegment = index === array.length - 1;
|
| 725 | if (isLastSegment && segment === "*") {
|
| 726 | const star = "*";
|
| 727 | return stringify2(params[star]);
|
| 728 | }
|
| 729 | const keyMatch = segment.match(/^:([\w-]+)(\??)(.*)/);
|
| 730 | if (keyMatch) {
|
| 731 | const [, key, optional, suffix] = keyMatch;
|
| 732 | let param = params[key];
|
| 733 | invariant(optional === "?" || param != null, `Missing ":${key}" param`);
|
| 734 | return encodeURIComponent(stringify2(param)) + suffix;
|
| 735 | }
|
| 736 | return segment.replace(/\?$/g, "");
|
| 737 | }).filter((segment) => !!segment);
|
| 738 | return prefix + segments.join("/");
|
| 739 | }
|
| 740 | function matchPath(pattern, pathname) {
|
| 741 | if (typeof pattern === "string") {
|
| 742 | pattern = { path: pattern, caseSensitive: false, end: true };
|
| 743 | }
|
| 744 | let [matcher, compiledParams] = compilePath(
|
| 745 | pattern.path,
|
| 746 | pattern.caseSensitive,
|
| 747 | pattern.end
|
| 748 | );
|
| 749 | let match = pathname.match(matcher);
|
| 750 | if (!match) return null;
|
| 751 | let matchedPathname = match[0];
|
| 752 | let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
|
| 753 | let captureGroups = match.slice(1);
|
| 754 | let params = compiledParams.reduce(
|
| 755 | (memo2, { paramName, isOptional }, index) => {
|
| 756 | if (paramName === "*") {
|
| 757 | let splatValue = captureGroups[index] || "";
|
| 758 | pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
|
| 759 | }
|
| 760 | const value = captureGroups[index];
|
| 761 | if (isOptional && !value) {
|
| 762 | memo2[paramName] = void 0;
|
| 763 | } else {
|
| 764 | memo2[paramName] = (value || "").replace(/%2F/g, "/");
|
| 765 | }
|
| 766 | return memo2;
|
| 767 | },
|
| 768 | {}
|
| 769 | );
|
| 770 | return {
|
| 771 | params,
|
| 772 | pathname: matchedPathname,
|
| 773 | pathnameBase,
|
| 774 | pattern
|
| 775 | };
|
| 776 | }
|
| 777 | function compilePath(path, caseSensitive = false, end = true) {
|
| 778 | warning(
|
| 779 | path === "*" || !path.endsWith("*") || path.endsWith("/*"),
|
| 780 | `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(/\*$/, "/*")}".`
|
| 781 | );
|
| 782 | let params = [];
|
| 783 | let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
|
| 784 | /\/:([\w-]+)(\?)?/g,
|
| 785 | (match, paramName, isOptional, index, str) => {
|
| 786 | params.push({ paramName, isOptional: isOptional != null });
|
| 787 | if (isOptional) {
|
| 788 | let nextChar = str.charAt(index + match.length);
|
| 789 | if (nextChar && nextChar !== "/") {
|
| 790 | return "/([^\\/]*)";
|
| 791 | }
|
| 792 | return "(?:/([^\\/]*))?";
|
| 793 | }
|
| 794 | return "/([^\\/]+)";
|
| 795 | }
|
| 796 | ).replace(/\/([\w-]+)\?(\/|$)/g, "(/$1)?$2");
|
| 797 | if (path.endsWith("*")) {
|
| 798 | params.push({ paramName: "*" });
|
| 799 | regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
|
| 800 | } else if (end) {
|
| 801 | regexpSource += "\\/*$";
|
| 802 | } else if (path !== "" && path !== "/") {
|
| 803 | regexpSource += "(?:(?=\\/|$))";
|
| 804 | } else {
|
| 805 | }
|
| 806 | let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
|
| 807 | return [matcher, params];
|
| 808 | }
|
| 809 | function decodePath(value) {
|
| 810 | try {
|
| 811 | return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
|
| 812 | } catch (error) {
|
| 813 | warning(
|
| 814 | false,
|
| 815 | `The URL path "${value}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${error}).`
|
| 816 | );
|
| 817 | return value;
|
| 818 | }
|
| 819 | }
|
| 820 | function stripBasename(pathname, basename) {
|
| 821 | if (basename === "/") return pathname;
|
| 822 | if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
|
| 823 | return null;
|
| 824 | }
|
| 825 | let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
|
| 826 | let nextChar = pathname.charAt(startIndex);
|
| 827 | if (nextChar && nextChar !== "/") {
|
| 828 | return null;
|
| 829 | }
|
| 830 | return pathname.slice(startIndex) || "/";
|
| 831 | }
|
| 832 | function prependBasename({
|
| 833 | basename,
|
| 834 | pathname
|
| 835 | }) {
|
| 836 | return pathname === "/" ? basename : joinPaths([basename, pathname]);
|
| 837 | }
|
| 838 | var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
| 839 | var isAbsoluteUrl = (url) => ABSOLUTE_URL_REGEX.test(url);
|
| 840 | function resolvePath(to, fromPathname = "/") {
|
| 841 | let {
|
| 842 | pathname: toPathname,
|
| 843 | search = "",
|
| 844 | hash = ""
|
| 845 | } = typeof to === "string" ? parsePath(to) : to;
|
| 846 | let pathname;
|
| 847 | if (toPathname) {
|
| 848 | toPathname = removeDoubleSlashes(toPathname);
|
| 849 | if (toPathname.startsWith("/")) {
|
| 850 | pathname = resolvePathname(toPathname.substring(1), "/");
|
| 851 | } else {
|
| 852 | pathname = resolvePathname(toPathname, fromPathname);
|
| 853 | }
|
| 854 | } else {
|
| 855 | pathname = fromPathname;
|
| 856 | }
|
| 857 | return {
|
| 858 | pathname,
|
| 859 | search: normalizeSearch(search),
|
| 860 | hash: normalizeHash(hash)
|
| 861 | };
|
| 862 | }
|
| 863 | function resolvePathname(relativePath, fromPathname) {
|
| 864 | let segments = removeTrailingSlash(fromPathname).split("/");
|
| 865 | let relativeSegments = relativePath.split("/");
|
| 866 | relativeSegments.forEach((segment) => {
|
| 867 | if (segment === "..") {
|
| 868 | if (segments.length > 1) segments.pop();
|
| 869 | } else if (segment !== ".") {
|
| 870 | segments.push(segment);
|
| 871 | }
|
| 872 | });
|
| 873 | return segments.length > 1 ? segments.join("/") : "/";
|
| 874 | }
|
| 875 | function getInvalidPathError(char, field, dest, path) {
|
| 876 | return `Cannot include a '${char}' character in a manually specified \`to.${field}\` field [${JSON.stringify(
|
| 877 | path
|
| 878 | )}]. 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.`;
|
| 879 | }
|
| 880 | function getPathContributingMatches(matches) {
|
| 881 | return matches.filter(
|
| 882 | (match, index) => index === 0 || match.route.path && match.route.path.length > 0
|
| 883 | );
|
| 884 | }
|
| 885 | function getResolveToMatches(matches) {
|
| 886 | let pathMatches = getPathContributingMatches(matches);
|
| 887 | return pathMatches.map(
|
| 888 | (match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
|
| 889 | );
|
| 890 | }
|
| 891 | function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = false) {
|
| 892 | let to;
|
| 893 | if (typeof toArg === "string") {
|
| 894 | to = parsePath(toArg);
|
| 895 | } else {
|
| 896 | to = { ...toArg };
|
| 897 | invariant(
|
| 898 | !to.pathname || !to.pathname.includes("?"),
|
| 899 | getInvalidPathError("?", "pathname", "search", to)
|
| 900 | );
|
| 901 | invariant(
|
| 902 | !to.pathname || !to.pathname.includes("#"),
|
| 903 | getInvalidPathError("#", "pathname", "hash", to)
|
| 904 | );
|
| 905 | invariant(
|
| 906 | !to.search || !to.search.includes("#"),
|
| 907 | getInvalidPathError("#", "search", "hash", to)
|
| 908 | );
|
| 909 | }
|
| 910 | let isEmptyPath = toArg === "" || to.pathname === "";
|
| 911 | let toPathname = isEmptyPath ? "/" : to.pathname;
|
| 912 | let from;
|
| 913 | if (toPathname == null) {
|
| 914 | from = locationPathname;
|
| 915 | } else {
|
| 916 | let routePathnameIndex = routePathnames.length - 1;
|
| 917 | if (!isPathRelative && toPathname.startsWith("..")) {
|
| 918 | let toSegments = toPathname.split("/");
|
| 919 | while (toSegments[0] === "..") {
|
| 920 | toSegments.shift();
|
| 921 | routePathnameIndex -= 1;
|
| 922 | }
|
| 923 | to.pathname = toSegments.join("/");
|
| 924 | }
|
| 925 | from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
| 926 | }
|
| 927 | let path = resolvePath(to, from);
|
| 928 | let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
|
| 929 | let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
|
| 930 | if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
|
| 931 | path.pathname += "/";
|
| 932 | }
|
| 933 | return path;
|
| 934 | }
|
| 935 | var removeDoubleSlashes = (path) => path.replace(/\/\/+/g, "/");
|
| 936 | var joinPaths = (paths) => removeDoubleSlashes(paths.join("/"));
|
| 937 | var removeTrailingSlash = (path) => path.replace(/\/+$/, "");
|
| 938 | var normalizePathname = (pathname) => removeTrailingSlash(pathname).replace(/^\/*/, "/");
|
| 939 | var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
|
| 940 | var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
|
| 941 | var DataWithResponseInit = class {
|
| 942 | constructor(data2, init) {
|
| 943 | this.type = "DataWithResponseInit";
|
| 944 | this.data = data2;
|
| 945 | this.init = init || null;
|
| 946 | }
|
| 947 | };
|
| 948 | function data(data2, init) {
|
| 949 | return new DataWithResponseInit(
|
| 950 | data2,
|
| 951 | typeof init === "number" ? { status: init } : init
|
| 952 | );
|
| 953 | }
|
| 954 | var redirect = (url, init = 302) => {
|
| 955 | let responseInit = init;
|
| 956 | if (typeof responseInit === "number") {
|
| 957 | responseInit = { status: responseInit };
|
| 958 | } else if (typeof responseInit.status === "undefined") {
|
| 959 | responseInit.status = 302;
|
| 960 | }
|
| 961 | let headers = new Headers(responseInit.headers);
|
| 962 | headers.set("Location", url);
|
| 963 | return new Response(null, { ...responseInit, headers });
|
| 964 | };
|
| 965 | var redirectDocument = (url, init) => {
|
| 966 | let response = redirect(url, init);
|
| 967 | response.headers.set("X-Remix-Reload-Document", "true");
|
| 968 | return response;
|
| 969 | };
|
| 970 | var replace = (url, init) => {
|
| 971 | let response = redirect(url, init);
|
| 972 | response.headers.set("X-Remix-Replace", "true");
|
| 973 | return response;
|
| 974 | };
|
| 975 | var ErrorResponseImpl = class {
|
| 976 | constructor(status, statusText, data2, internal = false) {
|
| 977 | this.status = status;
|
| 978 | this.statusText = statusText || "";
|
| 979 | this.internal = internal;
|
| 980 | if (data2 instanceof Error) {
|
| 981 | this.data = data2.toString();
|
| 982 | this.error = data2;
|
| 983 | } else {
|
| 984 | this.data = data2;
|
| 985 | }
|
| 986 | }
|
| 987 | };
|
| 988 | function isRouteErrorResponse(error) {
|
| 989 | return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
| 990 | }
|
| 991 | function getRoutePattern(matches) {
|
| 992 | let parts = matches.map((m) => m.route.path).filter(Boolean);
|
| 993 | return joinPaths(parts) || "/";
|
| 994 | }
|
| 995 | var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
| 996 | function parseToInfo(_to, basename) {
|
| 997 | let to = _to;
|
| 998 | if (typeof to !== "string" || !ABSOLUTE_URL_REGEX.test(to)) {
|
| 999 | return {
|
| 1000 | absoluteURL: void 0,
|
| 1001 | isExternal: false,
|
| 1002 | to
|
| 1003 | };
|
| 1004 | }
|
| 1005 | let absoluteURL = to;
|
| 1006 | let isExternal = false;
|
| 1007 | if (isBrowser) {
|
| 1008 | try {
|
| 1009 | let currentUrl = new URL(window.location.href);
|
| 1010 | let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
|
| 1011 | let path = stripBasename(targetUrl.pathname, basename);
|
| 1012 | if (targetUrl.origin === currentUrl.origin && path != null) {
|
| 1013 | to = path + targetUrl.search + targetUrl.hash;
|
| 1014 | } else {
|
| 1015 | isExternal = true;
|
| 1016 | }
|
| 1017 | } catch (e) {
|
| 1018 | warning(
|
| 1019 | false,
|
| 1020 | `<Link to="${to}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
|
| 1021 | );
|
| 1022 | }
|
| 1023 | }
|
| 1024 | return {
|
| 1025 | absoluteURL,
|
| 1026 | isExternal,
|
| 1027 | to
|
| 1028 | };
|
| 1029 | }
|
| 1030 |
|
| 1031 |
|
| 1032 | var UninstrumentedSymbol = Symbol("Uninstrumented");
|
| 1033 | function getRouteInstrumentationUpdates(fns, route) {
|
| 1034 | let aggregated = {
|
| 1035 | lazy: [],
|
| 1036 | "lazy.loader": [],
|
| 1037 | "lazy.action": [],
|
| 1038 | "lazy.middleware": [],
|
| 1039 | middleware: [],
|
| 1040 | loader: [],
|
| 1041 | action: []
|
| 1042 | };
|
| 1043 | fns.forEach(
|
| 1044 | (fn) => fn({
|
| 1045 | id: route.id,
|
| 1046 | index: route.index,
|
| 1047 | path: route.path,
|
| 1048 | instrument(i) {
|
| 1049 | let keys = Object.keys(aggregated);
|
| 1050 | for (let key of keys) {
|
| 1051 | if (i[key]) {
|
| 1052 | aggregated[key].push(i[key]);
|
| 1053 | }
|
| 1054 | }
|
| 1055 | }
|
| 1056 | })
|
| 1057 | );
|
| 1058 | let updates = {};
|
| 1059 | if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
|
| 1060 | let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
|
| 1061 | if (instrumented) {
|
| 1062 | updates.lazy = instrumented;
|
| 1063 | }
|
| 1064 | }
|
| 1065 | if (typeof route.lazy === "object") {
|
| 1066 | let lazyObject = route.lazy;
|
| 1067 | ["middleware", "loader", "action"].forEach((key) => {
|
| 1068 | let lazyFn = lazyObject[key];
|
| 1069 | let instrumentations = aggregated[`lazy.${key}`];
|
| 1070 | if (typeof lazyFn === "function" && instrumentations.length > 0) {
|
| 1071 | let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
|
| 1072 | if (instrumented) {
|
| 1073 | updates.lazy = Object.assign(updates.lazy || {}, {
|
| 1074 | [key]: instrumented
|
| 1075 | });
|
| 1076 | }
|
| 1077 | }
|
| 1078 | });
|
| 1079 | }
|
| 1080 | ["loader", "action"].forEach((key) => {
|
| 1081 | let handler = route[key];
|
| 1082 | if (typeof handler === "function" && aggregated[key].length > 0) {
|
| 1083 | let original = _nullishCoalesce(handler[UninstrumentedSymbol], () => ( handler));
|
| 1084 | let instrumented = wrapImpl(
|
| 1085 | aggregated[key],
|
| 1086 | original,
|
| 1087 | (...args) => getHandlerInfo(args[0])
|
| 1088 | );
|
| 1089 | if (instrumented) {
|
| 1090 | if (key === "loader" && original.hydrate === true) {
|
| 1091 | instrumented.hydrate = true;
|
| 1092 | }
|
| 1093 | instrumented[UninstrumentedSymbol] = original;
|
| 1094 | updates[key] = instrumented;
|
| 1095 | }
|
| 1096 | }
|
| 1097 | });
|
| 1098 | if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) {
|
| 1099 | updates.middleware = route.middleware.map((middleware) => {
|
| 1100 | let original = _nullishCoalesce(middleware[UninstrumentedSymbol], () => ( middleware));
|
| 1101 | let instrumented = wrapImpl(
|
| 1102 | aggregated.middleware,
|
| 1103 | original,
|
| 1104 | (...args) => getHandlerInfo(args[0])
|
| 1105 | );
|
| 1106 | if (instrumented) {
|
| 1107 | instrumented[UninstrumentedSymbol] = original;
|
| 1108 | return instrumented;
|
| 1109 | }
|
| 1110 | return middleware;
|
| 1111 | });
|
| 1112 | }
|
| 1113 | return updates;
|
| 1114 | }
|
| 1115 | function instrumentClientSideRouter(router, fns) {
|
| 1116 | let aggregated = {
|
| 1117 | navigate: [],
|
| 1118 | fetch: []
|
| 1119 | };
|
| 1120 | fns.forEach(
|
| 1121 | (fn) => fn({
|
| 1122 | instrument(i) {
|
| 1123 | let keys = Object.keys(i);
|
| 1124 | for (let key of keys) {
|
| 1125 | if (i[key]) {
|
| 1126 | aggregated[key].push(i[key]);
|
| 1127 | }
|
| 1128 | }
|
| 1129 | }
|
| 1130 | })
|
| 1131 | );
|
| 1132 | if (aggregated.navigate.length > 0) {
|
| 1133 | let navigate = _nullishCoalesce(router.navigate[UninstrumentedSymbol], () => ( router.navigate));
|
| 1134 | let instrumentedNavigate = wrapImpl(
|
| 1135 | aggregated.navigate,
|
| 1136 | navigate,
|
| 1137 | (...args) => {
|
| 1138 | let [to, opts] = args;
|
| 1139 | return {
|
| 1140 | to: typeof to === "number" || typeof to === "string" ? to : to ? createPath(to) : ".",
|
| 1141 | ...getRouterInfo(router, _nullishCoalesce(opts, () => ( {})))
|
| 1142 | };
|
| 1143 | }
|
| 1144 | );
|
| 1145 | if (instrumentedNavigate) {
|
| 1146 | instrumentedNavigate[UninstrumentedSymbol] = navigate;
|
| 1147 | router.navigate = instrumentedNavigate;
|
| 1148 | }
|
| 1149 | }
|
| 1150 | if (aggregated.fetch.length > 0) {
|
| 1151 | let fetch2 = _nullishCoalesce(router.fetch[UninstrumentedSymbol], () => ( router.fetch));
|
| 1152 | let instrumentedFetch = wrapImpl(aggregated.fetch, fetch2, (...args) => {
|
| 1153 | let [key, , href, opts] = args;
|
| 1154 | return {
|
| 1155 | href: _nullishCoalesce(href, () => ( ".")),
|
| 1156 | fetcherKey: key,
|
| 1157 | ...getRouterInfo(router, _nullishCoalesce(opts, () => ( {})))
|
| 1158 | };
|
| 1159 | });
|
| 1160 | if (instrumentedFetch) {
|
| 1161 | instrumentedFetch[UninstrumentedSymbol] = fetch2;
|
| 1162 | router.fetch = instrumentedFetch;
|
| 1163 | }
|
| 1164 | }
|
| 1165 | return router;
|
| 1166 | }
|
| 1167 | function instrumentHandler(handler, fns) {
|
| 1168 | let aggregated = {
|
| 1169 | request: []
|
| 1170 | };
|
| 1171 | fns.forEach(
|
| 1172 | (fn) => fn({
|
| 1173 | instrument(i) {
|
| 1174 | let keys = Object.keys(i);
|
| 1175 | for (let key of keys) {
|
| 1176 | if (i[key]) {
|
| 1177 | aggregated[key].push(i[key]);
|
| 1178 | }
|
| 1179 | }
|
| 1180 | }
|
| 1181 | })
|
| 1182 | );
|
| 1183 | let instrumentedHandler = handler;
|
| 1184 | if (aggregated.request.length > 0) {
|
| 1185 | instrumentedHandler = wrapImpl(aggregated.request, handler, (...args) => {
|
| 1186 | let [request, context] = args;
|
| 1187 | return {
|
| 1188 | request: getReadonlyRequest(request),
|
| 1189 | context: context != null ? getReadonlyContext(context) : context
|
| 1190 | };
|
| 1191 | });
|
| 1192 | }
|
| 1193 | return instrumentedHandler;
|
| 1194 | }
|
| 1195 | function wrapImpl(impls, handler, getInfo) {
|
| 1196 | if (impls.length === 0) {
|
| 1197 | return null;
|
| 1198 | }
|
| 1199 | return async (...args) => {
|
| 1200 | let result = await recurseRight(
|
| 1201 | impls,
|
| 1202 | getInfo(...args),
|
| 1203 | () => handler(...args),
|
| 1204 | impls.length - 1
|
| 1205 | );
|
| 1206 | if (result.type === "error") {
|
| 1207 | throw result.value;
|
| 1208 | }
|
| 1209 | return result.value;
|
| 1210 | };
|
| 1211 | }
|
| 1212 | async function recurseRight(impls, info, handler, index) {
|
| 1213 | let impl = impls[index];
|
| 1214 | let result;
|
| 1215 | if (!impl) {
|
| 1216 | try {
|
| 1217 | let value = await handler();
|
| 1218 | result = { type: "success", value };
|
| 1219 | } catch (e) {
|
| 1220 | result = { type: "error", value: e };
|
| 1221 | }
|
| 1222 | } else {
|
| 1223 | let handlerPromise = void 0;
|
| 1224 | let callHandler = async () => {
|
| 1225 | if (handlerPromise) {
|
| 1226 | console.error("You cannot call instrumented handlers more than once");
|
| 1227 | } else {
|
| 1228 | handlerPromise = recurseRight(impls, info, handler, index - 1);
|
| 1229 | }
|
| 1230 | result = await handlerPromise;
|
| 1231 | invariant(result, "Expected a result");
|
| 1232 | if (result.type === "error" && result.value instanceof Error) {
|
| 1233 | return { status: "error", error: result.value };
|
| 1234 | }
|
| 1235 | return { status: "success", error: void 0 };
|
| 1236 | };
|
| 1237 | try {
|
| 1238 | await impl(callHandler, info);
|
| 1239 | } catch (e) {
|
| 1240 | console.error("An instrumentation function threw an error:", e);
|
| 1241 | }
|
| 1242 | if (!handlerPromise) {
|
| 1243 | await callHandler();
|
| 1244 | }
|
| 1245 | await handlerPromise;
|
| 1246 | }
|
| 1247 | if (result) {
|
| 1248 | return result;
|
| 1249 | }
|
| 1250 | return {
|
| 1251 | type: "error",
|
| 1252 | value: new Error("No result assigned in instrumentation chain.")
|
| 1253 | };
|
| 1254 | }
|
| 1255 | function getHandlerInfo(args) {
|
| 1256 | let { request, context, params, unstable_pattern } = args;
|
| 1257 | return {
|
| 1258 | request: getReadonlyRequest(request),
|
| 1259 | params: { ...params },
|
| 1260 | unstable_pattern,
|
| 1261 | context: getReadonlyContext(context)
|
| 1262 | };
|
| 1263 | }
|
| 1264 | function getRouterInfo(router, opts) {
|
| 1265 | return {
|
| 1266 | currentUrl: createPath(router.state.location),
|
| 1267 | ..."formMethod" in opts ? { formMethod: opts.formMethod } : {},
|
| 1268 | ..."formEncType" in opts ? { formEncType: opts.formEncType } : {},
|
| 1269 | ..."formData" in opts ? { formData: opts.formData } : {},
|
| 1270 | ..."body" in opts ? { body: opts.body } : {}
|
| 1271 | };
|
| 1272 | }
|
| 1273 | function getReadonlyRequest(request) {
|
| 1274 | return {
|
| 1275 | method: request.method,
|
| 1276 | url: request.url,
|
| 1277 | headers: {
|
| 1278 | get: (...args) => request.headers.get(...args)
|
| 1279 | }
|
| 1280 | };
|
| 1281 | }
|
| 1282 | function getReadonlyContext(context) {
|
| 1283 | if (isPlainObject(context)) {
|
| 1284 | let frozen = { ...context };
|
| 1285 | Object.freeze(frozen);
|
| 1286 | return frozen;
|
| 1287 | } else {
|
| 1288 | return {
|
| 1289 | get: (ctx) => context.get(ctx)
|
| 1290 | };
|
| 1291 | }
|
| 1292 | }
|
| 1293 | var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
| 1294 | function isPlainObject(thing) {
|
| 1295 | if (thing === null || typeof thing !== "object") {
|
| 1296 | return false;
|
| 1297 | }
|
| 1298 | const proto = Object.getPrototypeOf(thing);
|
| 1299 | return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
|
| 1300 | }
|
| 1301 |
|
| 1302 |
|
| 1303 | var validMutationMethodsArr = [
|
| 1304 | "POST",
|
| 1305 | "PUT",
|
| 1306 | "PATCH",
|
| 1307 | "DELETE"
|
| 1308 | ];
|
| 1309 | var validMutationMethods = new Set(
|
| 1310 | validMutationMethodsArr
|
| 1311 | );
|
| 1312 | var validRequestMethodsArr = [
|
| 1313 | "GET",
|
| 1314 | ...validMutationMethodsArr
|
| 1315 | ];
|
| 1316 | var validRequestMethods = new Set(validRequestMethodsArr);
|
| 1317 | var redirectStatusCodes = new Set([301, 302, 303, 307, 308]);
|
| 1318 | var redirectPreserveMethodStatusCodes = new Set([307, 308]);
|
| 1319 | var IDLE_NAVIGATION = {
|
| 1320 | state: "idle",
|
| 1321 | location: void 0,
|
| 1322 | formMethod: void 0,
|
| 1323 | formAction: void 0,
|
| 1324 | formEncType: void 0,
|
| 1325 | formData: void 0,
|
| 1326 | json: void 0,
|
| 1327 | text: void 0
|
| 1328 | };
|
| 1329 | var IDLE_FETCHER = {
|
| 1330 | state: "idle",
|
| 1331 | data: void 0,
|
| 1332 | formMethod: void 0,
|
| 1333 | formAction: void 0,
|
| 1334 | formEncType: void 0,
|
| 1335 | formData: void 0,
|
| 1336 | json: void 0,
|
| 1337 | text: void 0
|
| 1338 | };
|
| 1339 | var IDLE_BLOCKER = {
|
| 1340 | state: "unblocked",
|
| 1341 | proceed: void 0,
|
| 1342 | reset: void 0,
|
| 1343 | location: void 0
|
| 1344 | };
|
| 1345 | var defaultMapRouteProperties = (route) => ({
|
| 1346 | hasErrorBoundary: Boolean(route.hasErrorBoundary)
|
| 1347 | });
|
| 1348 | var TRANSITIONS_STORAGE_KEY = "remix-router-transitions";
|
| 1349 | var ResetLoaderDataSymbol = Symbol("ResetLoaderData");
|
| 1350 | function createRouter(init) {
|
| 1351 | const routerWindow = init.window ? init.window : typeof window !== "undefined" ? window : void 0;
|
| 1352 | const isBrowser2 = typeof routerWindow !== "undefined" && typeof routerWindow.document !== "undefined" && typeof routerWindow.document.createElement !== "undefined";
|
| 1353 | invariant(
|
| 1354 | init.routes.length > 0,
|
| 1355 | "You must provide a non-empty routes array to createRouter"
|
| 1356 | );
|
| 1357 | let hydrationRouteProperties2 = init.hydrationRouteProperties || [];
|
| 1358 | let _mapRouteProperties = init.mapRouteProperties || defaultMapRouteProperties;
|
| 1359 | let mapRouteProperties2 = _mapRouteProperties;
|
| 1360 | if (init.unstable_instrumentations) {
|
| 1361 | let instrumentations = init.unstable_instrumentations;
|
| 1362 | mapRouteProperties2 = (route) => {
|
| 1363 | return {
|
| 1364 | ..._mapRouteProperties(route),
|
| 1365 | ...getRouteInstrumentationUpdates(
|
| 1366 | instrumentations.map((i) => i.route).filter(Boolean),
|
| 1367 | route
|
| 1368 | )
|
| 1369 | };
|
| 1370 | };
|
| 1371 | }
|
| 1372 | let manifest = {};
|
| 1373 | let dataRoutes = convertRoutesToDataRoutes(
|
| 1374 | init.routes,
|
| 1375 | mapRouteProperties2,
|
| 1376 | void 0,
|
| 1377 | manifest
|
| 1378 | );
|
| 1379 | let inFlightDataRoutes;
|
| 1380 | let basename = init.basename || "/";
|
| 1381 | if (!basename.startsWith("/")) {
|
| 1382 | basename = `/${basename}`;
|
| 1383 | }
|
| 1384 | let dataStrategyImpl = init.dataStrategy || defaultDataStrategyWithMiddleware;
|
| 1385 | let future = {
|
| 1386 | unstable_passThroughRequests: false,
|
| 1387 | ...init.future
|
| 1388 | };
|
| 1389 | let unlistenHistory = null;
|
| 1390 | let subscribers = new Set();
|
| 1391 | let savedScrollPositions = null;
|
| 1392 | let getScrollRestorationKey = null;
|
| 1393 | let getScrollPosition = null;
|
| 1394 | let initialScrollRestored = init.hydrationData != null;
|
| 1395 | let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
|
| 1396 | let initialMatchesIsFOW = false;
|
| 1397 | let initialErrors = null;
|
| 1398 | let initialized;
|
| 1399 | let renderFallback;
|
| 1400 | if (initialMatches == null && !init.patchRoutesOnNavigation) {
|
| 1401 | let error = getInternalRouterError(404, {
|
| 1402 | pathname: init.history.location.pathname
|
| 1403 | });
|
| 1404 | let { matches, route } = getShortCircuitMatches(dataRoutes);
|
| 1405 | initialized = true;
|
| 1406 | renderFallback = !initialized;
|
| 1407 | initialMatches = matches;
|
| 1408 | initialErrors = { [route.id]: error };
|
| 1409 | } else {
|
| 1410 | if (initialMatches && !init.hydrationData) {
|
| 1411 | let fogOfWar = checkFogOfWar(
|
| 1412 | initialMatches,
|
| 1413 | dataRoutes,
|
| 1414 | init.history.location.pathname
|
| 1415 | );
|
| 1416 | if (fogOfWar.active) {
|
| 1417 | initialMatches = null;
|
| 1418 | }
|
| 1419 | }
|
| 1420 | if (!initialMatches) {
|
| 1421 | initialized = false;
|
| 1422 | renderFallback = !initialized;
|
| 1423 | initialMatches = [];
|
| 1424 | let fogOfWar = checkFogOfWar(
|
| 1425 | null,
|
| 1426 | dataRoutes,
|
| 1427 | init.history.location.pathname
|
| 1428 | );
|
| 1429 | if (fogOfWar.active && fogOfWar.matches) {
|
| 1430 | initialMatchesIsFOW = true;
|
| 1431 | initialMatches = fogOfWar.matches;
|
| 1432 | }
|
| 1433 | } else if (initialMatches.some((m) => m.route.lazy)) {
|
| 1434 | initialized = false;
|
| 1435 | renderFallback = !initialized;
|
| 1436 | } else if (!initialMatches.some((m) => routeHasLoaderOrMiddleware(m.route))) {
|
| 1437 | initialized = true;
|
| 1438 | renderFallback = !initialized;
|
| 1439 | } else {
|
| 1440 | let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
|
| 1441 | let errors = init.hydrationData ? init.hydrationData.errors : null;
|
| 1442 | let relevantMatches = initialMatches;
|
| 1443 | if (errors) {
|
| 1444 | let idx = initialMatches.findIndex(
|
| 1445 | (m) => errors[m.route.id] !== void 0
|
| 1446 | );
|
| 1447 | relevantMatches = relevantMatches.slice(0, idx + 1);
|
| 1448 | }
|
| 1449 | renderFallback = false;
|
| 1450 | initialized = true;
|
| 1451 | relevantMatches.forEach((m) => {
|
| 1452 | let status = getRouteHydrationStatus(m.route, loaderData, errors);
|
| 1453 | renderFallback = renderFallback || status.renderFallback;
|
| 1454 | initialized = initialized && !status.shouldLoad;
|
| 1455 | });
|
| 1456 | }
|
| 1457 | }
|
| 1458 | let router;
|
| 1459 | let state = {
|
| 1460 | historyAction: init.history.action,
|
| 1461 | location: init.history.location,
|
| 1462 | matches: initialMatches,
|
| 1463 | initialized,
|
| 1464 | renderFallback,
|
| 1465 | navigation: IDLE_NAVIGATION,
|
| 1466 |
|
| 1467 | restoreScrollPosition: init.hydrationData != null ? false : null,
|
| 1468 | preventScrollReset: false,
|
| 1469 | revalidation: "idle",
|
| 1470 | loaderData: init.hydrationData && init.hydrationData.loaderData || {},
|
| 1471 | actionData: init.hydrationData && init.hydrationData.actionData || null,
|
| 1472 | errors: init.hydrationData && init.hydrationData.errors || initialErrors,
|
| 1473 | fetchers: new Map(),
|
| 1474 | blockers: new Map()
|
| 1475 | };
|
| 1476 | let pendingAction = "POP" ;
|
| 1477 | let pendingPopstateNavigationDfd = null;
|
| 1478 | let pendingPreventScrollReset = false;
|
| 1479 | let pendingNavigationController;
|
| 1480 | let pendingViewTransitionEnabled = false;
|
| 1481 | let appliedViewTransitions = new Map();
|
| 1482 | let removePageHideEventListener = null;
|
| 1483 | let isUninterruptedRevalidation = false;
|
| 1484 | let isRevalidationRequired = false;
|
| 1485 | let cancelledFetcherLoads = new Set();
|
| 1486 | let fetchControllers = new Map();
|
| 1487 | let incrementingLoadId = 0;
|
| 1488 | let pendingNavigationLoadId = -1;
|
| 1489 | let fetchReloadIds = new Map();
|
| 1490 | let fetchRedirectIds = new Set();
|
| 1491 | let fetchLoadMatches = new Map();
|
| 1492 | let activeFetchers = new Map();
|
| 1493 | let fetchersQueuedForDeletion = new Set();
|
| 1494 | let blockerFunctions = new Map();
|
| 1495 | let unblockBlockerHistoryUpdate = void 0;
|
| 1496 | let pendingRevalidationDfd = null;
|
| 1497 | function initialize() {
|
| 1498 | unlistenHistory = init.history.listen(
|
| 1499 | ({ action: historyAction, location, delta }) => {
|
| 1500 | if (unblockBlockerHistoryUpdate) {
|
| 1501 | unblockBlockerHistoryUpdate();
|
| 1502 | unblockBlockerHistoryUpdate = void 0;
|
| 1503 | return;
|
| 1504 | }
|
| 1505 | warning(
|
| 1506 | blockerFunctions.size === 0 || delta != null,
|
| 1507 | "You are trying to use a blocker on a POP navigation to a location that was not created by @remix-run/router. This will fail silently in production. This can happen if you are navigating outside the router via `window.history.pushState`/`window.location.hash` instead of using router navigation APIs. This can also happen if you are using createHashRouter and the user manually changes the URL."
|
| 1508 | );
|
| 1509 | let blockerKey = shouldBlockNavigation({
|
| 1510 | currentLocation: state.location,
|
| 1511 | nextLocation: location,
|
| 1512 | historyAction
|
| 1513 | });
|
| 1514 | if (blockerKey && delta != null) {
|
| 1515 | let nextHistoryUpdatePromise = new Promise((resolve) => {
|
| 1516 | unblockBlockerHistoryUpdate = resolve;
|
| 1517 | });
|
| 1518 | init.history.go(delta * -1);
|
| 1519 | updateBlocker(blockerKey, {
|
| 1520 | state: "blocked",
|
| 1521 | location,
|
| 1522 | proceed() {
|
| 1523 | updateBlocker(blockerKey, {
|
| 1524 | state: "proceeding",
|
| 1525 | proceed: void 0,
|
| 1526 | reset: void 0,
|
| 1527 | location
|
| 1528 | });
|
| 1529 | nextHistoryUpdatePromise.then(() => init.history.go(delta));
|
| 1530 | },
|
| 1531 | reset() {
|
| 1532 | let blockers = new Map(state.blockers);
|
| 1533 | blockers.set(blockerKey, IDLE_BLOCKER);
|
| 1534 | updateState({ blockers });
|
| 1535 | }
|
| 1536 | });
|
| 1537 | _optionalChain([pendingPopstateNavigationDfd, 'optionalAccess', _7 => _7.resolve, 'call', _8 => _8()]);
|
| 1538 | pendingPopstateNavigationDfd = null;
|
| 1539 | return;
|
| 1540 | }
|
| 1541 | return startNavigation(historyAction, location);
|
| 1542 | }
|
| 1543 | );
|
| 1544 | if (isBrowser2) {
|
| 1545 | restoreAppliedTransitions(routerWindow, appliedViewTransitions);
|
| 1546 | let _saveAppliedTransitions = () => persistAppliedTransitions(routerWindow, appliedViewTransitions);
|
| 1547 | routerWindow.addEventListener("pagehide", _saveAppliedTransitions);
|
| 1548 | removePageHideEventListener = () => routerWindow.removeEventListener("pagehide", _saveAppliedTransitions);
|
| 1549 | }
|
| 1550 | if (!state.initialized) {
|
| 1551 | startNavigation("POP" , state.location, {
|
| 1552 | initialHydration: true
|
| 1553 | });
|
| 1554 | }
|
| 1555 | return router;
|
| 1556 | }
|
| 1557 | function dispose() {
|
| 1558 | if (unlistenHistory) {
|
| 1559 | unlistenHistory();
|
| 1560 | }
|
| 1561 | if (removePageHideEventListener) {
|
| 1562 | removePageHideEventListener();
|
| 1563 | }
|
| 1564 | subscribers.clear();
|
| 1565 | pendingNavigationController && pendingNavigationController.abort();
|
| 1566 | state.fetchers.forEach((_, key) => deleteFetcher(key));
|
| 1567 | state.blockers.forEach((_, key) => deleteBlocker(key));
|
| 1568 | }
|
| 1569 | function subscribe(fn) {
|
| 1570 | subscribers.add(fn);
|
| 1571 | return () => subscribers.delete(fn);
|
| 1572 | }
|
| 1573 | function updateState(newState, opts = {}) {
|
| 1574 | if (newState.matches) {
|
| 1575 | newState.matches = newState.matches.map((m) => {
|
| 1576 | let route = manifest[m.route.id];
|
| 1577 | let matchRoute = m.route;
|
| 1578 | if (matchRoute.element !== route.element || matchRoute.errorElement !== route.errorElement || matchRoute.hydrateFallbackElement !== route.hydrateFallbackElement) {
|
| 1579 | return {
|
| 1580 | ...m,
|
| 1581 | route
|
| 1582 | };
|
| 1583 | }
|
| 1584 | return m;
|
| 1585 | });
|
| 1586 | }
|
| 1587 | state = {
|
| 1588 | ...state,
|
| 1589 | ...newState
|
| 1590 | };
|
| 1591 | let unmountedFetchers = [];
|
| 1592 | let mountedFetchers = [];
|
| 1593 | state.fetchers.forEach((fetcher, key) => {
|
| 1594 | if (fetcher.state === "idle") {
|
| 1595 | if (fetchersQueuedForDeletion.has(key)) {
|
| 1596 | unmountedFetchers.push(key);
|
| 1597 | } else {
|
| 1598 | mountedFetchers.push(key);
|
| 1599 | }
|
| 1600 | }
|
| 1601 | });
|
| 1602 | fetchersQueuedForDeletion.forEach((key) => {
|
| 1603 | if (!state.fetchers.has(key) && !fetchControllers.has(key)) {
|
| 1604 | unmountedFetchers.push(key);
|
| 1605 | }
|
| 1606 | });
|
| 1607 | [...subscribers].forEach(
|
| 1608 | (subscriber) => subscriber(state, {
|
| 1609 | deletedFetchers: unmountedFetchers,
|
| 1610 | newErrors: _nullishCoalesce(newState.errors, () => ( null)),
|
| 1611 | viewTransitionOpts: opts.viewTransitionOpts,
|
| 1612 | flushSync: opts.flushSync === true
|
| 1613 | })
|
| 1614 | );
|
| 1615 | unmountedFetchers.forEach((key) => deleteFetcher(key));
|
| 1616 | mountedFetchers.forEach((key) => state.fetchers.delete(key));
|
| 1617 | }
|
| 1618 | function completeNavigation(location, newState, { flushSync } = {}) {
|
| 1619 | let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && _optionalChain([location, 'access', _9 => _9.state, 'optionalAccess', _10 => _10._isRedirect]) !== true;
|
| 1620 | let actionData;
|
| 1621 | if (newState.actionData) {
|
| 1622 | if (Object.keys(newState.actionData).length > 0) {
|
| 1623 | actionData = newState.actionData;
|
| 1624 | } else {
|
| 1625 | actionData = null;
|
| 1626 | }
|
| 1627 | } else if (isActionReload) {
|
| 1628 | actionData = state.actionData;
|
| 1629 | } else {
|
| 1630 | actionData = null;
|
| 1631 | }
|
| 1632 | let loaderData = newState.loaderData ? mergeLoaderData(
|
| 1633 | state.loaderData,
|
| 1634 | newState.loaderData,
|
| 1635 | newState.matches || [],
|
| 1636 | newState.errors
|
| 1637 | ) : state.loaderData;
|
| 1638 | let blockers = state.blockers;
|
| 1639 | if (blockers.size > 0) {
|
| 1640 | blockers = new Map(blockers);
|
| 1641 | blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER));
|
| 1642 | }
|
| 1643 | let restoreScrollPosition = isUninterruptedRevalidation ? false : getSavedScrollPosition(location, newState.matches || state.matches);
|
| 1644 | let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && _optionalChain([location, 'access', _11 => _11.state, 'optionalAccess', _12 => _12._isRedirect]) !== true;
|
| 1645 | if (inFlightDataRoutes) {
|
| 1646 | dataRoutes = inFlightDataRoutes;
|
| 1647 | inFlightDataRoutes = void 0;
|
| 1648 | }
|
| 1649 | if (isUninterruptedRevalidation) {
|
| 1650 | } else if (pendingAction === "POP" ) {
|
| 1651 | } else if (pendingAction === "PUSH" ) {
|
| 1652 | init.history.push(location, location.state);
|
| 1653 | } else if (pendingAction === "REPLACE" ) {
|
| 1654 | init.history.replace(location, location.state);
|
| 1655 | }
|
| 1656 | let viewTransitionOpts;
|
| 1657 | if (pendingAction === "POP" ) {
|
| 1658 | let priorPaths = appliedViewTransitions.get(state.location.pathname);
|
| 1659 | if (priorPaths && priorPaths.has(location.pathname)) {
|
| 1660 | viewTransitionOpts = {
|
| 1661 | currentLocation: state.location,
|
| 1662 | nextLocation: location
|
| 1663 | };
|
| 1664 | } else if (appliedViewTransitions.has(location.pathname)) {
|
| 1665 | viewTransitionOpts = {
|
| 1666 | currentLocation: location,
|
| 1667 | nextLocation: state.location
|
| 1668 | };
|
| 1669 | }
|
| 1670 | } else if (pendingViewTransitionEnabled) {
|
| 1671 | let toPaths = appliedViewTransitions.get(state.location.pathname);
|
| 1672 | if (toPaths) {
|
| 1673 | toPaths.add(location.pathname);
|
| 1674 | } else {
|
| 1675 | toPaths = new Set([location.pathname]);
|
| 1676 | appliedViewTransitions.set(state.location.pathname, toPaths);
|
| 1677 | }
|
| 1678 | viewTransitionOpts = {
|
| 1679 | currentLocation: state.location,
|
| 1680 | nextLocation: location
|
| 1681 | };
|
| 1682 | }
|
| 1683 | updateState(
|
| 1684 | {
|
| 1685 | ...newState,
|
| 1686 |
|
| 1687 | actionData,
|
| 1688 | loaderData,
|
| 1689 | historyAction: pendingAction,
|
| 1690 | location,
|
| 1691 | initialized: true,
|
| 1692 | renderFallback: false,
|
| 1693 | navigation: IDLE_NAVIGATION,
|
| 1694 | revalidation: "idle",
|
| 1695 | restoreScrollPosition,
|
| 1696 | preventScrollReset,
|
| 1697 | blockers
|
| 1698 | },
|
| 1699 | {
|
| 1700 | viewTransitionOpts,
|
| 1701 | flushSync: flushSync === true
|
| 1702 | }
|
| 1703 | );
|
| 1704 | pendingAction = "POP" ;
|
| 1705 | pendingPreventScrollReset = false;
|
| 1706 | pendingViewTransitionEnabled = false;
|
| 1707 | isUninterruptedRevalidation = false;
|
| 1708 | isRevalidationRequired = false;
|
| 1709 | _optionalChain([pendingPopstateNavigationDfd, 'optionalAccess', _13 => _13.resolve, 'call', _14 => _14()]);
|
| 1710 | pendingPopstateNavigationDfd = null;
|
| 1711 | _optionalChain([pendingRevalidationDfd, 'optionalAccess', _15 => _15.resolve, 'call', _16 => _16()]);
|
| 1712 | pendingRevalidationDfd = null;
|
| 1713 | }
|
| 1714 | async function navigate(to, opts) {
|
| 1715 | _optionalChain([pendingPopstateNavigationDfd, 'optionalAccess', _17 => _17.resolve, 'call', _18 => _18()]);
|
| 1716 | pendingPopstateNavigationDfd = null;
|
| 1717 | if (typeof to === "number") {
|
| 1718 | if (!pendingPopstateNavigationDfd) {
|
| 1719 | pendingPopstateNavigationDfd = createDeferred();
|
| 1720 | }
|
| 1721 | let promise = pendingPopstateNavigationDfd.promise;
|
| 1722 | init.history.go(to);
|
| 1723 | return promise;
|
| 1724 | }
|
| 1725 | let normalizedPath = normalizeTo(
|
| 1726 | state.location,
|
| 1727 | state.matches,
|
| 1728 | basename,
|
| 1729 | to,
|
| 1730 | _optionalChain([opts, 'optionalAccess', _19 => _19.fromRouteId]),
|
| 1731 | _optionalChain([opts, 'optionalAccess', _20 => _20.relative])
|
| 1732 | );
|
| 1733 | let { path, submission, error } = normalizeNavigateOptions(
|
| 1734 | false,
|
| 1735 | normalizedPath,
|
| 1736 | opts
|
| 1737 | );
|
| 1738 | let maskPath;
|
| 1739 | if (_optionalChain([opts, 'optionalAccess', _21 => _21.unstable_mask])) {
|
| 1740 | let partialPath = typeof opts.unstable_mask === "string" ? parsePath(opts.unstable_mask) : {
|
| 1741 | ...state.location.unstable_mask,
|
| 1742 | ...opts.unstable_mask
|
| 1743 | };
|
| 1744 | maskPath = {
|
| 1745 | pathname: "",
|
| 1746 | search: "",
|
| 1747 | hash: "",
|
| 1748 | ...partialPath
|
| 1749 | };
|
| 1750 | }
|
| 1751 | let currentLocation = state.location;
|
| 1752 | let nextLocation = createLocation(
|
| 1753 | currentLocation,
|
| 1754 | path,
|
| 1755 | opts && opts.state,
|
| 1756 | void 0,
|
| 1757 | maskPath
|
| 1758 | );
|
| 1759 | nextLocation = {
|
| 1760 | ...nextLocation,
|
| 1761 | ...init.history.encodeLocation(nextLocation)
|
| 1762 | };
|
| 1763 | let userReplace = opts && opts.replace != null ? opts.replace : void 0;
|
| 1764 | let historyAction = "PUSH" ;
|
| 1765 | if (userReplace === true) {
|
| 1766 | historyAction = "REPLACE" ;
|
| 1767 | } else if (userReplace === false) {
|
| 1768 | } else if (submission != null && isMutationMethod(submission.formMethod) && submission.formAction === state.location.pathname + state.location.search) {
|
| 1769 | historyAction = "REPLACE" ;
|
| 1770 | }
|
| 1771 | let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : void 0;
|
| 1772 | let flushSync = (opts && opts.flushSync) === true;
|
| 1773 | let blockerKey = shouldBlockNavigation({
|
| 1774 | currentLocation,
|
| 1775 | nextLocation,
|
| 1776 | historyAction
|
| 1777 | });
|
| 1778 | if (blockerKey) {
|
| 1779 | updateBlocker(blockerKey, {
|
| 1780 | state: "blocked",
|
| 1781 | location: nextLocation,
|
| 1782 | proceed() {
|
| 1783 | updateBlocker(blockerKey, {
|
| 1784 | state: "proceeding",
|
| 1785 | proceed: void 0,
|
| 1786 | reset: void 0,
|
| 1787 | location: nextLocation
|
| 1788 | });
|
| 1789 | navigate(to, opts);
|
| 1790 | },
|
| 1791 | reset() {
|
| 1792 | let blockers = new Map(state.blockers);
|
| 1793 | blockers.set(blockerKey, IDLE_BLOCKER);
|
| 1794 | updateState({ blockers });
|
| 1795 | }
|
| 1796 | });
|
| 1797 | return;
|
| 1798 | }
|
| 1799 | await startNavigation(historyAction, nextLocation, {
|
| 1800 | submission,
|
| 1801 |
|
| 1802 |
|
| 1803 | pendingError: error,
|
| 1804 | preventScrollReset,
|
| 1805 | replace: opts && opts.replace,
|
| 1806 | enableViewTransition: opts && opts.viewTransition,
|
| 1807 | flushSync,
|
| 1808 | callSiteDefaultShouldRevalidate: opts && opts.unstable_defaultShouldRevalidate
|
| 1809 | });
|
| 1810 | }
|
| 1811 | function revalidate() {
|
| 1812 | if (!pendingRevalidationDfd) {
|
| 1813 | pendingRevalidationDfd = createDeferred();
|
| 1814 | }
|
| 1815 | interruptActiveLoads();
|
| 1816 | updateState({ revalidation: "loading" });
|
| 1817 | let promise = pendingRevalidationDfd.promise;
|
| 1818 | if (state.navigation.state === "submitting") {
|
| 1819 | return promise;
|
| 1820 | }
|
| 1821 | if (state.navigation.state === "idle") {
|
| 1822 | startNavigation(state.historyAction, state.location, {
|
| 1823 | startUninterruptedRevalidation: true
|
| 1824 | });
|
| 1825 | return promise;
|
| 1826 | }
|
| 1827 | startNavigation(
|
| 1828 | pendingAction || state.historyAction,
|
| 1829 | state.navigation.location,
|
| 1830 | {
|
| 1831 | overrideNavigation: state.navigation,
|
| 1832 |
|
| 1833 | enableViewTransition: pendingViewTransitionEnabled === true
|
| 1834 | }
|
| 1835 | );
|
| 1836 | return promise;
|
| 1837 | }
|
| 1838 | async function startNavigation(historyAction, location, opts) {
|
| 1839 | pendingNavigationController && pendingNavigationController.abort();
|
| 1840 | pendingNavigationController = null;
|
| 1841 | pendingAction = historyAction;
|
| 1842 | isUninterruptedRevalidation = (opts && opts.startUninterruptedRevalidation) === true;
|
| 1843 | saveScrollPosition(state.location, state.matches);
|
| 1844 | pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
| 1845 | pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
|
| 1846 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
| 1847 | let loadingNavigation = opts && opts.overrideNavigation;
|
| 1848 | let matches = _optionalChain([opts, 'optionalAccess', _22 => _22.initialHydration]) && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ? (
|
| 1849 |
|
| 1850 | state.matches
|
| 1851 | ) : matchRoutes(routesToUse, location, basename);
|
| 1852 | let flushSync = (opts && opts.flushSync) === true;
|
| 1853 | if (matches && state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
|
| 1854 | completeNavigation(location, { matches }, { flushSync });
|
| 1855 | return;
|
| 1856 | }
|
| 1857 | let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
|
| 1858 | if (fogOfWar.active && fogOfWar.matches) {
|
| 1859 | matches = fogOfWar.matches;
|
| 1860 | }
|
| 1861 | if (!matches) {
|
| 1862 | let { error, notFoundMatches, route } = handleNavigational404(
|
| 1863 | location.pathname
|
| 1864 | );
|
| 1865 | completeNavigation(
|
| 1866 | location,
|
| 1867 | {
|
| 1868 | matches: notFoundMatches,
|
| 1869 | loaderData: {},
|
| 1870 | errors: {
|
| 1871 | [route.id]: error
|
| 1872 | }
|
| 1873 | },
|
| 1874 | { flushSync }
|
| 1875 | );
|
| 1876 | return;
|
| 1877 | }
|
| 1878 | pendingNavigationController = new AbortController();
|
| 1879 | let request = createClientSideRequest(
|
| 1880 | init.history,
|
| 1881 | location,
|
| 1882 | pendingNavigationController.signal,
|
| 1883 | opts && opts.submission
|
| 1884 | );
|
| 1885 | let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
|
| 1886 | let pendingActionResult;
|
| 1887 | if (opts && opts.pendingError) {
|
| 1888 | pendingActionResult = [
|
| 1889 | findNearestBoundary(matches).route.id,
|
| 1890 | { type: "error" , error: opts.pendingError }
|
| 1891 | ];
|
| 1892 | } else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
|
| 1893 | let actionResult = await handleAction(
|
| 1894 | request,
|
| 1895 | location,
|
| 1896 | opts.submission,
|
| 1897 | matches,
|
| 1898 | scopedContext,
|
| 1899 | fogOfWar.active,
|
| 1900 | opts && opts.initialHydration === true,
|
| 1901 | { replace: opts.replace, flushSync }
|
| 1902 | );
|
| 1903 | if (actionResult.shortCircuited) {
|
| 1904 | return;
|
| 1905 | }
|
| 1906 | if (actionResult.pendingActionResult) {
|
| 1907 | let [routeId, result] = actionResult.pendingActionResult;
|
| 1908 | if (isErrorResult(result) && isRouteErrorResponse(result.error) && result.error.status === 404) {
|
| 1909 | pendingNavigationController = null;
|
| 1910 | completeNavigation(location, {
|
| 1911 | matches: actionResult.matches,
|
| 1912 | loaderData: {},
|
| 1913 | errors: {
|
| 1914 | [routeId]: result.error
|
| 1915 | }
|
| 1916 | });
|
| 1917 | return;
|
| 1918 | }
|
| 1919 | }
|
| 1920 | matches = actionResult.matches || matches;
|
| 1921 | pendingActionResult = actionResult.pendingActionResult;
|
| 1922 | loadingNavigation = getLoadingNavigation(location, opts.submission);
|
| 1923 | flushSync = false;
|
| 1924 | fogOfWar.active = false;
|
| 1925 | request = createClientSideRequest(
|
| 1926 | init.history,
|
| 1927 | request.url,
|
| 1928 | request.signal
|
| 1929 | );
|
| 1930 | }
|
| 1931 | let {
|
| 1932 | shortCircuited,
|
| 1933 | matches: updatedMatches,
|
| 1934 | loaderData,
|
| 1935 | errors
|
| 1936 | } = await handleLoaders(
|
| 1937 | request,
|
| 1938 | location,
|
| 1939 | matches,
|
| 1940 | scopedContext,
|
| 1941 | fogOfWar.active,
|
| 1942 | loadingNavigation,
|
| 1943 | opts && opts.submission,
|
| 1944 | opts && opts.fetcherSubmission,
|
| 1945 | opts && opts.replace,
|
| 1946 | opts && opts.initialHydration === true,
|
| 1947 | flushSync,
|
| 1948 | pendingActionResult,
|
| 1949 | opts && opts.callSiteDefaultShouldRevalidate
|
| 1950 | );
|
| 1951 | if (shortCircuited) {
|
| 1952 | return;
|
| 1953 | }
|
| 1954 | pendingNavigationController = null;
|
| 1955 | completeNavigation(location, {
|
| 1956 | matches: updatedMatches || matches,
|
| 1957 | ...getActionDataForCommit(pendingActionResult),
|
| 1958 | loaderData,
|
| 1959 | errors
|
| 1960 | });
|
| 1961 | }
|
| 1962 | async function handleAction(request, location, submission, matches, scopedContext, isFogOfWar, initialHydration, opts = {}) {
|
| 1963 | interruptActiveLoads();
|
| 1964 | let navigation = getSubmittingNavigation(location, submission);
|
| 1965 | updateState({ navigation }, { flushSync: opts.flushSync === true });
|
| 1966 | if (isFogOfWar) {
|
| 1967 | let discoverResult = await discoverRoutes(
|
| 1968 | matches,
|
| 1969 | location.pathname,
|
| 1970 | request.signal
|
| 1971 | );
|
| 1972 | if (discoverResult.type === "aborted") {
|
| 1973 | return { shortCircuited: true };
|
| 1974 | } else if (discoverResult.type === "error") {
|
| 1975 | if (discoverResult.partialMatches.length === 0) {
|
| 1976 | let { matches: matches2, route } = getShortCircuitMatches(dataRoutes);
|
| 1977 | return {
|
| 1978 | matches: matches2,
|
| 1979 | pendingActionResult: [
|
| 1980 | route.id,
|
| 1981 | {
|
| 1982 | type: "error" ,
|
| 1983 | error: discoverResult.error
|
| 1984 | }
|
| 1985 | ]
|
| 1986 | };
|
| 1987 | }
|
| 1988 | let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
|
| 1989 | return {
|
| 1990 | matches: discoverResult.partialMatches,
|
| 1991 | pendingActionResult: [
|
| 1992 | boundaryId,
|
| 1993 | {
|
| 1994 | type: "error" ,
|
| 1995 | error: discoverResult.error
|
| 1996 | }
|
| 1997 | ]
|
| 1998 | };
|
| 1999 | } else if (!discoverResult.matches) {
|
| 2000 | let { notFoundMatches, error, route } = handleNavigational404(
|
| 2001 | location.pathname
|
| 2002 | );
|
| 2003 | return {
|
| 2004 | matches: notFoundMatches,
|
| 2005 | pendingActionResult: [
|
| 2006 | route.id,
|
| 2007 | {
|
| 2008 | type: "error" ,
|
| 2009 | error
|
| 2010 | }
|
| 2011 | ]
|
| 2012 | };
|
| 2013 | } else {
|
| 2014 | matches = discoverResult.matches;
|
| 2015 | }
|
| 2016 | }
|
| 2017 | let result;
|
| 2018 | let actionMatch = getTargetMatch(matches, location);
|
| 2019 | if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
| 2020 | result = {
|
| 2021 | type: "error" ,
|
| 2022 | error: getInternalRouterError(405, {
|
| 2023 | method: request.method,
|
| 2024 | pathname: location.pathname,
|
| 2025 | routeId: actionMatch.route.id
|
| 2026 | })
|
| 2027 | };
|
| 2028 | } else {
|
| 2029 | let dsMatches = getTargetedDataStrategyMatches(
|
| 2030 | mapRouteProperties2,
|
| 2031 | manifest,
|
| 2032 | request,
|
| 2033 | location,
|
| 2034 | matches,
|
| 2035 | actionMatch,
|
| 2036 | initialHydration ? [] : hydrationRouteProperties2,
|
| 2037 | scopedContext
|
| 2038 | );
|
| 2039 | let results = await callDataStrategy(
|
| 2040 | request,
|
| 2041 | location,
|
| 2042 | dsMatches,
|
| 2043 | scopedContext,
|
| 2044 | null
|
| 2045 | );
|
| 2046 | result = results[actionMatch.route.id];
|
| 2047 | if (!result) {
|
| 2048 | for (let match of matches) {
|
| 2049 | if (results[match.route.id]) {
|
| 2050 | result = results[match.route.id];
|
| 2051 | break;
|
| 2052 | }
|
| 2053 | }
|
| 2054 | }
|
| 2055 | if (request.signal.aborted) {
|
| 2056 | return { shortCircuited: true };
|
| 2057 | }
|
| 2058 | }
|
| 2059 | if (isRedirectResult(result)) {
|
| 2060 | let replace2;
|
| 2061 | if (opts && opts.replace != null) {
|
| 2062 | replace2 = opts.replace;
|
| 2063 | } else {
|
| 2064 | let location2 = normalizeRedirectLocation(
|
| 2065 | result.response.headers.get("Location"),
|
| 2066 | new URL(request.url),
|
| 2067 | basename,
|
| 2068 | init.history
|
| 2069 | );
|
| 2070 | replace2 = location2 === state.location.pathname + state.location.search;
|
| 2071 | }
|
| 2072 | await startRedirectNavigation(request, result, true, {
|
| 2073 | submission,
|
| 2074 | replace: replace2
|
| 2075 | });
|
| 2076 | return { shortCircuited: true };
|
| 2077 | }
|
| 2078 | if (isErrorResult(result)) {
|
| 2079 | let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
|
| 2080 | if ((opts && opts.replace) !== true) {
|
| 2081 | pendingAction = "PUSH" ;
|
| 2082 | }
|
| 2083 | return {
|
| 2084 | matches,
|
| 2085 | pendingActionResult: [
|
| 2086 | boundaryMatch.route.id,
|
| 2087 | result,
|
| 2088 | actionMatch.route.id
|
| 2089 | ]
|
| 2090 | };
|
| 2091 | }
|
| 2092 | return {
|
| 2093 | matches,
|
| 2094 | pendingActionResult: [actionMatch.route.id, result]
|
| 2095 | };
|
| 2096 | }
|
| 2097 | async function handleLoaders(request, location, matches, scopedContext, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult, callSiteDefaultShouldRevalidate) {
|
| 2098 | let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
| 2099 | let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
| 2100 | let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
|
| 2101 | if (isFogOfWar) {
|
| 2102 | if (shouldUpdateNavigationState) {
|
| 2103 | let actionData = getUpdatedActionData(pendingActionResult);
|
| 2104 | updateState(
|
| 2105 | {
|
| 2106 | navigation: loadingNavigation,
|
| 2107 | ...actionData !== void 0 ? { actionData } : {}
|
| 2108 | },
|
| 2109 | {
|
| 2110 | flushSync
|
| 2111 | }
|
| 2112 | );
|
| 2113 | }
|
| 2114 | let discoverResult = await discoverRoutes(
|
| 2115 | matches,
|
| 2116 | location.pathname,
|
| 2117 | request.signal
|
| 2118 | );
|
| 2119 | if (discoverResult.type === "aborted") {
|
| 2120 | return { shortCircuited: true };
|
| 2121 | } else if (discoverResult.type === "error") {
|
| 2122 | if (discoverResult.partialMatches.length === 0) {
|
| 2123 | let { matches: matches2, route } = getShortCircuitMatches(dataRoutes);
|
| 2124 | return {
|
| 2125 | matches: matches2,
|
| 2126 | loaderData: {},
|
| 2127 | errors: {
|
| 2128 | [route.id]: discoverResult.error
|
| 2129 | }
|
| 2130 | };
|
| 2131 | }
|
| 2132 | let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
|
| 2133 | return {
|
| 2134 | matches: discoverResult.partialMatches,
|
| 2135 | loaderData: {},
|
| 2136 | errors: {
|
| 2137 | [boundaryId]: discoverResult.error
|
| 2138 | }
|
| 2139 | };
|
| 2140 | } else if (!discoverResult.matches) {
|
| 2141 | let { error, notFoundMatches, route } = handleNavigational404(
|
| 2142 | location.pathname
|
| 2143 | );
|
| 2144 | return {
|
| 2145 | matches: notFoundMatches,
|
| 2146 | loaderData: {},
|
| 2147 | errors: {
|
| 2148 | [route.id]: error
|
| 2149 | }
|
| 2150 | };
|
| 2151 | } else {
|
| 2152 | matches = discoverResult.matches;
|
| 2153 | }
|
| 2154 | }
|
| 2155 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
| 2156 | let { dsMatches, revalidatingFetchers } = getMatchesToLoad(
|
| 2157 | request,
|
| 2158 | scopedContext,
|
| 2159 | mapRouteProperties2,
|
| 2160 | manifest,
|
| 2161 | init.history,
|
| 2162 | state,
|
| 2163 | matches,
|
| 2164 | activeSubmission,
|
| 2165 | location,
|
| 2166 | initialHydration ? [] : hydrationRouteProperties2,
|
| 2167 | initialHydration === true,
|
| 2168 | isRevalidationRequired,
|
| 2169 | cancelledFetcherLoads,
|
| 2170 | fetchersQueuedForDeletion,
|
| 2171 | fetchLoadMatches,
|
| 2172 | fetchRedirectIds,
|
| 2173 | routesToUse,
|
| 2174 | basename,
|
| 2175 | init.patchRoutesOnNavigation != null,
|
| 2176 | pendingActionResult,
|
| 2177 | callSiteDefaultShouldRevalidate
|
| 2178 | );
|
| 2179 | pendingNavigationLoadId = ++incrementingLoadId;
|
| 2180 | if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some(
|
| 2181 | (m) => m.route.middleware && m.route.middleware.length > 0
|
| 2182 | ) && revalidatingFetchers.length === 0) {
|
| 2183 | let updatedFetchers2 = markFetchRedirectsDone();
|
| 2184 | completeNavigation(
|
| 2185 | location,
|
| 2186 | {
|
| 2187 | matches,
|
| 2188 | loaderData: {},
|
| 2189 |
|
| 2190 | errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? { [pendingActionResult[0]]: pendingActionResult[1].error } : null,
|
| 2191 | ...getActionDataForCommit(pendingActionResult),
|
| 2192 | ...updatedFetchers2 ? { fetchers: new Map(state.fetchers) } : {}
|
| 2193 | },
|
| 2194 | { flushSync }
|
| 2195 | );
|
| 2196 | return { shortCircuited: true };
|
| 2197 | }
|
| 2198 | if (shouldUpdateNavigationState) {
|
| 2199 | let updates = {};
|
| 2200 | if (!isFogOfWar) {
|
| 2201 | updates.navigation = loadingNavigation;
|
| 2202 | let actionData = getUpdatedActionData(pendingActionResult);
|
| 2203 | if (actionData !== void 0) {
|
| 2204 | updates.actionData = actionData;
|
| 2205 | }
|
| 2206 | }
|
| 2207 | if (revalidatingFetchers.length > 0) {
|
| 2208 | updates.fetchers = getUpdatedRevalidatingFetchers(revalidatingFetchers);
|
| 2209 | }
|
| 2210 | updateState(updates, { flushSync });
|
| 2211 | }
|
| 2212 | revalidatingFetchers.forEach((rf) => {
|
| 2213 | abortFetcher(rf.key);
|
| 2214 | if (rf.controller) {
|
| 2215 | fetchControllers.set(rf.key, rf.controller);
|
| 2216 | }
|
| 2217 | });
|
| 2218 | let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((f) => abortFetcher(f.key));
|
| 2219 | if (pendingNavigationController) {
|
| 2220 | pendingNavigationController.signal.addEventListener(
|
| 2221 | "abort",
|
| 2222 | abortPendingFetchRevalidations
|
| 2223 | );
|
| 2224 | }
|
| 2225 | let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
| 2226 | dsMatches,
|
| 2227 | revalidatingFetchers,
|
| 2228 | request,
|
| 2229 | location,
|
| 2230 | scopedContext
|
| 2231 | );
|
| 2232 | if (request.signal.aborted) {
|
| 2233 | return { shortCircuited: true };
|
| 2234 | }
|
| 2235 | if (pendingNavigationController) {
|
| 2236 | pendingNavigationController.signal.removeEventListener(
|
| 2237 | "abort",
|
| 2238 | abortPendingFetchRevalidations
|
| 2239 | );
|
| 2240 | }
|
| 2241 | revalidatingFetchers.forEach((rf) => fetchControllers.delete(rf.key));
|
| 2242 | let redirect2 = findRedirect(loaderResults);
|
| 2243 | if (redirect2) {
|
| 2244 | await startRedirectNavigation(request, redirect2.result, true, {
|
| 2245 | replace: replace2
|
| 2246 | });
|
| 2247 | return { shortCircuited: true };
|
| 2248 | }
|
| 2249 | redirect2 = findRedirect(fetcherResults);
|
| 2250 | if (redirect2) {
|
| 2251 | fetchRedirectIds.add(redirect2.key);
|
| 2252 | await startRedirectNavigation(request, redirect2.result, true, {
|
| 2253 | replace: replace2
|
| 2254 | });
|
| 2255 | return { shortCircuited: true };
|
| 2256 | }
|
| 2257 | let { loaderData, errors } = processLoaderData(
|
| 2258 | state,
|
| 2259 | matches,
|
| 2260 | loaderResults,
|
| 2261 | pendingActionResult,
|
| 2262 | revalidatingFetchers,
|
| 2263 | fetcherResults
|
| 2264 | );
|
| 2265 | if (initialHydration && state.errors) {
|
| 2266 | errors = { ...state.errors, ...errors };
|
| 2267 | }
|
| 2268 | let updatedFetchers = markFetchRedirectsDone();
|
| 2269 | let didAbortFetchLoads = abortStaleFetchLoads(pendingNavigationLoadId);
|
| 2270 | let shouldUpdateFetchers = updatedFetchers || didAbortFetchLoads || revalidatingFetchers.length > 0;
|
| 2271 | return {
|
| 2272 | matches,
|
| 2273 | loaderData,
|
| 2274 | errors,
|
| 2275 | ...shouldUpdateFetchers ? { fetchers: new Map(state.fetchers) } : {}
|
| 2276 | };
|
| 2277 | }
|
| 2278 | function getUpdatedActionData(pendingActionResult) {
|
| 2279 | if (pendingActionResult && !isErrorResult(pendingActionResult[1])) {
|
| 2280 | return {
|
| 2281 | [pendingActionResult[0]]: pendingActionResult[1].data
|
| 2282 | };
|
| 2283 | } else if (state.actionData) {
|
| 2284 | if (Object.keys(state.actionData).length === 0) {
|
| 2285 | return null;
|
| 2286 | } else {
|
| 2287 | return state.actionData;
|
| 2288 | }
|
| 2289 | }
|
| 2290 | }
|
| 2291 | function getUpdatedRevalidatingFetchers(revalidatingFetchers) {
|
| 2292 | revalidatingFetchers.forEach((rf) => {
|
| 2293 | let fetcher = state.fetchers.get(rf.key);
|
| 2294 | let revalidatingFetcher = getLoadingFetcher(
|
| 2295 | void 0,
|
| 2296 | fetcher ? fetcher.data : void 0
|
| 2297 | );
|
| 2298 | state.fetchers.set(rf.key, revalidatingFetcher);
|
| 2299 | });
|
| 2300 | return new Map(state.fetchers);
|
| 2301 | }
|
| 2302 | async function fetch2(key, routeId, href, opts) {
|
| 2303 | abortFetcher(key);
|
| 2304 | let flushSync = (opts && opts.flushSync) === true;
|
| 2305 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
| 2306 | let normalizedPath = normalizeTo(
|
| 2307 | state.location,
|
| 2308 | state.matches,
|
| 2309 | basename,
|
| 2310 | href,
|
| 2311 | routeId,
|
| 2312 | _optionalChain([opts, 'optionalAccess', _23 => _23.relative])
|
| 2313 | );
|
| 2314 | let matches = matchRoutes(routesToUse, normalizedPath, basename);
|
| 2315 | let fogOfWar = checkFogOfWar(matches, routesToUse, normalizedPath);
|
| 2316 | if (fogOfWar.active && fogOfWar.matches) {
|
| 2317 | matches = fogOfWar.matches;
|
| 2318 | }
|
| 2319 | if (!matches) {
|
| 2320 | setFetcherError(
|
| 2321 | key,
|
| 2322 | routeId,
|
| 2323 | getInternalRouterError(404, { pathname: normalizedPath }),
|
| 2324 | { flushSync }
|
| 2325 | );
|
| 2326 | return;
|
| 2327 | }
|
| 2328 | let { path, submission, error } = normalizeNavigateOptions(
|
| 2329 | true,
|
| 2330 | normalizedPath,
|
| 2331 | opts
|
| 2332 | );
|
| 2333 | if (error) {
|
| 2334 | setFetcherError(key, routeId, error, { flushSync });
|
| 2335 | return;
|
| 2336 | }
|
| 2337 | let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
|
| 2338 | let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
| 2339 | if (submission && isMutationMethod(submission.formMethod)) {
|
| 2340 | await handleFetcherAction(
|
| 2341 | key,
|
| 2342 | routeId,
|
| 2343 | path,
|
| 2344 | matches,
|
| 2345 | scopedContext,
|
| 2346 | fogOfWar.active,
|
| 2347 | flushSync,
|
| 2348 | preventScrollReset,
|
| 2349 | submission,
|
| 2350 | opts && opts.unstable_defaultShouldRevalidate
|
| 2351 | );
|
| 2352 | return;
|
| 2353 | }
|
| 2354 | fetchLoadMatches.set(key, { routeId, path });
|
| 2355 | await handleFetcherLoader(
|
| 2356 | key,
|
| 2357 | routeId,
|
| 2358 | path,
|
| 2359 | matches,
|
| 2360 | scopedContext,
|
| 2361 | fogOfWar.active,
|
| 2362 | flushSync,
|
| 2363 | preventScrollReset,
|
| 2364 | submission
|
| 2365 | );
|
| 2366 | }
|
| 2367 | async function handleFetcherAction(key, routeId, path, requestMatches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission, callSiteDefaultShouldRevalidate) {
|
| 2368 | interruptActiveLoads();
|
| 2369 | fetchLoadMatches.delete(key);
|
| 2370 | let existingFetcher = state.fetchers.get(key);
|
| 2371 | updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), {
|
| 2372 | flushSync
|
| 2373 | });
|
| 2374 | let abortController = new AbortController();
|
| 2375 | let fetchRequest = createClientSideRequest(
|
| 2376 | init.history,
|
| 2377 | path,
|
| 2378 | abortController.signal,
|
| 2379 | submission
|
| 2380 | );
|
| 2381 | if (isFogOfWar) {
|
| 2382 | let discoverResult = await discoverRoutes(
|
| 2383 | requestMatches,
|
| 2384 | new URL(fetchRequest.url).pathname,
|
| 2385 | fetchRequest.signal,
|
| 2386 | key
|
| 2387 | );
|
| 2388 | if (discoverResult.type === "aborted") {
|
| 2389 | return;
|
| 2390 | } else if (discoverResult.type === "error") {
|
| 2391 | setFetcherError(key, routeId, discoverResult.error, { flushSync });
|
| 2392 | return;
|
| 2393 | } else if (!discoverResult.matches) {
|
| 2394 | setFetcherError(
|
| 2395 | key,
|
| 2396 | routeId,
|
| 2397 | getInternalRouterError(404, { pathname: path }),
|
| 2398 | { flushSync }
|
| 2399 | );
|
| 2400 | return;
|
| 2401 | } else {
|
| 2402 | requestMatches = discoverResult.matches;
|
| 2403 | }
|
| 2404 | }
|
| 2405 | let match = getTargetMatch(requestMatches, path);
|
| 2406 | if (!match.route.action && !match.route.lazy) {
|
| 2407 | let error = getInternalRouterError(405, {
|
| 2408 | method: submission.formMethod,
|
| 2409 | pathname: path,
|
| 2410 | routeId
|
| 2411 | });
|
| 2412 | setFetcherError(key, routeId, error, { flushSync });
|
| 2413 | return;
|
| 2414 | }
|
| 2415 | fetchControllers.set(key, abortController);
|
| 2416 | let originatingLoadId = incrementingLoadId;
|
| 2417 | let fetchMatches = getTargetedDataStrategyMatches(
|
| 2418 | mapRouteProperties2,
|
| 2419 | manifest,
|
| 2420 | fetchRequest,
|
| 2421 | path,
|
| 2422 | requestMatches,
|
| 2423 | match,
|
| 2424 | hydrationRouteProperties2,
|
| 2425 | scopedContext
|
| 2426 | );
|
| 2427 | let actionResults = await callDataStrategy(
|
| 2428 | fetchRequest,
|
| 2429 | path,
|
| 2430 | fetchMatches,
|
| 2431 | scopedContext,
|
| 2432 | key
|
| 2433 | );
|
| 2434 | let actionResult = actionResults[match.route.id];
|
| 2435 | if (!actionResult) {
|
| 2436 | for (let match2 of fetchMatches) {
|
| 2437 | if (actionResults[match2.route.id]) {
|
| 2438 | actionResult = actionResults[match2.route.id];
|
| 2439 | break;
|
| 2440 | }
|
| 2441 | }
|
| 2442 | }
|
| 2443 | if (fetchRequest.signal.aborted) {
|
| 2444 | if (fetchControllers.get(key) === abortController) {
|
| 2445 | fetchControllers.delete(key);
|
| 2446 | }
|
| 2447 | return;
|
| 2448 | }
|
| 2449 | if (fetchersQueuedForDeletion.has(key)) {
|
| 2450 | if (isRedirectResult(actionResult) || isErrorResult(actionResult)) {
|
| 2451 | updateFetcherState(key, getDoneFetcher(void 0));
|
| 2452 | return;
|
| 2453 | }
|
| 2454 | } else {
|
| 2455 | if (isRedirectResult(actionResult)) {
|
| 2456 | fetchControllers.delete(key);
|
| 2457 | if (pendingNavigationLoadId > originatingLoadId) {
|
| 2458 | updateFetcherState(key, getDoneFetcher(void 0));
|
| 2459 | return;
|
| 2460 | } else {
|
| 2461 | fetchRedirectIds.add(key);
|
| 2462 | updateFetcherState(key, getLoadingFetcher(submission));
|
| 2463 | return startRedirectNavigation(fetchRequest, actionResult, false, {
|
| 2464 | fetcherSubmission: submission,
|
| 2465 | preventScrollReset
|
| 2466 | });
|
| 2467 | }
|
| 2468 | }
|
| 2469 | if (isErrorResult(actionResult)) {
|
| 2470 | setFetcherError(key, routeId, actionResult.error);
|
| 2471 | return;
|
| 2472 | }
|
| 2473 | }
|
| 2474 | let nextLocation = state.navigation.location || state.location;
|
| 2475 | let revalidationRequest = createClientSideRequest(
|
| 2476 | init.history,
|
| 2477 | nextLocation,
|
| 2478 | abortController.signal
|
| 2479 | );
|
| 2480 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
| 2481 | let matches = state.navigation.state !== "idle" ? matchRoutes(routesToUse, state.navigation.location, basename) : state.matches;
|
| 2482 | invariant(matches, "Didn't find any matches after fetcher action");
|
| 2483 | let loadId = ++incrementingLoadId;
|
| 2484 | fetchReloadIds.set(key, loadId);
|
| 2485 | let loadFetcher = getLoadingFetcher(submission, actionResult.data);
|
| 2486 | state.fetchers.set(key, loadFetcher);
|
| 2487 | let { dsMatches, revalidatingFetchers } = getMatchesToLoad(
|
| 2488 | revalidationRequest,
|
| 2489 | scopedContext,
|
| 2490 | mapRouteProperties2,
|
| 2491 | manifest,
|
| 2492 | init.history,
|
| 2493 | state,
|
| 2494 | matches,
|
| 2495 | submission,
|
| 2496 | nextLocation,
|
| 2497 | hydrationRouteProperties2,
|
| 2498 | false,
|
| 2499 | isRevalidationRequired,
|
| 2500 | cancelledFetcherLoads,
|
| 2501 | fetchersQueuedForDeletion,
|
| 2502 | fetchLoadMatches,
|
| 2503 | fetchRedirectIds,
|
| 2504 | routesToUse,
|
| 2505 | basename,
|
| 2506 | init.patchRoutesOnNavigation != null,
|
| 2507 | [match.route.id, actionResult],
|
| 2508 | callSiteDefaultShouldRevalidate
|
| 2509 | );
|
| 2510 | revalidatingFetchers.filter((rf) => rf.key !== key).forEach((rf) => {
|
| 2511 | let staleKey = rf.key;
|
| 2512 | let existingFetcher2 = state.fetchers.get(staleKey);
|
| 2513 | let revalidatingFetcher = getLoadingFetcher(
|
| 2514 | void 0,
|
| 2515 | existingFetcher2 ? existingFetcher2.data : void 0
|
| 2516 | );
|
| 2517 | state.fetchers.set(staleKey, revalidatingFetcher);
|
| 2518 | abortFetcher(staleKey);
|
| 2519 | if (rf.controller) {
|
| 2520 | fetchControllers.set(staleKey, rf.controller);
|
| 2521 | }
|
| 2522 | });
|
| 2523 | updateState({ fetchers: new Map(state.fetchers) });
|
| 2524 | let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((rf) => abortFetcher(rf.key));
|
| 2525 | abortController.signal.addEventListener(
|
| 2526 | "abort",
|
| 2527 | abortPendingFetchRevalidations
|
| 2528 | );
|
| 2529 | let { loaderResults, fetcherResults } = await callLoadersAndMaybeResolveData(
|
| 2530 | dsMatches,
|
| 2531 | revalidatingFetchers,
|
| 2532 | revalidationRequest,
|
| 2533 | nextLocation,
|
| 2534 | scopedContext
|
| 2535 | );
|
| 2536 | if (abortController.signal.aborted) {
|
| 2537 | return;
|
| 2538 | }
|
| 2539 | abortController.signal.removeEventListener(
|
| 2540 | "abort",
|
| 2541 | abortPendingFetchRevalidations
|
| 2542 | );
|
| 2543 | fetchReloadIds.delete(key);
|
| 2544 | fetchControllers.delete(key);
|
| 2545 | revalidatingFetchers.forEach((r) => fetchControllers.delete(r.key));
|
| 2546 | if (state.fetchers.has(key)) {
|
| 2547 | let doneFetcher = getDoneFetcher(actionResult.data);
|
| 2548 | state.fetchers.set(key, doneFetcher);
|
| 2549 | }
|
| 2550 | let redirect2 = findRedirect(loaderResults);
|
| 2551 | if (redirect2) {
|
| 2552 | return startRedirectNavigation(
|
| 2553 | revalidationRequest,
|
| 2554 | redirect2.result,
|
| 2555 | false,
|
| 2556 | { preventScrollReset }
|
| 2557 | );
|
| 2558 | }
|
| 2559 | redirect2 = findRedirect(fetcherResults);
|
| 2560 | if (redirect2) {
|
| 2561 | fetchRedirectIds.add(redirect2.key);
|
| 2562 | return startRedirectNavigation(
|
| 2563 | revalidationRequest,
|
| 2564 | redirect2.result,
|
| 2565 | false,
|
| 2566 | { preventScrollReset }
|
| 2567 | );
|
| 2568 | }
|
| 2569 | let { loaderData, errors } = processLoaderData(
|
| 2570 | state,
|
| 2571 | matches,
|
| 2572 | loaderResults,
|
| 2573 | void 0,
|
| 2574 | revalidatingFetchers,
|
| 2575 | fetcherResults
|
| 2576 | );
|
| 2577 | abortStaleFetchLoads(loadId);
|
| 2578 | if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) {
|
| 2579 | invariant(pendingAction, "Expected pending action");
|
| 2580 | pendingNavigationController && pendingNavigationController.abort();
|
| 2581 | completeNavigation(state.navigation.location, {
|
| 2582 | matches,
|
| 2583 | loaderData,
|
| 2584 | errors,
|
| 2585 | fetchers: new Map(state.fetchers)
|
| 2586 | });
|
| 2587 | } else {
|
| 2588 | updateState({
|
| 2589 | errors,
|
| 2590 | loaderData: mergeLoaderData(
|
| 2591 | state.loaderData,
|
| 2592 | loaderData,
|
| 2593 | matches,
|
| 2594 | errors
|
| 2595 | ),
|
| 2596 | fetchers: new Map(state.fetchers)
|
| 2597 | });
|
| 2598 | isRevalidationRequired = false;
|
| 2599 | }
|
| 2600 | }
|
| 2601 | async function handleFetcherLoader(key, routeId, path, matches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission) {
|
| 2602 | let existingFetcher = state.fetchers.get(key);
|
| 2603 | updateFetcherState(
|
| 2604 | key,
|
| 2605 | getLoadingFetcher(
|
| 2606 | submission,
|
| 2607 | existingFetcher ? existingFetcher.data : void 0
|
| 2608 | ),
|
| 2609 | { flushSync }
|
| 2610 | );
|
| 2611 | let abortController = new AbortController();
|
| 2612 | let fetchRequest = createClientSideRequest(
|
| 2613 | init.history,
|
| 2614 | path,
|
| 2615 | abortController.signal
|
| 2616 | );
|
| 2617 | if (isFogOfWar) {
|
| 2618 | let discoverResult = await discoverRoutes(
|
| 2619 | matches,
|
| 2620 | new URL(fetchRequest.url).pathname,
|
| 2621 | fetchRequest.signal,
|
| 2622 | key
|
| 2623 | );
|
| 2624 | if (discoverResult.type === "aborted") {
|
| 2625 | return;
|
| 2626 | } else if (discoverResult.type === "error") {
|
| 2627 | setFetcherError(key, routeId, discoverResult.error, { flushSync });
|
| 2628 | return;
|
| 2629 | } else if (!discoverResult.matches) {
|
| 2630 | setFetcherError(
|
| 2631 | key,
|
| 2632 | routeId,
|
| 2633 | getInternalRouterError(404, { pathname: path }),
|
| 2634 | { flushSync }
|
| 2635 | );
|
| 2636 | return;
|
| 2637 | } else {
|
| 2638 | matches = discoverResult.matches;
|
| 2639 | }
|
| 2640 | }
|
| 2641 | let match = getTargetMatch(matches, path);
|
| 2642 | fetchControllers.set(key, abortController);
|
| 2643 | let originatingLoadId = incrementingLoadId;
|
| 2644 | let dsMatches = getTargetedDataStrategyMatches(
|
| 2645 | mapRouteProperties2,
|
| 2646 | manifest,
|
| 2647 | fetchRequest,
|
| 2648 | path,
|
| 2649 | matches,
|
| 2650 | match,
|
| 2651 | hydrationRouteProperties2,
|
| 2652 | scopedContext
|
| 2653 | );
|
| 2654 | let results = await callDataStrategy(
|
| 2655 | fetchRequest,
|
| 2656 | path,
|
| 2657 | dsMatches,
|
| 2658 | scopedContext,
|
| 2659 | key
|
| 2660 | );
|
| 2661 | let result = results[match.route.id];
|
| 2662 | if (fetchControllers.get(key) === abortController) {
|
| 2663 | fetchControllers.delete(key);
|
| 2664 | }
|
| 2665 | if (fetchRequest.signal.aborted) {
|
| 2666 | return;
|
| 2667 | }
|
| 2668 | if (fetchersQueuedForDeletion.has(key)) {
|
| 2669 | updateFetcherState(key, getDoneFetcher(void 0));
|
| 2670 | return;
|
| 2671 | }
|
| 2672 | if (isRedirectResult(result)) {
|
| 2673 | if (pendingNavigationLoadId > originatingLoadId) {
|
| 2674 | updateFetcherState(key, getDoneFetcher(void 0));
|
| 2675 | return;
|
| 2676 | } else {
|
| 2677 | fetchRedirectIds.add(key);
|
| 2678 | await startRedirectNavigation(fetchRequest, result, false, {
|
| 2679 | preventScrollReset
|
| 2680 | });
|
| 2681 | return;
|
| 2682 | }
|
| 2683 | }
|
| 2684 | if (isErrorResult(result)) {
|
| 2685 | setFetcherError(key, routeId, result.error);
|
| 2686 | return;
|
| 2687 | }
|
| 2688 | updateFetcherState(key, getDoneFetcher(result.data));
|
| 2689 | }
|
| 2690 | async function startRedirectNavigation(request, redirect2, isNavigation, {
|
| 2691 | submission,
|
| 2692 | fetcherSubmission,
|
| 2693 | preventScrollReset,
|
| 2694 | replace: replace2
|
| 2695 | } = {}) {
|
| 2696 | if (!isNavigation) {
|
| 2697 | _optionalChain([pendingPopstateNavigationDfd, 'optionalAccess', _24 => _24.resolve, 'call', _25 => _25()]);
|
| 2698 | pendingPopstateNavigationDfd = null;
|
| 2699 | }
|
| 2700 | if (redirect2.response.headers.has("X-Remix-Revalidate")) {
|
| 2701 | isRevalidationRequired = true;
|
| 2702 | }
|
| 2703 | let location = redirect2.response.headers.get("Location");
|
| 2704 | invariant(location, "Expected a Location header on the redirect Response");
|
| 2705 | location = normalizeRedirectLocation(
|
| 2706 | location,
|
| 2707 | new URL(request.url),
|
| 2708 | basename,
|
| 2709 | init.history
|
| 2710 | );
|
| 2711 | let redirectLocation = createLocation(state.location, location, {
|
| 2712 | _isRedirect: true
|
| 2713 | });
|
| 2714 | if (isBrowser2) {
|
| 2715 | let isDocumentReload = false;
|
| 2716 | if (redirect2.response.headers.has("X-Remix-Reload-Document")) {
|
| 2717 | isDocumentReload = true;
|
| 2718 | } else if (isAbsoluteUrl(location)) {
|
| 2719 | const url = createBrowserURLImpl(location, true);
|
| 2720 | isDocumentReload =
|
| 2721 | url.origin !== routerWindow.location.origin ||
|
| 2722 | stripBasename(url.pathname, basename) == null;
|
| 2723 | }
|
| 2724 | if (isDocumentReload) {
|
| 2725 | if (replace2) {
|
| 2726 | routerWindow.location.replace(location);
|
| 2727 | } else {
|
| 2728 | routerWindow.location.assign(location);
|
| 2729 | }
|
| 2730 | return;
|
| 2731 | }
|
| 2732 | }
|
| 2733 | pendingNavigationController = null;
|
| 2734 | let redirectNavigationType = replace2 === true || redirect2.response.headers.has("X-Remix-Replace") ? "REPLACE" : "PUSH" ;
|
| 2735 | let { formMethod, formAction, formEncType } = state.navigation;
|
| 2736 | if (!submission && !fetcherSubmission && formMethod && formAction && formEncType) {
|
| 2737 | submission = getSubmissionFromNavigation(state.navigation);
|
| 2738 | }
|
| 2739 | let activeSubmission = submission || fetcherSubmission;
|
| 2740 | if (redirectPreserveMethodStatusCodes.has(redirect2.response.status) && activeSubmission && isMutationMethod(activeSubmission.formMethod)) {
|
| 2741 | await startNavigation(redirectNavigationType, redirectLocation, {
|
| 2742 | submission: {
|
| 2743 | ...activeSubmission,
|
| 2744 | formAction: location
|
| 2745 | },
|
| 2746 |
|
| 2747 | preventScrollReset: preventScrollReset || pendingPreventScrollReset,
|
| 2748 | enableViewTransition: isNavigation ? pendingViewTransitionEnabled : void 0
|
| 2749 | });
|
| 2750 | } else {
|
| 2751 | let overrideNavigation = getLoadingNavigation(
|
| 2752 | redirectLocation,
|
| 2753 | submission
|
| 2754 | );
|
| 2755 | await startNavigation(redirectNavigationType, redirectLocation, {
|
| 2756 | overrideNavigation,
|
| 2757 |
|
| 2758 | fetcherSubmission,
|
| 2759 |
|
| 2760 | preventScrollReset: preventScrollReset || pendingPreventScrollReset,
|
| 2761 | enableViewTransition: isNavigation ? pendingViewTransitionEnabled : void 0
|
| 2762 | });
|
| 2763 | }
|
| 2764 | }
|
| 2765 | async function callDataStrategy(request, path, matches, scopedContext, fetcherKey) {
|
| 2766 | let results;
|
| 2767 | let dataResults = {};
|
| 2768 | try {
|
| 2769 | results = await callDataStrategyImpl(
|
| 2770 | dataStrategyImpl,
|
| 2771 | request,
|
| 2772 | path,
|
| 2773 | matches,
|
| 2774 | fetcherKey,
|
| 2775 | scopedContext,
|
| 2776 | false
|
| 2777 | );
|
| 2778 | } catch (e) {
|
| 2779 | matches.filter((m) => m.shouldLoad).forEach((m) => {
|
| 2780 | dataResults[m.route.id] = {
|
| 2781 | type: "error" ,
|
| 2782 | error: e
|
| 2783 | };
|
| 2784 | });
|
| 2785 | return dataResults;
|
| 2786 | }
|
| 2787 | if (request.signal.aborted) {
|
| 2788 | return dataResults;
|
| 2789 | }
|
| 2790 | if (!isMutationMethod(request.method)) {
|
| 2791 | for (let match of matches) {
|
| 2792 | if (_optionalChain([results, 'access', _26 => _26[match.route.id], 'optionalAccess', _27 => _27.type]) === "error" ) {
|
| 2793 | break;
|
| 2794 | }
|
| 2795 | if (!results.hasOwnProperty(match.route.id) && !state.loaderData.hasOwnProperty(match.route.id) && (!state.errors || !state.errors.hasOwnProperty(match.route.id)) && match.shouldCallHandler()) {
|
| 2796 | results[match.route.id] = {
|
| 2797 | type: "error" ,
|
| 2798 | result: new Error(
|
| 2799 | `No result returned from dataStrategy for route ${match.route.id}`
|
| 2800 | )
|
| 2801 | };
|
| 2802 | }
|
| 2803 | }
|
| 2804 | }
|
| 2805 | for (let [routeId, result] of Object.entries(results)) {
|
| 2806 | if (isRedirectDataStrategyResult(result)) {
|
| 2807 | let response = result.result;
|
| 2808 | dataResults[routeId] = {
|
| 2809 | type: "redirect" ,
|
| 2810 | response: normalizeRelativeRoutingRedirectResponse(
|
| 2811 | response,
|
| 2812 | request,
|
| 2813 | routeId,
|
| 2814 | matches,
|
| 2815 | basename
|
| 2816 | )
|
| 2817 | };
|
| 2818 | } else {
|
| 2819 | dataResults[routeId] = await convertDataStrategyResultToDataResult(result);
|
| 2820 | }
|
| 2821 | }
|
| 2822 | return dataResults;
|
| 2823 | }
|
| 2824 | async function callLoadersAndMaybeResolveData(matches, fetchersToLoad, request, location, scopedContext) {
|
| 2825 | let loaderResultsPromise = callDataStrategy(
|
| 2826 | request,
|
| 2827 | location,
|
| 2828 | matches,
|
| 2829 | scopedContext,
|
| 2830 | null
|
| 2831 | );
|
| 2832 | let fetcherResultsPromise = Promise.all(
|
| 2833 | fetchersToLoad.map(async (f) => {
|
| 2834 | if (f.matches && f.match && f.request && f.controller) {
|
| 2835 | let results = await callDataStrategy(
|
| 2836 | f.request,
|
| 2837 | f.path,
|
| 2838 | f.matches,
|
| 2839 | scopedContext,
|
| 2840 | f.key
|
| 2841 | );
|
| 2842 | let result = results[f.match.route.id];
|
| 2843 | return { [f.key]: result };
|
| 2844 | } else {
|
| 2845 | return Promise.resolve({
|
| 2846 | [f.key]: {
|
| 2847 | type: "error" ,
|
| 2848 | error: getInternalRouterError(404, {
|
| 2849 | pathname: f.path
|
| 2850 | })
|
| 2851 | }
|
| 2852 | });
|
| 2853 | }
|
| 2854 | })
|
| 2855 | );
|
| 2856 | let loaderResults = await loaderResultsPromise;
|
| 2857 | let fetcherResults = (await fetcherResultsPromise).reduce(
|
| 2858 | (acc, r) => Object.assign(acc, r),
|
| 2859 | {}
|
| 2860 | );
|
| 2861 | return {
|
| 2862 | loaderResults,
|
| 2863 | fetcherResults
|
| 2864 | };
|
| 2865 | }
|
| 2866 | function interruptActiveLoads() {
|
| 2867 | isRevalidationRequired = true;
|
| 2868 | fetchLoadMatches.forEach((_, key) => {
|
| 2869 | if (fetchControllers.has(key)) {
|
| 2870 | cancelledFetcherLoads.add(key);
|
| 2871 | }
|
| 2872 | abortFetcher(key);
|
| 2873 | });
|
| 2874 | }
|
| 2875 | function updateFetcherState(key, fetcher, opts = {}) {
|
| 2876 | state.fetchers.set(key, fetcher);
|
| 2877 | updateState(
|
| 2878 | { fetchers: new Map(state.fetchers) },
|
| 2879 | { flushSync: (opts && opts.flushSync) === true }
|
| 2880 | );
|
| 2881 | }
|
| 2882 | function setFetcherError(key, routeId, error, opts = {}) {
|
| 2883 | let boundaryMatch = findNearestBoundary(state.matches, routeId);
|
| 2884 | deleteFetcher(key);
|
| 2885 | updateState(
|
| 2886 | {
|
| 2887 | errors: {
|
| 2888 | [boundaryMatch.route.id]: error
|
| 2889 | },
|
| 2890 | fetchers: new Map(state.fetchers)
|
| 2891 | },
|
| 2892 | { flushSync: (opts && opts.flushSync) === true }
|
| 2893 | );
|
| 2894 | }
|
| 2895 | function getFetcher(key) {
|
| 2896 | activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
|
| 2897 | if (fetchersQueuedForDeletion.has(key)) {
|
| 2898 | fetchersQueuedForDeletion.delete(key);
|
| 2899 | }
|
| 2900 | return state.fetchers.get(key) || IDLE_FETCHER;
|
| 2901 | }
|
| 2902 | function resetFetcher(key, opts) {
|
| 2903 | abortFetcher(key, _optionalChain([opts, 'optionalAccess', _28 => _28.reason]));
|
| 2904 | updateFetcherState(key, getDoneFetcher(null));
|
| 2905 | }
|
| 2906 | function deleteFetcher(key) {
|
| 2907 | let fetcher = state.fetchers.get(key);
|
| 2908 | if (fetchControllers.has(key) && !(fetcher && fetcher.state === "loading" && fetchReloadIds.has(key))) {
|
| 2909 | abortFetcher(key);
|
| 2910 | }
|
| 2911 | fetchLoadMatches.delete(key);
|
| 2912 | fetchReloadIds.delete(key);
|
| 2913 | fetchRedirectIds.delete(key);
|
| 2914 | fetchersQueuedForDeletion.delete(key);
|
| 2915 | cancelledFetcherLoads.delete(key);
|
| 2916 | state.fetchers.delete(key);
|
| 2917 | }
|
| 2918 | function queueFetcherForDeletion(key) {
|
| 2919 | let count = (activeFetchers.get(key) || 0) - 1;
|
| 2920 | if (count <= 0) {
|
| 2921 | activeFetchers.delete(key);
|
| 2922 | fetchersQueuedForDeletion.add(key);
|
| 2923 | } else {
|
| 2924 | activeFetchers.set(key, count);
|
| 2925 | }
|
| 2926 | updateState({ fetchers: new Map(state.fetchers) });
|
| 2927 | }
|
| 2928 | function abortFetcher(key, reason) {
|
| 2929 | let controller = fetchControllers.get(key);
|
| 2930 | if (controller) {
|
| 2931 | controller.abort(reason);
|
| 2932 | fetchControllers.delete(key);
|
| 2933 | }
|
| 2934 | }
|
| 2935 | function markFetchersDone(keys) {
|
| 2936 | for (let key of keys) {
|
| 2937 | let fetcher = getFetcher(key);
|
| 2938 | let doneFetcher = getDoneFetcher(fetcher.data);
|
| 2939 | state.fetchers.set(key, doneFetcher);
|
| 2940 | }
|
| 2941 | }
|
| 2942 | function markFetchRedirectsDone() {
|
| 2943 | let doneKeys = [];
|
| 2944 | let updatedFetchers = false;
|
| 2945 | for (let key of fetchRedirectIds) {
|
| 2946 | let fetcher = state.fetchers.get(key);
|
| 2947 | invariant(fetcher, `Expected fetcher: ${key}`);
|
| 2948 | if (fetcher.state === "loading") {
|
| 2949 | fetchRedirectIds.delete(key);
|
| 2950 | doneKeys.push(key);
|
| 2951 | updatedFetchers = true;
|
| 2952 | }
|
| 2953 | }
|
| 2954 | markFetchersDone(doneKeys);
|
| 2955 | return updatedFetchers;
|
| 2956 | }
|
| 2957 | function abortStaleFetchLoads(landedId) {
|
| 2958 | let yeetedKeys = [];
|
| 2959 | for (let [key, id] of fetchReloadIds) {
|
| 2960 | if (id < landedId) {
|
| 2961 | let fetcher = state.fetchers.get(key);
|
| 2962 | invariant(fetcher, `Expected fetcher: ${key}`);
|
| 2963 | if (fetcher.state === "loading") {
|
| 2964 | abortFetcher(key);
|
| 2965 | fetchReloadIds.delete(key);
|
| 2966 | yeetedKeys.push(key);
|
| 2967 | }
|
| 2968 | }
|
| 2969 | }
|
| 2970 | markFetchersDone(yeetedKeys);
|
| 2971 | return yeetedKeys.length > 0;
|
| 2972 | }
|
| 2973 | function getBlocker(key, fn) {
|
| 2974 | let blocker = state.blockers.get(key) || IDLE_BLOCKER;
|
| 2975 | if (blockerFunctions.get(key) !== fn) {
|
| 2976 | blockerFunctions.set(key, fn);
|
| 2977 | }
|
| 2978 | return blocker;
|
| 2979 | }
|
| 2980 | function deleteBlocker(key) {
|
| 2981 | state.blockers.delete(key);
|
| 2982 | blockerFunctions.delete(key);
|
| 2983 | }
|
| 2984 | function updateBlocker(key, newBlocker) {
|
| 2985 | let blocker = state.blockers.get(key) || IDLE_BLOCKER;
|
| 2986 | invariant(
|
| 2987 | blocker.state === "unblocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "proceeding" || blocker.state === "blocked" && newBlocker.state === "unblocked" || blocker.state === "proceeding" && newBlocker.state === "unblocked",
|
| 2988 | `Invalid blocker state transition: ${blocker.state} -> ${newBlocker.state}`
|
| 2989 | );
|
| 2990 | let blockers = new Map(state.blockers);
|
| 2991 | blockers.set(key, newBlocker);
|
| 2992 | updateState({ blockers });
|
| 2993 | }
|
| 2994 | function shouldBlockNavigation({
|
| 2995 | currentLocation,
|
| 2996 | nextLocation,
|
| 2997 | historyAction
|
| 2998 | }) {
|
| 2999 | if (blockerFunctions.size === 0) {
|
| 3000 | return;
|
| 3001 | }
|
| 3002 | if (blockerFunctions.size > 1) {
|
| 3003 | warning(false, "A router only supports one blocker at a time");
|
| 3004 | }
|
| 3005 | let entries = Array.from(blockerFunctions.entries());
|
| 3006 | let [blockerKey, blockerFunction] = entries[entries.length - 1];
|
| 3007 | let blocker = state.blockers.get(blockerKey);
|
| 3008 | if (blocker && blocker.state === "proceeding") {
|
| 3009 | return;
|
| 3010 | }
|
| 3011 | if (blockerFunction({ currentLocation, nextLocation, historyAction })) {
|
| 3012 | return blockerKey;
|
| 3013 | }
|
| 3014 | }
|
| 3015 | function handleNavigational404(pathname) {
|
| 3016 | let error = getInternalRouterError(404, { pathname });
|
| 3017 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
| 3018 | let { matches, route } = getShortCircuitMatches(routesToUse);
|
| 3019 | return { notFoundMatches: matches, route, error };
|
| 3020 | }
|
| 3021 | function enableScrollRestoration(positions, getPosition, getKey) {
|
| 3022 | savedScrollPositions = positions;
|
| 3023 | getScrollPosition = getPosition;
|
| 3024 | getScrollRestorationKey = getKey || null;
|
| 3025 | if (!initialScrollRestored && state.navigation === IDLE_NAVIGATION) {
|
| 3026 | initialScrollRestored = true;
|
| 3027 | let y = getSavedScrollPosition(state.location, state.matches);
|
| 3028 | if (y != null) {
|
| 3029 | updateState({ restoreScrollPosition: y });
|
| 3030 | }
|
| 3031 | }
|
| 3032 | return () => {
|
| 3033 | savedScrollPositions = null;
|
| 3034 | getScrollPosition = null;
|
| 3035 | getScrollRestorationKey = null;
|
| 3036 | };
|
| 3037 | }
|
| 3038 | function getScrollKey(location, matches) {
|
| 3039 | if (getScrollRestorationKey) {
|
| 3040 | let key = getScrollRestorationKey(
|
| 3041 | location,
|
| 3042 | matches.map((m) => convertRouteMatchToUiMatch(m, state.loaderData))
|
| 3043 | );
|
| 3044 | return key || location.key;
|
| 3045 | }
|
| 3046 | return location.key;
|
| 3047 | }
|
| 3048 | function saveScrollPosition(location, matches) {
|
| 3049 | if (savedScrollPositions && getScrollPosition) {
|
| 3050 | let key = getScrollKey(location, matches);
|
| 3051 | savedScrollPositions[key] = getScrollPosition();
|
| 3052 | }
|
| 3053 | }
|
| 3054 | function getSavedScrollPosition(location, matches) {
|
| 3055 | if (savedScrollPositions) {
|
| 3056 | let key = getScrollKey(location, matches);
|
| 3057 | let y = savedScrollPositions[key];
|
| 3058 | if (typeof y === "number") {
|
| 3059 | return y;
|
| 3060 | }
|
| 3061 | }
|
| 3062 | return null;
|
| 3063 | }
|
| 3064 | function checkFogOfWar(matches, routesToUse, pathname) {
|
| 3065 | if (init.patchRoutesOnNavigation) {
|
| 3066 | if (!matches) {
|
| 3067 | let fogMatches = matchRoutesImpl(
|
| 3068 | routesToUse,
|
| 3069 | pathname,
|
| 3070 | basename,
|
| 3071 | true
|
| 3072 | );
|
| 3073 | return { active: true, matches: fogMatches || [] };
|
| 3074 | } else {
|
| 3075 | if (Object.keys(matches[0].params).length > 0) {
|
| 3076 | let partialMatches = matchRoutesImpl(
|
| 3077 | routesToUse,
|
| 3078 | pathname,
|
| 3079 | basename,
|
| 3080 | true
|
| 3081 | );
|
| 3082 | return { active: true, matches: partialMatches };
|
| 3083 | }
|
| 3084 | }
|
| 3085 | }
|
| 3086 | return { active: false, matches: null };
|
| 3087 | }
|
| 3088 | async function discoverRoutes(matches, pathname, signal, fetcherKey) {
|
| 3089 | if (!init.patchRoutesOnNavigation) {
|
| 3090 | return { type: "success", matches };
|
| 3091 | }
|
| 3092 | let partialMatches = matches;
|
| 3093 | while (true) {
|
| 3094 | let isNonHMR = inFlightDataRoutes == null;
|
| 3095 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
| 3096 | let localManifest = manifest;
|
| 3097 | try {
|
| 3098 | await init.patchRoutesOnNavigation({
|
| 3099 | signal,
|
| 3100 | path: pathname,
|
| 3101 | matches: partialMatches,
|
| 3102 | fetcherKey,
|
| 3103 | patch: (routeId, children) => {
|
| 3104 | if (signal.aborted) return;
|
| 3105 | patchRoutesImpl(
|
| 3106 | routeId,
|
| 3107 | children,
|
| 3108 | routesToUse,
|
| 3109 | localManifest,
|
| 3110 | mapRouteProperties2,
|
| 3111 | false
|
| 3112 | );
|
| 3113 | }
|
| 3114 | });
|
| 3115 | } catch (e) {
|
| 3116 | return { type: "error", error: e, partialMatches };
|
| 3117 | } finally {
|
| 3118 | if (isNonHMR && !signal.aborted) {
|
| 3119 | dataRoutes = [...dataRoutes];
|
| 3120 | }
|
| 3121 | }
|
| 3122 | if (signal.aborted) {
|
| 3123 | return { type: "aborted" };
|
| 3124 | }
|
| 3125 | let newMatches = matchRoutes(routesToUse, pathname, basename);
|
| 3126 | let newPartialMatches = null;
|
| 3127 | if (newMatches) {
|
| 3128 | if (Object.keys(newMatches[0].params).length === 0) {
|
| 3129 | return { type: "success", matches: newMatches };
|
| 3130 | } else {
|
| 3131 | newPartialMatches = matchRoutesImpl(
|
| 3132 | routesToUse,
|
| 3133 | pathname,
|
| 3134 | basename,
|
| 3135 | true
|
| 3136 | );
|
| 3137 | let matchedDeeper = newPartialMatches && partialMatches.length < newPartialMatches.length && compareMatches(
|
| 3138 | partialMatches,
|
| 3139 | newPartialMatches.slice(0, partialMatches.length)
|
| 3140 | );
|
| 3141 | if (!matchedDeeper) {
|
| 3142 | return { type: "success", matches: newMatches };
|
| 3143 | }
|
| 3144 | }
|
| 3145 | }
|
| 3146 | if (!newPartialMatches) {
|
| 3147 | newPartialMatches = matchRoutesImpl(
|
| 3148 | routesToUse,
|
| 3149 | pathname,
|
| 3150 | basename,
|
| 3151 | true
|
| 3152 | );
|
| 3153 | }
|
| 3154 | if (!newPartialMatches || compareMatches(partialMatches, newPartialMatches)) {
|
| 3155 | return { type: "success", matches: null };
|
| 3156 | }
|
| 3157 | partialMatches = newPartialMatches;
|
| 3158 | }
|
| 3159 | }
|
| 3160 | function compareMatches(a, b) {
|
| 3161 | return a.length === b.length && a.every((m, i) => m.route.id === b[i].route.id);
|
| 3162 | }
|
| 3163 | function _internalSetRoutes(newRoutes) {
|
| 3164 | manifest = {};
|
| 3165 | inFlightDataRoutes = convertRoutesToDataRoutes(
|
| 3166 | newRoutes,
|
| 3167 | mapRouteProperties2,
|
| 3168 | void 0,
|
| 3169 | manifest
|
| 3170 | );
|
| 3171 | }
|
| 3172 | function patchRoutes(routeId, children, unstable_allowElementMutations = false) {
|
| 3173 | let isNonHMR = inFlightDataRoutes == null;
|
| 3174 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
| 3175 | patchRoutesImpl(
|
| 3176 | routeId,
|
| 3177 | children,
|
| 3178 | routesToUse,
|
| 3179 | manifest,
|
| 3180 | mapRouteProperties2,
|
| 3181 | unstable_allowElementMutations
|
| 3182 | );
|
| 3183 | if (isNonHMR) {
|
| 3184 | dataRoutes = [...dataRoutes];
|
| 3185 | updateState({});
|
| 3186 | }
|
| 3187 | }
|
| 3188 | router = {
|
| 3189 | get basename() {
|
| 3190 | return basename;
|
| 3191 | },
|
| 3192 | get future() {
|
| 3193 | return future;
|
| 3194 | },
|
| 3195 | get state() {
|
| 3196 | return state;
|
| 3197 | },
|
| 3198 | get routes() {
|
| 3199 | return dataRoutes;
|
| 3200 | },
|
| 3201 | get window() {
|
| 3202 | return routerWindow;
|
| 3203 | },
|
| 3204 | initialize,
|
| 3205 | subscribe,
|
| 3206 | enableScrollRestoration,
|
| 3207 | navigate,
|
| 3208 | fetch: fetch2,
|
| 3209 | revalidate,
|
| 3210 |
|
| 3211 |
|
| 3212 | createHref: (to) => init.history.createHref(to),
|
| 3213 | encodeLocation: (to) => init.history.encodeLocation(to),
|
| 3214 | getFetcher,
|
| 3215 | resetFetcher,
|
| 3216 | deleteFetcher: queueFetcherForDeletion,
|
| 3217 | dispose,
|
| 3218 | getBlocker,
|
| 3219 | deleteBlocker,
|
| 3220 | patchRoutes,
|
| 3221 | _internalFetchControllers: fetchControllers,
|
| 3222 |
|
| 3223 |
|
| 3224 | _internalSetRoutes,
|
| 3225 | _internalSetStateDoNotUseOrYouWillBreakYourApp(newState) {
|
| 3226 | updateState(newState);
|
| 3227 | }
|
| 3228 | };
|
| 3229 | if (init.unstable_instrumentations) {
|
| 3230 | router = instrumentClientSideRouter(
|
| 3231 | router,
|
| 3232 | init.unstable_instrumentations.map((i) => i.router).filter(Boolean)
|
| 3233 | );
|
| 3234 | }
|
| 3235 | return router;
|
| 3236 | }
|
| 3237 | function createStaticHandler(routes, opts) {
|
| 3238 | invariant(
|
| 3239 | routes.length > 0,
|
| 3240 | "You must provide a non-empty routes array to createStaticHandler"
|
| 3241 | );
|
| 3242 | let manifest = {};
|
| 3243 | let basename = (opts ? opts.basename : null) || "/";
|
| 3244 | let _mapRouteProperties = _optionalChain([opts, 'optionalAccess', _29 => _29.mapRouteProperties]) || defaultMapRouteProperties;
|
| 3245 | let mapRouteProperties2 = _mapRouteProperties;
|
| 3246 | let future = {
|
| 3247 | unstable_passThroughRequests: false,
|
| 3248 |
|
| 3249 | ..._optionalChain([opts, 'optionalAccess', _30 => _30.future])
|
| 3250 | };
|
| 3251 | if (_optionalChain([opts, 'optionalAccess', _31 => _31.unstable_instrumentations])) {
|
| 3252 | let instrumentations = opts.unstable_instrumentations;
|
| 3253 | mapRouteProperties2 = (route) => {
|
| 3254 | return {
|
| 3255 | ..._mapRouteProperties(route),
|
| 3256 | ...getRouteInstrumentationUpdates(
|
| 3257 | instrumentations.map((i) => i.route).filter(Boolean),
|
| 3258 | route
|
| 3259 | )
|
| 3260 | };
|
| 3261 | };
|
| 3262 | }
|
| 3263 | let dataRoutes = convertRoutesToDataRoutes(
|
| 3264 | routes,
|
| 3265 | mapRouteProperties2,
|
| 3266 | void 0,
|
| 3267 | manifest
|
| 3268 | );
|
| 3269 | async function query(request, {
|
| 3270 | requestContext,
|
| 3271 | filterMatchesToLoad,
|
| 3272 | skipLoaderErrorBubbling,
|
| 3273 | skipRevalidation,
|
| 3274 | dataStrategy,
|
| 3275 | generateMiddlewareResponse,
|
| 3276 | unstable_normalizePath
|
| 3277 | } = {}) {
|
| 3278 | let normalizePath = unstable_normalizePath || defaultNormalizePath;
|
| 3279 | let method = request.method;
|
| 3280 | let location = createLocation("", normalizePath(request), null, "default");
|
| 3281 | let matches = matchRoutes(dataRoutes, location, basename);
|
| 3282 | requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
| 3283 | if (!isValidMethod(method) && method !== "HEAD") {
|
| 3284 | let error = getInternalRouterError(405, { method });
|
| 3285 | let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
|
| 3286 | let staticContext = {
|
| 3287 | basename,
|
| 3288 | location,
|
| 3289 | matches: methodNotAllowedMatches,
|
| 3290 | loaderData: {},
|
| 3291 | actionData: null,
|
| 3292 | errors: {
|
| 3293 | [route.id]: error
|
| 3294 | },
|
| 3295 | statusCode: error.status,
|
| 3296 | loaderHeaders: {},
|
| 3297 | actionHeaders: {}
|
| 3298 | };
|
| 3299 | return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
| 3300 | } else if (!matches) {
|
| 3301 | let error = getInternalRouterError(404, { pathname: location.pathname });
|
| 3302 | let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
|
| 3303 | let staticContext = {
|
| 3304 | basename,
|
| 3305 | location,
|
| 3306 | matches: notFoundMatches,
|
| 3307 | loaderData: {},
|
| 3308 | actionData: null,
|
| 3309 | errors: {
|
| 3310 | [route.id]: error
|
| 3311 | },
|
| 3312 | statusCode: error.status,
|
| 3313 | loaderHeaders: {},
|
| 3314 | actionHeaders: {}
|
| 3315 | };
|
| 3316 | return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
|
| 3317 | }
|
| 3318 | if (generateMiddlewareResponse) {
|
| 3319 | invariant(
|
| 3320 | requestContext instanceof RouterContextProvider,
|
| 3321 | "When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
| 3322 | );
|
| 3323 | try {
|
| 3324 | await loadLazyMiddlewareForMatches(
|
| 3325 | matches,
|
| 3326 | manifest,
|
| 3327 | mapRouteProperties2
|
| 3328 | );
|
| 3329 | let renderedStaticContext;
|
| 3330 | let response = await runServerMiddlewarePipeline(
|
| 3331 | {
|
| 3332 | request,
|
| 3333 | unstable_url: createDataFunctionUrl(request, location),
|
| 3334 | unstable_pattern: getRoutePattern(matches),
|
| 3335 | matches,
|
| 3336 | params: matches[0].params,
|
| 3337 |
|
| 3338 |
|
| 3339 | context: requestContext
|
| 3340 | },
|
| 3341 | async () => {
|
| 3342 | let res = await generateMiddlewareResponse(
|
| 3343 | async (revalidationRequest, opts2 = {}) => {
|
| 3344 | let result2 = await queryImpl(
|
| 3345 | revalidationRequest,
|
| 3346 | location,
|
| 3347 | matches,
|
| 3348 | requestContext,
|
| 3349 | dataStrategy || null,
|
| 3350 | skipLoaderErrorBubbling === true,
|
| 3351 | null,
|
| 3352 | "filterMatchesToLoad" in opts2 ? _nullishCoalesce(opts2.filterMatchesToLoad, () => ( null)) : _nullishCoalesce(filterMatchesToLoad, () => ( null)),
|
| 3353 | skipRevalidation === true
|
| 3354 | );
|
| 3355 | if (isResponse(result2)) {
|
| 3356 | return result2;
|
| 3357 | }
|
| 3358 | renderedStaticContext = { location, basename, ...result2 };
|
| 3359 | return renderedStaticContext;
|
| 3360 | }
|
| 3361 | );
|
| 3362 | return res;
|
| 3363 | },
|
| 3364 | async (error, routeId) => {
|
| 3365 | if (isRedirectResponse(error)) {
|
| 3366 | return error;
|
| 3367 | }
|
| 3368 | if (isResponse(error)) {
|
| 3369 | try {
|
| 3370 | error = new ErrorResponseImpl(
|
| 3371 | error.status,
|
| 3372 | error.statusText,
|
| 3373 | await parseResponseBody(error)
|
| 3374 | );
|
| 3375 | } catch (e) {
|
| 3376 | error = e;
|
| 3377 | }
|
| 3378 | }
|
| 3379 | if (isDataWithResponseInit(error)) {
|
| 3380 | error = dataWithResponseInitToErrorResponse(error);
|
| 3381 | }
|
| 3382 | if (renderedStaticContext) {
|
| 3383 | if (routeId in renderedStaticContext.loaderData) {
|
| 3384 | renderedStaticContext.loaderData[routeId] = void 0;
|
| 3385 | }
|
| 3386 | let staticContext = getStaticContextFromError(
|
| 3387 | dataRoutes,
|
| 3388 | renderedStaticContext,
|
| 3389 | error,
|
| 3390 | skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
|
| 3391 | );
|
| 3392 | return generateMiddlewareResponse(
|
| 3393 | () => Promise.resolve(staticContext)
|
| 3394 | );
|
| 3395 | } else {
|
| 3396 | let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
|
| 3397 | matches,
|
| 3398 | _optionalChain([matches, 'access', _32 => _32.find, 'call', _33 => _33(
|
| 3399 | (m) => m.route.id === routeId || m.route.loader
|
| 3400 | ), 'optionalAccess', _34 => _34.route, 'access', _35 => _35.id]) || routeId
|
| 3401 | ).route.id;
|
| 3402 | let staticContext = {
|
| 3403 | matches,
|
| 3404 | location,
|
| 3405 | basename,
|
| 3406 | loaderData: {},
|
| 3407 | actionData: null,
|
| 3408 | errors: {
|
| 3409 | [boundaryRouteId]: error
|
| 3410 | },
|
| 3411 | statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
| 3412 | actionHeaders: {},
|
| 3413 | loaderHeaders: {}
|
| 3414 | };
|
| 3415 | return generateMiddlewareResponse(
|
| 3416 | () => Promise.resolve(staticContext)
|
| 3417 | );
|
| 3418 | }
|
| 3419 | }
|
| 3420 | );
|
| 3421 | invariant(isResponse(response), "Expected a response in query()");
|
| 3422 | return response;
|
| 3423 | } catch (e) {
|
| 3424 | if (isResponse(e)) {
|
| 3425 | return e;
|
| 3426 | }
|
| 3427 | throw e;
|
| 3428 | }
|
| 3429 | }
|
| 3430 | let result = await queryImpl(
|
| 3431 | request,
|
| 3432 | location,
|
| 3433 | matches,
|
| 3434 | requestContext,
|
| 3435 | dataStrategy || null,
|
| 3436 | skipLoaderErrorBubbling === true,
|
| 3437 | null,
|
| 3438 | filterMatchesToLoad || null,
|
| 3439 | skipRevalidation === true
|
| 3440 | );
|
| 3441 | if (isResponse(result)) {
|
| 3442 | return result;
|
| 3443 | }
|
| 3444 | return { location, basename, ...result };
|
| 3445 | }
|
| 3446 | async function queryRoute(request, {
|
| 3447 | routeId,
|
| 3448 | requestContext,
|
| 3449 | dataStrategy,
|
| 3450 | generateMiddlewareResponse,
|
| 3451 | unstable_normalizePath
|
| 3452 | } = {}) {
|
| 3453 | let normalizePath = unstable_normalizePath || defaultNormalizePath;
|
| 3454 | let method = request.method;
|
| 3455 | let location = createLocation("", normalizePath(request), null, "default");
|
| 3456 | let matches = matchRoutes(dataRoutes, location, basename);
|
| 3457 | requestContext = requestContext != null ? requestContext : new RouterContextProvider();
|
| 3458 | if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
|
| 3459 | throw getInternalRouterError(405, { method });
|
| 3460 | } else if (!matches) {
|
| 3461 | throw getInternalRouterError(404, { pathname: location.pathname });
|
| 3462 | }
|
| 3463 | let match = routeId ? matches.find((m) => m.route.id === routeId) : getTargetMatch(matches, location);
|
| 3464 | if (routeId && !match) {
|
| 3465 | throw getInternalRouterError(403, {
|
| 3466 | pathname: location.pathname,
|
| 3467 | routeId
|
| 3468 | });
|
| 3469 | } else if (!match) {
|
| 3470 | throw getInternalRouterError(404, { pathname: location.pathname });
|
| 3471 | }
|
| 3472 | if (generateMiddlewareResponse) {
|
| 3473 | invariant(
|
| 3474 | requestContext instanceof RouterContextProvider,
|
| 3475 | "When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
|
| 3476 | );
|
| 3477 | await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties2);
|
| 3478 | let response = await runServerMiddlewarePipeline(
|
| 3479 | {
|
| 3480 | request,
|
| 3481 | unstable_url: createDataFunctionUrl(request, location),
|
| 3482 | unstable_pattern: getRoutePattern(matches),
|
| 3483 | matches,
|
| 3484 | params: matches[0].params,
|
| 3485 |
|
| 3486 |
|
| 3487 | context: requestContext
|
| 3488 | },
|
| 3489 | async () => {
|
| 3490 | let res = await generateMiddlewareResponse(
|
| 3491 | async (innerRequest) => {
|
| 3492 | let result2 = await queryImpl(
|
| 3493 | innerRequest,
|
| 3494 | location,
|
| 3495 | matches,
|
| 3496 | requestContext,
|
| 3497 | dataStrategy || null,
|
| 3498 | false,
|
| 3499 | match,
|
| 3500 | null,
|
| 3501 | false
|
| 3502 | );
|
| 3503 | let processed = handleQueryResult(result2);
|
| 3504 | return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
|
| 3505 | }
|
| 3506 | );
|
| 3507 | return res;
|
| 3508 | },
|
| 3509 | (error) => {
|
| 3510 | if (isDataWithResponseInit(error)) {
|
| 3511 | return Promise.resolve(dataWithResponseInitToResponse(error));
|
| 3512 | }
|
| 3513 | if (isResponse(error)) {
|
| 3514 | return Promise.resolve(error);
|
| 3515 | }
|
| 3516 | throw error;
|
| 3517 | }
|
| 3518 | );
|
| 3519 | return response;
|
| 3520 | }
|
| 3521 | let result = await queryImpl(
|
| 3522 | request,
|
| 3523 | location,
|
| 3524 | matches,
|
| 3525 | requestContext,
|
| 3526 | dataStrategy || null,
|
| 3527 | false,
|
| 3528 | match,
|
| 3529 | null,
|
| 3530 | false
|
| 3531 | );
|
| 3532 | return handleQueryResult(result);
|
| 3533 | function handleQueryResult(result2) {
|
| 3534 | if (isResponse(result2)) {
|
| 3535 | return result2;
|
| 3536 | }
|
| 3537 | let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
|
| 3538 | if (error !== void 0) {
|
| 3539 | throw error;
|
| 3540 | }
|
| 3541 | if (result2.actionData) {
|
| 3542 | return Object.values(result2.actionData)[0];
|
| 3543 | }
|
| 3544 | if (result2.loaderData) {
|
| 3545 | return Object.values(result2.loaderData)[0];
|
| 3546 | }
|
| 3547 | return void 0;
|
| 3548 | }
|
| 3549 | }
|
| 3550 | async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
|
| 3551 | invariant(
|
| 3552 | request.signal,
|
| 3553 | "query()/queryRoute() requests must contain an AbortController signal"
|
| 3554 | );
|
| 3555 | try {
|
| 3556 | if (isMutationMethod(request.method)) {
|
| 3557 | let result2 = await submit(
|
| 3558 | request,
|
| 3559 | location,
|
| 3560 | matches,
|
| 3561 | routeMatch || getTargetMatch(matches, location),
|
| 3562 | requestContext,
|
| 3563 | dataStrategy,
|
| 3564 | skipLoaderErrorBubbling,
|
| 3565 | routeMatch != null,
|
| 3566 | filterMatchesToLoad,
|
| 3567 | skipRevalidation
|
| 3568 | );
|
| 3569 | return result2;
|
| 3570 | }
|
| 3571 | let result = await loadRouteData(
|
| 3572 | request,
|
| 3573 | location,
|
| 3574 | matches,
|
| 3575 | requestContext,
|
| 3576 | dataStrategy,
|
| 3577 | skipLoaderErrorBubbling,
|
| 3578 | routeMatch,
|
| 3579 | filterMatchesToLoad
|
| 3580 | );
|
| 3581 | return isResponse(result) ? result : {
|
| 3582 | ...result,
|
| 3583 | actionData: null,
|
| 3584 | actionHeaders: {}
|
| 3585 | };
|
| 3586 | } catch (e) {
|
| 3587 | if (isDataStrategyResult(e) && isResponse(e.result)) {
|
| 3588 | if (e.type === "error" ) {
|
| 3589 | throw e.result;
|
| 3590 | }
|
| 3591 | return e.result;
|
| 3592 | }
|
| 3593 | if (isRedirectResponse(e)) {
|
| 3594 | return e;
|
| 3595 | }
|
| 3596 | throw e;
|
| 3597 | }
|
| 3598 | }
|
| 3599 | async function submit(request, location, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest, filterMatchesToLoad, skipRevalidation) {
|
| 3600 | let result;
|
| 3601 | if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
| 3602 | let error = getInternalRouterError(405, {
|
| 3603 | method: request.method,
|
| 3604 | pathname: new URL(request.url).pathname,
|
| 3605 | routeId: actionMatch.route.id
|
| 3606 | });
|
| 3607 | if (isRouteRequest) {
|
| 3608 | throw error;
|
| 3609 | }
|
| 3610 | result = {
|
| 3611 | type: "error" ,
|
| 3612 | error
|
| 3613 | };
|
| 3614 | } else {
|
| 3615 | let dsMatches = getTargetedDataStrategyMatches(
|
| 3616 | mapRouteProperties2,
|
| 3617 | manifest,
|
| 3618 | request,
|
| 3619 | location,
|
| 3620 | matches,
|
| 3621 | actionMatch,
|
| 3622 | [],
|
| 3623 | requestContext
|
| 3624 | );
|
| 3625 | let results = await callDataStrategy(
|
| 3626 | request,
|
| 3627 | location,
|
| 3628 | dsMatches,
|
| 3629 | isRouteRequest,
|
| 3630 | requestContext,
|
| 3631 | dataStrategy
|
| 3632 | );
|
| 3633 | result = results[actionMatch.route.id];
|
| 3634 | if (request.signal.aborted) {
|
| 3635 | throwStaticHandlerAbortedError(request, isRouteRequest);
|
| 3636 | }
|
| 3637 | }
|
| 3638 | if (isRedirectResult(result)) {
|
| 3639 | throw new Response(null, {
|
| 3640 | status: result.response.status,
|
| 3641 | headers: {
|
| 3642 | Location: result.response.headers.get("Location")
|
| 3643 | }
|
| 3644 | });
|
| 3645 | }
|
| 3646 | if (isRouteRequest) {
|
| 3647 | if (isErrorResult(result)) {
|
| 3648 | throw result.error;
|
| 3649 | }
|
| 3650 | return {
|
| 3651 | matches: [actionMatch],
|
| 3652 | loaderData: {},
|
| 3653 | actionData: { [actionMatch.route.id]: result.data },
|
| 3654 | errors: null,
|
| 3655 |
|
| 3656 |
|
| 3657 | statusCode: 200,
|
| 3658 | loaderHeaders: {},
|
| 3659 | actionHeaders: {}
|
| 3660 | };
|
| 3661 | }
|
| 3662 | if (skipRevalidation) {
|
| 3663 | if (isErrorResult(result)) {
|
| 3664 | let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
| 3665 | return {
|
| 3666 | statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
| 3667 | actionData: null,
|
| 3668 | actionHeaders: {
|
| 3669 | ...result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
| 3670 | },
|
| 3671 | matches,
|
| 3672 | loaderData: {},
|
| 3673 | errors: {
|
| 3674 | [boundaryMatch.route.id]: result.error
|
| 3675 | },
|
| 3676 | loaderHeaders: {}
|
| 3677 | };
|
| 3678 | } else {
|
| 3679 | return {
|
| 3680 | actionData: {
|
| 3681 | [actionMatch.route.id]: result.data
|
| 3682 | },
|
| 3683 | actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {},
|
| 3684 | matches,
|
| 3685 | loaderData: {},
|
| 3686 | errors: null,
|
| 3687 | statusCode: result.statusCode || 200,
|
| 3688 | loaderHeaders: {}
|
| 3689 | };
|
| 3690 | }
|
| 3691 | }
|
| 3692 | let loaderRequest = new Request(request.url, {
|
| 3693 | headers: request.headers,
|
| 3694 | redirect: request.redirect,
|
| 3695 | signal: request.signal
|
| 3696 | });
|
| 3697 | if (isErrorResult(result)) {
|
| 3698 | let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id);
|
| 3699 | let handlerContext2 = await loadRouteData(
|
| 3700 | loaderRequest,
|
| 3701 | location,
|
| 3702 | matches,
|
| 3703 | requestContext,
|
| 3704 | dataStrategy,
|
| 3705 | skipLoaderErrorBubbling,
|
| 3706 | null,
|
| 3707 | filterMatchesToLoad,
|
| 3708 | [boundaryMatch.route.id, result]
|
| 3709 | );
|
| 3710 | return {
|
| 3711 | ...handlerContext2,
|
| 3712 | statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500,
|
| 3713 | actionData: null,
|
| 3714 | actionHeaders: {
|
| 3715 | ...result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
| 3716 | }
|
| 3717 | };
|
| 3718 | }
|
| 3719 | let handlerContext = await loadRouteData(
|
| 3720 | loaderRequest,
|
| 3721 | location,
|
| 3722 | matches,
|
| 3723 | requestContext,
|
| 3724 | dataStrategy,
|
| 3725 | skipLoaderErrorBubbling,
|
| 3726 | null,
|
| 3727 | filterMatchesToLoad
|
| 3728 | );
|
| 3729 | return {
|
| 3730 | ...handlerContext,
|
| 3731 | actionData: {
|
| 3732 | [actionMatch.route.id]: result.data
|
| 3733 | },
|
| 3734 |
|
| 3735 | ...result.statusCode ? { statusCode: result.statusCode } : {},
|
| 3736 | actionHeaders: result.headers ? { [actionMatch.route.id]: result.headers } : {}
|
| 3737 | };
|
| 3738 | }
|
| 3739 | async function loadRouteData(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, pendingActionResult) {
|
| 3740 | let isRouteRequest = routeMatch != null;
|
| 3741 | if (isRouteRequest && !_optionalChain([routeMatch, 'optionalAccess', _36 => _36.route, 'access', _37 => _37.loader]) && !_optionalChain([routeMatch, 'optionalAccess', _38 => _38.route, 'access', _39 => _39.lazy])) {
|
| 3742 | throw getInternalRouterError(400, {
|
| 3743 | method: request.method,
|
| 3744 | pathname: new URL(request.url).pathname,
|
| 3745 | routeId: _optionalChain([routeMatch, 'optionalAccess', _40 => _40.route, 'access', _41 => _41.id])
|
| 3746 | });
|
| 3747 | }
|
| 3748 | let dsMatches;
|
| 3749 | if (routeMatch) {
|
| 3750 | dsMatches = getTargetedDataStrategyMatches(
|
| 3751 | mapRouteProperties2,
|
| 3752 | manifest,
|
| 3753 | request,
|
| 3754 | location,
|
| 3755 | matches,
|
| 3756 | routeMatch,
|
| 3757 | [],
|
| 3758 | requestContext
|
| 3759 | );
|
| 3760 | } else {
|
| 3761 | let maxIdx = pendingActionResult && isErrorResult(pendingActionResult[1]) ? (
|
| 3762 |
|
| 3763 | matches.findIndex((m) => m.route.id === pendingActionResult[0]) - 1
|
| 3764 | ) : void 0;
|
| 3765 | let pattern = getRoutePattern(matches);
|
| 3766 | dsMatches = matches.map((match, index) => {
|
| 3767 | if (maxIdx != null && index > maxIdx) {
|
| 3768 | return getDataStrategyMatch(
|
| 3769 | mapRouteProperties2,
|
| 3770 | manifest,
|
| 3771 | request,
|
| 3772 | location,
|
| 3773 | pattern,
|
| 3774 | match,
|
| 3775 | [],
|
| 3776 | requestContext,
|
| 3777 | false
|
| 3778 | );
|
| 3779 | }
|
| 3780 | return getDataStrategyMatch(
|
| 3781 | mapRouteProperties2,
|
| 3782 | manifest,
|
| 3783 | request,
|
| 3784 | location,
|
| 3785 | pattern,
|
| 3786 | match,
|
| 3787 | [],
|
| 3788 | requestContext,
|
| 3789 | (match.route.loader || match.route.lazy) != null && (!filterMatchesToLoad || filterMatchesToLoad(match))
|
| 3790 | );
|
| 3791 | });
|
| 3792 | }
|
| 3793 | if (!dataStrategy && !dsMatches.some((m) => m.shouldLoad)) {
|
| 3794 | return {
|
| 3795 | matches,
|
| 3796 | loaderData: {},
|
| 3797 | errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? {
|
| 3798 | [pendingActionResult[0]]: pendingActionResult[1].error
|
| 3799 | } : null,
|
| 3800 | statusCode: 200,
|
| 3801 | loaderHeaders: {}
|
| 3802 | };
|
| 3803 | }
|
| 3804 | let results = await callDataStrategy(
|
| 3805 | request,
|
| 3806 | location,
|
| 3807 | dsMatches,
|
| 3808 | isRouteRequest,
|
| 3809 | requestContext,
|
| 3810 | dataStrategy
|
| 3811 | );
|
| 3812 | if (request.signal.aborted) {
|
| 3813 | throwStaticHandlerAbortedError(request, isRouteRequest);
|
| 3814 | }
|
| 3815 | let handlerContext = processRouteLoaderData(
|
| 3816 | matches,
|
| 3817 | results,
|
| 3818 | pendingActionResult,
|
| 3819 | true,
|
| 3820 | skipLoaderErrorBubbling
|
| 3821 | );
|
| 3822 | return {
|
| 3823 | ...handlerContext,
|
| 3824 | matches
|
| 3825 | };
|
| 3826 | }
|
| 3827 | async function callDataStrategy(request, location, matches, isRouteRequest, requestContext, dataStrategy) {
|
| 3828 | let results = await callDataStrategyImpl(
|
| 3829 | dataStrategy || defaultDataStrategy,
|
| 3830 | request,
|
| 3831 | location,
|
| 3832 | matches,
|
| 3833 | null,
|
| 3834 | requestContext,
|
| 3835 | true
|
| 3836 | );
|
| 3837 | let dataResults = {};
|
| 3838 | await Promise.all(
|
| 3839 | matches.map(async (match) => {
|
| 3840 | if (!(match.route.id in results)) {
|
| 3841 | return;
|
| 3842 | }
|
| 3843 | let result = results[match.route.id];
|
| 3844 | if (isRedirectDataStrategyResult(result)) {
|
| 3845 | let response = result.result;
|
| 3846 | throw normalizeRelativeRoutingRedirectResponse(
|
| 3847 | response,
|
| 3848 | request,
|
| 3849 | match.route.id,
|
| 3850 | matches,
|
| 3851 | basename
|
| 3852 | );
|
| 3853 | }
|
| 3854 | if (isRouteRequest) {
|
| 3855 | if (isResponse(result.result)) {
|
| 3856 | throw result;
|
| 3857 | } else if (isDataWithResponseInit(result.result)) {
|
| 3858 | throw dataWithResponseInitToResponse(result.result);
|
| 3859 | }
|
| 3860 | }
|
| 3861 | dataResults[match.route.id] = await convertDataStrategyResultToDataResult(result);
|
| 3862 | })
|
| 3863 | );
|
| 3864 | return dataResults;
|
| 3865 | }
|
| 3866 | return {
|
| 3867 | dataRoutes,
|
| 3868 | query,
|
| 3869 | queryRoute
|
| 3870 | };
|
| 3871 | }
|
| 3872 | function getStaticContextFromError(routes, handlerContext, error, boundaryId) {
|
| 3873 | let errorBoundaryId = boundaryId || handlerContext._deepestRenderedBoundaryId || routes[0].id;
|
| 3874 | return {
|
| 3875 | ...handlerContext,
|
| 3876 | statusCode: isRouteErrorResponse(error) ? error.status : 500,
|
| 3877 | errors: {
|
| 3878 | [errorBoundaryId]: error
|
| 3879 | }
|
| 3880 | };
|
| 3881 | }
|
| 3882 | function throwStaticHandlerAbortedError(request, isRouteRequest) {
|
| 3883 | if (request.signal.reason !== void 0) {
|
| 3884 | throw request.signal.reason;
|
| 3885 | }
|
| 3886 | let method = isRouteRequest ? "queryRoute" : "query";
|
| 3887 | throw new Error(
|
| 3888 | `${method}() call aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
|
| 3889 | );
|
| 3890 | }
|
| 3891 | function isSubmissionNavigation(opts) {
|
| 3892 | return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== void 0);
|
| 3893 | }
|
| 3894 | function defaultNormalizePath(request) {
|
| 3895 | let url = new URL(request.url);
|
| 3896 | return {
|
| 3897 | pathname: url.pathname,
|
| 3898 | search: url.search,
|
| 3899 | hash: url.hash
|
| 3900 | };
|
| 3901 | }
|
| 3902 | function normalizeTo(location, matches, basename, to, fromRouteId, relative) {
|
| 3903 | let contextualMatches;
|
| 3904 | let activeRouteMatch;
|
| 3905 | if (fromRouteId) {
|
| 3906 | contextualMatches = [];
|
| 3907 | for (let match of matches) {
|
| 3908 | contextualMatches.push(match);
|
| 3909 | if (match.route.id === fromRouteId) {
|
| 3910 | activeRouteMatch = match;
|
| 3911 | break;
|
| 3912 | }
|
| 3913 | }
|
| 3914 | } else {
|
| 3915 | contextualMatches = matches;
|
| 3916 | activeRouteMatch = matches[matches.length - 1];
|
| 3917 | }
|
| 3918 | let path = resolveTo(
|
| 3919 | to ? to : ".",
|
| 3920 | getResolveToMatches(contextualMatches),
|
| 3921 | stripBasename(location.pathname, basename) || location.pathname,
|
| 3922 | relative === "path"
|
| 3923 | );
|
| 3924 | if (to == null) {
|
| 3925 | path.search = location.search;
|
| 3926 | path.hash = location.hash;
|
| 3927 | }
|
| 3928 | if ((to == null || to === "" || to === ".") && activeRouteMatch) {
|
| 3929 | let nakedIndex = hasNakedIndexQuery(path.search);
|
| 3930 | if (activeRouteMatch.route.index && !nakedIndex) {
|
| 3931 | path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
| 3932 | } else if (!activeRouteMatch.route.index && nakedIndex) {
|
| 3933 | let params = new URLSearchParams(path.search);
|
| 3934 | let indexValues = params.getAll("index");
|
| 3935 | params.delete("index");
|
| 3936 | indexValues.filter((v) => v).forEach((v) => params.append("index", v));
|
| 3937 | let qs = params.toString();
|
| 3938 | path.search = qs ? `?${qs}` : "";
|
| 3939 | }
|
| 3940 | }
|
| 3941 | if (basename !== "/") {
|
| 3942 | path.pathname = prependBasename({ basename, pathname: path.pathname });
|
| 3943 | }
|
| 3944 | return createPath(path);
|
| 3945 | }
|
| 3946 | function normalizeNavigateOptions(isFetcher, path, opts) {
|
| 3947 | if (!opts || !isSubmissionNavigation(opts)) {
|
| 3948 | return { path };
|
| 3949 | }
|
| 3950 | if (opts.formMethod && !isValidMethod(opts.formMethod)) {
|
| 3951 | return {
|
| 3952 | path,
|
| 3953 | error: getInternalRouterError(405, { method: opts.formMethod })
|
| 3954 | };
|
| 3955 | }
|
| 3956 | let getInvalidBodyError = () => ({
|
| 3957 | path,
|
| 3958 | error: getInternalRouterError(400, { type: "invalid-body" })
|
| 3959 | });
|
| 3960 | let rawFormMethod = opts.formMethod || "get";
|
| 3961 | let formMethod = rawFormMethod.toUpperCase();
|
| 3962 | let formAction = stripHashFromPath(path);
|
| 3963 | if (opts.body !== void 0) {
|
| 3964 | if (opts.formEncType === "text/plain") {
|
| 3965 | if (!isMutationMethod(formMethod)) {
|
| 3966 | return getInvalidBodyError();
|
| 3967 | }
|
| 3968 | let text = typeof opts.body === "string" ? opts.body : opts.body instanceof FormData || opts.body instanceof URLSearchParams ? (
|
| 3969 |
|
| 3970 | Array.from(opts.body.entries()).reduce(
|
| 3971 | (acc, [name, value]) => `${acc}${name}=${value}
|
| 3972 | `,
|
| 3973 | ""
|
| 3974 | )
|
| 3975 | ) : String(opts.body);
|
| 3976 | return {
|
| 3977 | path,
|
| 3978 | submission: {
|
| 3979 | formMethod,
|
| 3980 | formAction,
|
| 3981 | formEncType: opts.formEncType,
|
| 3982 | formData: void 0,
|
| 3983 | json: void 0,
|
| 3984 | text
|
| 3985 | }
|
| 3986 | };
|
| 3987 | } else if (opts.formEncType === "application/json") {
|
| 3988 | if (!isMutationMethod(formMethod)) {
|
| 3989 | return getInvalidBodyError();
|
| 3990 | }
|
| 3991 | try {
|
| 3992 | let json = typeof opts.body === "string" ? JSON.parse(opts.body) : opts.body;
|
| 3993 | return {
|
| 3994 | path,
|
| 3995 | submission: {
|
| 3996 | formMethod,
|
| 3997 | formAction,
|
| 3998 | formEncType: opts.formEncType,
|
| 3999 | formData: void 0,
|
| 4000 | json,
|
| 4001 | text: void 0
|
| 4002 | }
|
| 4003 | };
|
| 4004 | } catch (e) {
|
| 4005 | return getInvalidBodyError();
|
| 4006 | }
|
| 4007 | }
|
| 4008 | }
|
| 4009 | invariant(
|
| 4010 | typeof FormData === "function",
|
| 4011 | "FormData is not available in this environment"
|
| 4012 | );
|
| 4013 | let searchParams;
|
| 4014 | let formData;
|
| 4015 | if (opts.formData) {
|
| 4016 | searchParams = convertFormDataToSearchParams(opts.formData);
|
| 4017 | formData = opts.formData;
|
| 4018 | } else if (opts.body instanceof FormData) {
|
| 4019 | searchParams = convertFormDataToSearchParams(opts.body);
|
| 4020 | formData = opts.body;
|
| 4021 | } else if (opts.body instanceof URLSearchParams) {
|
| 4022 | searchParams = opts.body;
|
| 4023 | formData = convertSearchParamsToFormData(searchParams);
|
| 4024 | } else if (opts.body == null) {
|
| 4025 | searchParams = new URLSearchParams();
|
| 4026 | formData = new FormData();
|
| 4027 | } else {
|
| 4028 | try {
|
| 4029 | searchParams = new URLSearchParams(opts.body);
|
| 4030 | formData = convertSearchParamsToFormData(searchParams);
|
| 4031 | } catch (e) {
|
| 4032 | return getInvalidBodyError();
|
| 4033 | }
|
| 4034 | }
|
| 4035 | let submission = {
|
| 4036 | formMethod,
|
| 4037 | formAction,
|
| 4038 | formEncType: opts && opts.formEncType || "application/x-www-form-urlencoded",
|
| 4039 | formData,
|
| 4040 | json: void 0,
|
| 4041 | text: void 0
|
| 4042 | };
|
| 4043 | if (isMutationMethod(submission.formMethod)) {
|
| 4044 | return { path, submission };
|
| 4045 | }
|
| 4046 | let parsedPath = parsePath(path);
|
| 4047 | if (isFetcher && parsedPath.search && hasNakedIndexQuery(parsedPath.search)) {
|
| 4048 | searchParams.append("index", "");
|
| 4049 | }
|
| 4050 | parsedPath.search = `?${searchParams}`;
|
| 4051 | return { path: createPath(parsedPath), submission };
|
| 4052 | }
|
| 4053 | function getMatchesToLoad(request, scopedContext, mapRouteProperties2, manifest, history, state, matches, submission, location, lazyRoutePropertiesToSkip, initialHydration, isRevalidationRequired, cancelledFetcherLoads, fetchersQueuedForDeletion, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, hasPatchRoutesOnNavigation, pendingActionResult, callSiteDefaultShouldRevalidate) {
|
| 4054 | let actionResult = pendingActionResult ? isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : pendingActionResult[1].data : void 0;
|
| 4055 | let currentUrl = history.createURL(state.location);
|
| 4056 | let nextUrl = history.createURL(location);
|
| 4057 | let maxIdx;
|
| 4058 | if (initialHydration && state.errors) {
|
| 4059 | let boundaryId = Object.keys(state.errors)[0];
|
| 4060 | maxIdx = matches.findIndex((m) => m.route.id === boundaryId);
|
| 4061 | } else if (pendingActionResult && isErrorResult(pendingActionResult[1])) {
|
| 4062 | let boundaryId = pendingActionResult[0];
|
| 4063 | maxIdx = matches.findIndex((m) => m.route.id === boundaryId) - 1;
|
| 4064 | }
|
| 4065 | let actionStatus = pendingActionResult ? pendingActionResult[1].statusCode : void 0;
|
| 4066 | let shouldSkipRevalidation = actionStatus && actionStatus >= 400;
|
| 4067 | let baseShouldRevalidateArgs = {
|
| 4068 | currentUrl,
|
| 4069 | currentParams: _optionalChain([state, 'access', _42 => _42.matches, 'access', _43 => _43[0], 'optionalAccess', _44 => _44.params]) || {},
|
| 4070 | nextUrl,
|
| 4071 | nextParams: matches[0].params,
|
| 4072 | ...submission,
|
| 4073 | actionResult,
|
| 4074 | actionStatus
|
| 4075 | };
|
| 4076 | let pattern = getRoutePattern(matches);
|
| 4077 | let dsMatches = matches.map((match, index) => {
|
| 4078 | let { route } = match;
|
| 4079 | let forceShouldLoad = null;
|
| 4080 | if (maxIdx != null && index > maxIdx) {
|
| 4081 | forceShouldLoad = false;
|
| 4082 | } else if (route.lazy) {
|
| 4083 | forceShouldLoad = true;
|
| 4084 | } else if (!routeHasLoaderOrMiddleware(route)) {
|
| 4085 | forceShouldLoad = false;
|
| 4086 | } else if (initialHydration) {
|
| 4087 | let { shouldLoad: shouldLoad2 } = getRouteHydrationStatus(
|
| 4088 | route,
|
| 4089 | state.loaderData,
|
| 4090 | state.errors
|
| 4091 | );
|
| 4092 | forceShouldLoad = shouldLoad2;
|
| 4093 | } else if (isNewLoader(state.loaderData, state.matches[index], match)) {
|
| 4094 | forceShouldLoad = true;
|
| 4095 | }
|
| 4096 | if (forceShouldLoad !== null) {
|
| 4097 | return getDataStrategyMatch(
|
| 4098 | mapRouteProperties2,
|
| 4099 | manifest,
|
| 4100 | request,
|
| 4101 | location,
|
| 4102 | pattern,
|
| 4103 | match,
|
| 4104 | lazyRoutePropertiesToSkip,
|
| 4105 | scopedContext,
|
| 4106 | forceShouldLoad
|
| 4107 | );
|
| 4108 | }
|
| 4109 | let defaultShouldRevalidate = false;
|
| 4110 | if (typeof callSiteDefaultShouldRevalidate === "boolean") {
|
| 4111 | defaultShouldRevalidate = callSiteDefaultShouldRevalidate;
|
| 4112 | } else if (shouldSkipRevalidation) {
|
| 4113 | defaultShouldRevalidate = false;
|
| 4114 | } else if (isRevalidationRequired) {
|
| 4115 | defaultShouldRevalidate = true;
|
| 4116 | } else if (currentUrl.pathname + currentUrl.search === nextUrl.pathname + nextUrl.search) {
|
| 4117 | defaultShouldRevalidate = true;
|
| 4118 | } else if (currentUrl.search !== nextUrl.search) {
|
| 4119 | defaultShouldRevalidate = true;
|
| 4120 | } else if (isNewRouteInstance(state.matches[index], match)) {
|
| 4121 | defaultShouldRevalidate = true;
|
| 4122 | }
|
| 4123 | let shouldRevalidateArgs = {
|
| 4124 | ...baseShouldRevalidateArgs,
|
| 4125 | defaultShouldRevalidate
|
| 4126 | };
|
| 4127 | let shouldLoad = shouldRevalidateLoader(match, shouldRevalidateArgs);
|
| 4128 | return getDataStrategyMatch(
|
| 4129 | mapRouteProperties2,
|
| 4130 | manifest,
|
| 4131 | request,
|
| 4132 | location,
|
| 4133 | pattern,
|
| 4134 | match,
|
| 4135 | lazyRoutePropertiesToSkip,
|
| 4136 | scopedContext,
|
| 4137 | shouldLoad,
|
| 4138 | shouldRevalidateArgs,
|
| 4139 | callSiteDefaultShouldRevalidate
|
| 4140 | );
|
| 4141 | });
|
| 4142 | let revalidatingFetchers = [];
|
| 4143 | fetchLoadMatches.forEach((f, key) => {
|
| 4144 | if (initialHydration || !matches.some((m) => m.route.id === f.routeId) || fetchersQueuedForDeletion.has(key)) {
|
| 4145 | return;
|
| 4146 | }
|
| 4147 | let fetcher = state.fetchers.get(key);
|
| 4148 | let isMidInitialLoad = fetcher && fetcher.state !== "idle" && fetcher.data === void 0;
|
| 4149 | let fetcherMatches = matchRoutes(routesToUse, f.path, basename);
|
| 4150 | if (!fetcherMatches) {
|
| 4151 | if (hasPatchRoutesOnNavigation && isMidInitialLoad) {
|
| 4152 | return;
|
| 4153 | }
|
| 4154 | revalidatingFetchers.push({
|
| 4155 | key,
|
| 4156 | routeId: f.routeId,
|
| 4157 | path: f.path,
|
| 4158 | matches: null,
|
| 4159 | match: null,
|
| 4160 | request: null,
|
| 4161 | controller: null
|
| 4162 | });
|
| 4163 | return;
|
| 4164 | }
|
| 4165 | if (fetchRedirectIds.has(key)) {
|
| 4166 | return;
|
| 4167 | }
|
| 4168 | let fetcherMatch = getTargetMatch(fetcherMatches, f.path);
|
| 4169 | let fetchController = new AbortController();
|
| 4170 | let fetchRequest = createClientSideRequest(
|
| 4171 | history,
|
| 4172 | f.path,
|
| 4173 | fetchController.signal
|
| 4174 | );
|
| 4175 | let fetcherDsMatches = null;
|
| 4176 | if (cancelledFetcherLoads.has(key)) {
|
| 4177 | cancelledFetcherLoads.delete(key);
|
| 4178 | fetcherDsMatches = getTargetedDataStrategyMatches(
|
| 4179 | mapRouteProperties2,
|
| 4180 | manifest,
|
| 4181 | fetchRequest,
|
| 4182 | f.path,
|
| 4183 | fetcherMatches,
|
| 4184 | fetcherMatch,
|
| 4185 | lazyRoutePropertiesToSkip,
|
| 4186 | scopedContext
|
| 4187 | );
|
| 4188 | } else if (isMidInitialLoad) {
|
| 4189 | if (isRevalidationRequired) {
|
| 4190 | fetcherDsMatches = getTargetedDataStrategyMatches(
|
| 4191 | mapRouteProperties2,
|
| 4192 | manifest,
|
| 4193 | fetchRequest,
|
| 4194 | f.path,
|
| 4195 | fetcherMatches,
|
| 4196 | fetcherMatch,
|
| 4197 | lazyRoutePropertiesToSkip,
|
| 4198 | scopedContext
|
| 4199 | );
|
| 4200 | }
|
| 4201 | } else {
|
| 4202 | let defaultShouldRevalidate;
|
| 4203 | if (typeof callSiteDefaultShouldRevalidate === "boolean") {
|
| 4204 | defaultShouldRevalidate = callSiteDefaultShouldRevalidate;
|
| 4205 | } else if (shouldSkipRevalidation) {
|
| 4206 | defaultShouldRevalidate = false;
|
| 4207 | } else {
|
| 4208 | defaultShouldRevalidate = isRevalidationRequired;
|
| 4209 | }
|
| 4210 | let shouldRevalidateArgs = {
|
| 4211 | ...baseShouldRevalidateArgs,
|
| 4212 | defaultShouldRevalidate
|
| 4213 | };
|
| 4214 | if (shouldRevalidateLoader(fetcherMatch, shouldRevalidateArgs)) {
|
| 4215 | fetcherDsMatches = getTargetedDataStrategyMatches(
|
| 4216 | mapRouteProperties2,
|
| 4217 | manifest,
|
| 4218 | fetchRequest,
|
| 4219 | f.path,
|
| 4220 | fetcherMatches,
|
| 4221 | fetcherMatch,
|
| 4222 | lazyRoutePropertiesToSkip,
|
| 4223 | scopedContext,
|
| 4224 | shouldRevalidateArgs
|
| 4225 | );
|
| 4226 | }
|
| 4227 | }
|
| 4228 | if (fetcherDsMatches) {
|
| 4229 | revalidatingFetchers.push({
|
| 4230 | key,
|
| 4231 | routeId: f.routeId,
|
| 4232 | path: f.path,
|
| 4233 | matches: fetcherDsMatches,
|
| 4234 | match: fetcherMatch,
|
| 4235 | request: fetchRequest,
|
| 4236 | controller: fetchController
|
| 4237 | });
|
| 4238 | }
|
| 4239 | });
|
| 4240 | return { dsMatches, revalidatingFetchers };
|
| 4241 | }
|
| 4242 | function routeHasLoaderOrMiddleware(route) {
|
| 4243 | return route.loader != null || route.middleware != null && route.middleware.length > 0;
|
| 4244 | }
|
| 4245 | function getRouteHydrationStatus(route, loaderData, errors) {
|
| 4246 | if (route.lazy) {
|
| 4247 | return { shouldLoad: true, renderFallback: true };
|
| 4248 | }
|
| 4249 | if (!routeHasLoaderOrMiddleware(route)) {
|
| 4250 | return { shouldLoad: false, renderFallback: false };
|
| 4251 | }
|
| 4252 | let hasData = loaderData != null && route.id in loaderData;
|
| 4253 | let hasError = errors != null && errors[route.id] !== void 0;
|
| 4254 | if (!hasData && hasError) {
|
| 4255 | return { shouldLoad: false, renderFallback: false };
|
| 4256 | }
|
| 4257 | if (typeof route.loader === "function" && route.loader.hydrate === true) {
|
| 4258 | return { shouldLoad: true, renderFallback: !hasData };
|
| 4259 | }
|
| 4260 | let shouldLoad = !hasData && !hasError;
|
| 4261 | return { shouldLoad, renderFallback: shouldLoad };
|
| 4262 | }
|
| 4263 | function isNewLoader(currentLoaderData, currentMatch, match) {
|
| 4264 | let isNew = (
|
| 4265 |
|
| 4266 | !currentMatch ||
|
| 4267 | match.route.id !== currentMatch.route.id
|
| 4268 | );
|
| 4269 | let isMissingData = !currentLoaderData.hasOwnProperty(match.route.id);
|
| 4270 | return isNew || isMissingData;
|
| 4271 | }
|
| 4272 | function isNewRouteInstance(currentMatch, match) {
|
| 4273 | let currentPath = currentMatch.route.path;
|
| 4274 | return (
|
| 4275 |
|
| 4276 | currentMatch.pathname !== match.pathname ||
|
| 4277 |
|
| 4278 | currentPath != null && currentPath.endsWith("*") && currentMatch.params["*"] !== match.params["*"]
|
| 4279 | );
|
| 4280 | }
|
| 4281 | function shouldRevalidateLoader(loaderMatch, arg) {
|
| 4282 | if (loaderMatch.route.shouldRevalidate) {
|
| 4283 | let routeChoice = loaderMatch.route.shouldRevalidate(arg);
|
| 4284 | if (typeof routeChoice === "boolean") {
|
| 4285 | return routeChoice;
|
| 4286 | }
|
| 4287 | }
|
| 4288 | return arg.defaultShouldRevalidate;
|
| 4289 | }
|
| 4290 | function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties2, allowElementMutations) {
|
| 4291 | let childrenToPatch;
|
| 4292 | if (routeId) {
|
| 4293 | let route = manifest[routeId];
|
| 4294 | invariant(
|
| 4295 | route,
|
| 4296 | `No route found to patch children into: routeId = ${routeId}`
|
| 4297 | );
|
| 4298 | if (!route.children) {
|
| 4299 | route.children = [];
|
| 4300 | }
|
| 4301 | childrenToPatch = route.children;
|
| 4302 | } else {
|
| 4303 | childrenToPatch = routesToUse;
|
| 4304 | }
|
| 4305 | let uniqueChildren = [];
|
| 4306 | let existingChildren = [];
|
| 4307 | children.forEach((newRoute) => {
|
| 4308 | let existingRoute = childrenToPatch.find(
|
| 4309 | (existingRoute2) => isSameRoute(newRoute, existingRoute2)
|
| 4310 | );
|
| 4311 | if (existingRoute) {
|
| 4312 | existingChildren.push({ existingRoute, newRoute });
|
| 4313 | } else {
|
| 4314 | uniqueChildren.push(newRoute);
|
| 4315 | }
|
| 4316 | });
|
| 4317 | if (uniqueChildren.length > 0) {
|
| 4318 | let newRoutes = convertRoutesToDataRoutes(
|
| 4319 | uniqueChildren,
|
| 4320 | mapRouteProperties2,
|
| 4321 | [routeId || "_", "patch", String(_optionalChain([childrenToPatch, 'optionalAccess', _45 => _45.length]) || "0")],
|
| 4322 | manifest
|
| 4323 | );
|
| 4324 | childrenToPatch.push(...newRoutes);
|
| 4325 | }
|
| 4326 | if (allowElementMutations && existingChildren.length > 0) {
|
| 4327 | for (let i = 0; i < existingChildren.length; i++) {
|
| 4328 | let { existingRoute, newRoute } = existingChildren[i];
|
| 4329 | let existingRouteTyped = existingRoute;
|
| 4330 | let [newRouteTyped] = convertRoutesToDataRoutes(
|
| 4331 | [newRoute],
|
| 4332 | mapRouteProperties2,
|
| 4333 | [],
|
| 4334 |
|
| 4335 | {},
|
| 4336 |
|
| 4337 | true
|
| 4338 | );
|
| 4339 | Object.assign(existingRouteTyped, {
|
| 4340 | element: newRouteTyped.element ? newRouteTyped.element : existingRouteTyped.element,
|
| 4341 | errorElement: newRouteTyped.errorElement ? newRouteTyped.errorElement : existingRouteTyped.errorElement,
|
| 4342 | hydrateFallbackElement: newRouteTyped.hydrateFallbackElement ? newRouteTyped.hydrateFallbackElement : existingRouteTyped.hydrateFallbackElement
|
| 4343 | });
|
| 4344 | }
|
| 4345 | }
|
| 4346 | }
|
| 4347 | function isSameRoute(newRoute, existingRoute) {
|
| 4348 | if ("id" in newRoute && "id" in existingRoute && newRoute.id === existingRoute.id) {
|
| 4349 | return true;
|
| 4350 | }
|
| 4351 | if (!(newRoute.index === existingRoute.index && newRoute.path === existingRoute.path && newRoute.caseSensitive === existingRoute.caseSensitive)) {
|
| 4352 | return false;
|
| 4353 | }
|
| 4354 | if ((!newRoute.children || newRoute.children.length === 0) && (!existingRoute.children || existingRoute.children.length === 0)) {
|
| 4355 | return true;
|
| 4356 | }
|
| 4357 | return _nullishCoalesce(_optionalChain([newRoute, 'access', _46 => _46.children, 'optionalAccess', _47 => _47.every, 'call', _48 => _48(
|
| 4358 | (aChild, i) => _optionalChain([existingRoute, 'access', _49 => _49.children, 'optionalAccess', _50 => _50.some, 'call', _51 => _51((bChild) => isSameRoute(aChild, bChild))])
|
| 4359 | )]), () => ( false));
|
| 4360 | }
|
| 4361 | var lazyRoutePropertyCache = new WeakMap();
|
| 4362 | var loadLazyRouteProperty = ({
|
| 4363 | key,
|
| 4364 | route,
|
| 4365 | manifest,
|
| 4366 | mapRouteProperties: mapRouteProperties2
|
| 4367 | }) => {
|
| 4368 | let routeToUpdate = manifest[route.id];
|
| 4369 | invariant(routeToUpdate, "No route found in manifest");
|
| 4370 | if (!routeToUpdate.lazy || typeof routeToUpdate.lazy !== "object") {
|
| 4371 | return;
|
| 4372 | }
|
| 4373 | let lazyFn = routeToUpdate.lazy[key];
|
| 4374 | if (!lazyFn) {
|
| 4375 | return;
|
| 4376 | }
|
| 4377 | let cache = lazyRoutePropertyCache.get(routeToUpdate);
|
| 4378 | if (!cache) {
|
| 4379 | cache = {};
|
| 4380 | lazyRoutePropertyCache.set(routeToUpdate, cache);
|
| 4381 | }
|
| 4382 | let cachedPromise = cache[key];
|
| 4383 | if (cachedPromise) {
|
| 4384 | return cachedPromise;
|
| 4385 | }
|
| 4386 | let propertyPromise = (async () => {
|
| 4387 | let isUnsupported = isUnsupportedLazyRouteObjectKey(key);
|
| 4388 | let staticRouteValue = routeToUpdate[key];
|
| 4389 | let isStaticallyDefined = staticRouteValue !== void 0 && key !== "hasErrorBoundary";
|
| 4390 | if (isUnsupported) {
|
| 4391 | warning(
|
| 4392 | !isUnsupported,
|
| 4393 | "Route property " + key + " is not a supported lazy route property. This property will be ignored."
|
| 4394 | );
|
| 4395 | cache[key] = Promise.resolve();
|
| 4396 | } else if (isStaticallyDefined) {
|
| 4397 | warning(
|
| 4398 | false,
|
| 4399 | `Route "${routeToUpdate.id}" has a static property "${key}" defined. The lazy property will be ignored.`
|
| 4400 | );
|
| 4401 | } else {
|
| 4402 | let value = await lazyFn();
|
| 4403 | if (value != null) {
|
| 4404 | Object.assign(routeToUpdate, { [key]: value });
|
| 4405 | Object.assign(routeToUpdate, mapRouteProperties2(routeToUpdate));
|
| 4406 | }
|
| 4407 | }
|
| 4408 | if (typeof routeToUpdate.lazy === "object") {
|
| 4409 | routeToUpdate.lazy[key] = void 0;
|
| 4410 | if (Object.values(routeToUpdate.lazy).every((value) => value === void 0)) {
|
| 4411 | routeToUpdate.lazy = void 0;
|
| 4412 | }
|
| 4413 | }
|
| 4414 | })();
|
| 4415 | cache[key] = propertyPromise;
|
| 4416 | return propertyPromise;
|
| 4417 | };
|
| 4418 | var lazyRouteFunctionCache = new WeakMap();
|
| 4419 | function loadLazyRoute(route, type, manifest, mapRouteProperties2, lazyRoutePropertiesToSkip) {
|
| 4420 | let routeToUpdate = manifest[route.id];
|
| 4421 | invariant(routeToUpdate, "No route found in manifest");
|
| 4422 | if (!route.lazy) {
|
| 4423 | return {
|
| 4424 | lazyRoutePromise: void 0,
|
| 4425 | lazyHandlerPromise: void 0
|
| 4426 | };
|
| 4427 | }
|
| 4428 | if (typeof route.lazy === "function") {
|
| 4429 | let cachedPromise = lazyRouteFunctionCache.get(routeToUpdate);
|
| 4430 | if (cachedPromise) {
|
| 4431 | return {
|
| 4432 | lazyRoutePromise: cachedPromise,
|
| 4433 | lazyHandlerPromise: cachedPromise
|
| 4434 | };
|
| 4435 | }
|
| 4436 | let lazyRoutePromise2 = (async () => {
|
| 4437 | invariant(
|
| 4438 | typeof route.lazy === "function",
|
| 4439 | "No lazy route function found"
|
| 4440 | );
|
| 4441 | let lazyRoute = await route.lazy();
|
| 4442 | let routeUpdates = {};
|
| 4443 | for (let lazyRouteProperty in lazyRoute) {
|
| 4444 | let lazyValue = lazyRoute[lazyRouteProperty];
|
| 4445 | if (lazyValue === void 0) {
|
| 4446 | continue;
|
| 4447 | }
|
| 4448 | let isUnsupported = isUnsupportedLazyRouteFunctionKey(lazyRouteProperty);
|
| 4449 | let staticRouteValue = routeToUpdate[lazyRouteProperty];
|
| 4450 | let isStaticallyDefined = staticRouteValue !== void 0 &&
|
| 4451 |
|
| 4452 | lazyRouteProperty !== "hasErrorBoundary";
|
| 4453 | if (isUnsupported) {
|
| 4454 | warning(
|
| 4455 | !isUnsupported,
|
| 4456 | "Route property " + lazyRouteProperty + " is not a supported property to be returned from a lazy route function. This property will be ignored."
|
| 4457 | );
|
| 4458 | } else if (isStaticallyDefined) {
|
| 4459 | warning(
|
| 4460 | !isStaticallyDefined,
|
| 4461 | `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.`
|
| 4462 | );
|
| 4463 | } else {
|
| 4464 | routeUpdates[lazyRouteProperty] = lazyValue;
|
| 4465 | }
|
| 4466 | }
|
| 4467 | Object.assign(routeToUpdate, routeUpdates);
|
| 4468 | Object.assign(routeToUpdate, {
|
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 | ...mapRouteProperties2(routeToUpdate),
|
| 4473 | lazy: void 0
|
| 4474 | });
|
| 4475 | })();
|
| 4476 | lazyRouteFunctionCache.set(routeToUpdate, lazyRoutePromise2);
|
| 4477 | lazyRoutePromise2.catch(() => {
|
| 4478 | });
|
| 4479 | return {
|
| 4480 | lazyRoutePromise: lazyRoutePromise2,
|
| 4481 | lazyHandlerPromise: lazyRoutePromise2
|
| 4482 | };
|
| 4483 | }
|
| 4484 | let lazyKeys = Object.keys(route.lazy);
|
| 4485 | let lazyPropertyPromises = [];
|
| 4486 | let lazyHandlerPromise = void 0;
|
| 4487 | for (let key of lazyKeys) {
|
| 4488 | if (lazyRoutePropertiesToSkip && lazyRoutePropertiesToSkip.includes(key)) {
|
| 4489 | continue;
|
| 4490 | }
|
| 4491 | let promise = loadLazyRouteProperty({
|
| 4492 | key,
|
| 4493 | route,
|
| 4494 | manifest,
|
| 4495 | mapRouteProperties: mapRouteProperties2
|
| 4496 | });
|
| 4497 | if (promise) {
|
| 4498 | lazyPropertyPromises.push(promise);
|
| 4499 | if (key === type) {
|
| 4500 | lazyHandlerPromise = promise;
|
| 4501 | }
|
| 4502 | }
|
| 4503 | }
|
| 4504 | let lazyRoutePromise = lazyPropertyPromises.length > 0 ? Promise.all(lazyPropertyPromises).then(() => {
|
| 4505 | }) : void 0;
|
| 4506 | _optionalChain([lazyRoutePromise, 'optionalAccess', _52 => _52.catch, 'call', _53 => _53(() => {
|
| 4507 | })]);
|
| 4508 | _optionalChain([lazyHandlerPromise, 'optionalAccess', _54 => _54.catch, 'call', _55 => _55(() => {
|
| 4509 | })]);
|
| 4510 | return {
|
| 4511 | lazyRoutePromise,
|
| 4512 | lazyHandlerPromise
|
| 4513 | };
|
| 4514 | }
|
| 4515 | function isNonNullable(value) {
|
| 4516 | return value !== void 0;
|
| 4517 | }
|
| 4518 | function loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties2) {
|
| 4519 | let promises = matches.map(({ route }) => {
|
| 4520 | if (typeof route.lazy !== "object" || !route.lazy.middleware) {
|
| 4521 | return void 0;
|
| 4522 | }
|
| 4523 | return loadLazyRouteProperty({
|
| 4524 | key: "middleware",
|
| 4525 | route,
|
| 4526 | manifest,
|
| 4527 | mapRouteProperties: mapRouteProperties2
|
| 4528 | });
|
| 4529 | }).filter(isNonNullable);
|
| 4530 | return promises.length > 0 ? Promise.all(promises) : void 0;
|
| 4531 | }
|
| 4532 | async function defaultDataStrategy(args) {
|
| 4533 | let matchesToLoad = args.matches.filter((m) => m.shouldLoad);
|
| 4534 | let keyedResults = {};
|
| 4535 | let results = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
| 4536 | results.forEach((result, i) => {
|
| 4537 | keyedResults[matchesToLoad[i].route.id] = result;
|
| 4538 | });
|
| 4539 | return keyedResults;
|
| 4540 | }
|
| 4541 | async function defaultDataStrategyWithMiddleware(args) {
|
| 4542 | if (!args.matches.some((m) => m.route.middleware)) {
|
| 4543 | return defaultDataStrategy(args);
|
| 4544 | }
|
| 4545 | return runClientMiddlewarePipeline(args, () => defaultDataStrategy(args));
|
| 4546 | }
|
| 4547 | function runServerMiddlewarePipeline(args, handler, errorHandler) {
|
| 4548 | return runMiddlewarePipeline(
|
| 4549 | args,
|
| 4550 | handler,
|
| 4551 | processResult,
|
| 4552 | isResponse,
|
| 4553 | errorHandler
|
| 4554 | );
|
| 4555 | function processResult(result) {
|
| 4556 | return isDataWithResponseInit(result) ? dataWithResponseInitToResponse(result) : result;
|
| 4557 | }
|
| 4558 | }
|
| 4559 | function runClientMiddlewarePipeline(args, handler) {
|
| 4560 | return runMiddlewarePipeline(
|
| 4561 | args,
|
| 4562 | handler,
|
| 4563 | (r) => {
|
| 4564 | if (isRedirectResponse(r)) {
|
| 4565 | throw r;
|
| 4566 | }
|
| 4567 | return r;
|
| 4568 | },
|
| 4569 | isDataStrategyResults,
|
| 4570 | errorHandler
|
| 4571 | );
|
| 4572 | function errorHandler(error, routeId, nextResult) {
|
| 4573 | if (nextResult) {
|
| 4574 | return Promise.resolve(
|
| 4575 | Object.assign(nextResult.value, {
|
| 4576 | [routeId]: { type: "error", result: error }
|
| 4577 | })
|
| 4578 | );
|
| 4579 | } else {
|
| 4580 | let { matches } = args;
|
| 4581 | let maxBoundaryIdx = Math.min(
|
| 4582 |
|
| 4583 | Math.max(
|
| 4584 | matches.findIndex((m) => m.route.id === routeId),
|
| 4585 | 0
|
| 4586 | ),
|
| 4587 |
|
| 4588 | Math.max(
|
| 4589 | matches.findIndex((m) => m.shouldCallHandler()),
|
| 4590 | 0
|
| 4591 | )
|
| 4592 | );
|
| 4593 | let boundaryRouteId = findNearestBoundary(
|
| 4594 | matches,
|
| 4595 | matches[maxBoundaryIdx].route.id
|
| 4596 | ).route.id;
|
| 4597 | return Promise.resolve({
|
| 4598 | [boundaryRouteId]: { type: "error", result: error }
|
| 4599 | });
|
| 4600 | }
|
| 4601 | }
|
| 4602 | }
|
| 4603 | async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
|
| 4604 | let { matches, ...dataFnArgs } = args;
|
| 4605 | let tuples = matches.flatMap(
|
| 4606 | (m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
|
| 4607 | );
|
| 4608 | let result = await callRouteMiddleware(
|
| 4609 | dataFnArgs,
|
| 4610 | tuples,
|
| 4611 | handler,
|
| 4612 | processResult,
|
| 4613 | isResult,
|
| 4614 | errorHandler
|
| 4615 | );
|
| 4616 | return result;
|
| 4617 | }
|
| 4618 | async function callRouteMiddleware(args, middlewares, handler, processResult, isResult, errorHandler, idx = 0) {
|
| 4619 | let { request } = args;
|
| 4620 | if (request.signal.aborted) {
|
| 4621 | throw _nullishCoalesce(request.signal.reason, () => ( new Error(`Request aborted: ${request.method} ${request.url}`)));
|
| 4622 | }
|
| 4623 | let tuple = middlewares[idx];
|
| 4624 | if (!tuple) {
|
| 4625 | let result = await handler();
|
| 4626 | return result;
|
| 4627 | }
|
| 4628 | let [routeId, middleware] = tuple;
|
| 4629 | let nextResult;
|
| 4630 | let next = async () => {
|
| 4631 | if (nextResult) {
|
| 4632 | throw new Error("You may only call `next()` once per middleware");
|
| 4633 | }
|
| 4634 | try {
|
| 4635 | let result = await callRouteMiddleware(
|
| 4636 | args,
|
| 4637 | middlewares,
|
| 4638 | handler,
|
| 4639 | processResult,
|
| 4640 | isResult,
|
| 4641 | errorHandler,
|
| 4642 | idx + 1
|
| 4643 | );
|
| 4644 | nextResult = { value: result };
|
| 4645 | return nextResult.value;
|
| 4646 | } catch (error) {
|
| 4647 | nextResult = { value: await errorHandler(error, routeId, nextResult) };
|
| 4648 | return nextResult.value;
|
| 4649 | }
|
| 4650 | };
|
| 4651 | try {
|
| 4652 | let value = await middleware(args, next);
|
| 4653 | let result = value != null ? processResult(value) : void 0;
|
| 4654 | if (isResult(result)) {
|
| 4655 | return result;
|
| 4656 | } else if (nextResult) {
|
| 4657 | return _nullishCoalesce(result, () => ( nextResult.value));
|
| 4658 | } else {
|
| 4659 | nextResult = { value: await next() };
|
| 4660 | return nextResult.value;
|
| 4661 | }
|
| 4662 | } catch (error) {
|
| 4663 | let response = await errorHandler(error, routeId, nextResult);
|
| 4664 | return response;
|
| 4665 | }
|
| 4666 | }
|
| 4667 | function getDataStrategyMatchLazyPromises(mapRouteProperties2, manifest, request, match, lazyRoutePropertiesToSkip) {
|
| 4668 | let lazyMiddlewarePromise = loadLazyRouteProperty({
|
| 4669 | key: "middleware",
|
| 4670 | route: match.route,
|
| 4671 | manifest,
|
| 4672 | mapRouteProperties: mapRouteProperties2
|
| 4673 | });
|
| 4674 | let lazyRoutePromises = loadLazyRoute(
|
| 4675 | match.route,
|
| 4676 | isMutationMethod(request.method) ? "action" : "loader",
|
| 4677 | manifest,
|
| 4678 | mapRouteProperties2,
|
| 4679 | lazyRoutePropertiesToSkip
|
| 4680 | );
|
| 4681 | return {
|
| 4682 | middleware: lazyMiddlewarePromise,
|
| 4683 | route: lazyRoutePromises.lazyRoutePromise,
|
| 4684 | handler: lazyRoutePromises.lazyHandlerPromise
|
| 4685 | };
|
| 4686 | }
|
| 4687 | function getDataStrategyMatch(mapRouteProperties2, manifest, request, path, unstable_pattern, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, shouldRevalidateArgs = null, callSiteDefaultShouldRevalidate) {
|
| 4688 | let isUsingNewApi = false;
|
| 4689 | let _lazyPromises = getDataStrategyMatchLazyPromises(
|
| 4690 | mapRouteProperties2,
|
| 4691 | manifest,
|
| 4692 | request,
|
| 4693 | match,
|
| 4694 | lazyRoutePropertiesToSkip
|
| 4695 | );
|
| 4696 | return {
|
| 4697 | ...match,
|
| 4698 | _lazyPromises,
|
| 4699 | shouldLoad,
|
| 4700 | shouldRevalidateArgs,
|
| 4701 | shouldCallHandler(defaultShouldRevalidate) {
|
| 4702 | isUsingNewApi = true;
|
| 4703 | if (!shouldRevalidateArgs) {
|
| 4704 | return shouldLoad;
|
| 4705 | }
|
| 4706 | if (typeof callSiteDefaultShouldRevalidate === "boolean") {
|
| 4707 | return shouldRevalidateLoader(match, {
|
| 4708 | ...shouldRevalidateArgs,
|
| 4709 | defaultShouldRevalidate: callSiteDefaultShouldRevalidate
|
| 4710 | });
|
| 4711 | }
|
| 4712 | if (typeof defaultShouldRevalidate === "boolean") {
|
| 4713 | return shouldRevalidateLoader(match, {
|
| 4714 | ...shouldRevalidateArgs,
|
| 4715 | defaultShouldRevalidate
|
| 4716 | });
|
| 4717 | }
|
| 4718 | return shouldRevalidateLoader(match, shouldRevalidateArgs);
|
| 4719 | },
|
| 4720 | resolve(handlerOverride) {
|
| 4721 | let { lazy, loader, middleware } = match.route;
|
| 4722 | let callHandler = isUsingNewApi || shouldLoad || handlerOverride && !isMutationMethod(request.method) && (lazy || loader);
|
| 4723 | let isMiddlewareOnlyRoute = middleware && middleware.length > 0 && !loader && !lazy;
|
| 4724 | if (callHandler && (isMutationMethod(request.method) || !isMiddlewareOnlyRoute)) {
|
| 4725 | return callLoaderOrAction({
|
| 4726 | request,
|
| 4727 | path,
|
| 4728 | unstable_pattern,
|
| 4729 | match,
|
| 4730 | lazyHandlerPromise: _optionalChain([_lazyPromises, 'optionalAccess', _56 => _56.handler]),
|
| 4731 | lazyRoutePromise: _optionalChain([_lazyPromises, 'optionalAccess', _57 => _57.route]),
|
| 4732 | handlerOverride,
|
| 4733 | scopedContext
|
| 4734 | });
|
| 4735 | }
|
| 4736 | return Promise.resolve({ type: "data" , result: void 0 });
|
| 4737 | }
|
| 4738 | };
|
| 4739 | }
|
| 4740 | function getTargetedDataStrategyMatches(mapRouteProperties2, manifest, request, path, matches, targetMatch, lazyRoutePropertiesToSkip, scopedContext, shouldRevalidateArgs = null) {
|
| 4741 | return matches.map((match) => {
|
| 4742 | if (match.route.id !== targetMatch.route.id) {
|
| 4743 | return {
|
| 4744 | ...match,
|
| 4745 | shouldLoad: false,
|
| 4746 | shouldRevalidateArgs,
|
| 4747 | shouldCallHandler: () => false,
|
| 4748 | _lazyPromises: getDataStrategyMatchLazyPromises(
|
| 4749 | mapRouteProperties2,
|
| 4750 | manifest,
|
| 4751 | request,
|
| 4752 | match,
|
| 4753 | lazyRoutePropertiesToSkip
|
| 4754 | ),
|
| 4755 | resolve: () => Promise.resolve({ type: "data", result: void 0 })
|
| 4756 | };
|
| 4757 | }
|
| 4758 | return getDataStrategyMatch(
|
| 4759 | mapRouteProperties2,
|
| 4760 | manifest,
|
| 4761 | request,
|
| 4762 | path,
|
| 4763 | getRoutePattern(matches),
|
| 4764 | match,
|
| 4765 | lazyRoutePropertiesToSkip,
|
| 4766 | scopedContext,
|
| 4767 | true,
|
| 4768 | shouldRevalidateArgs
|
| 4769 | );
|
| 4770 | });
|
| 4771 | }
|
| 4772 | async function callDataStrategyImpl(dataStrategyImpl, request, path, matches, fetcherKey, scopedContext, isStaticHandler) {
|
| 4773 | if (matches.some((m) => _optionalChain([m, 'access', _58 => _58._lazyPromises, 'optionalAccess', _59 => _59.middleware]))) {
|
| 4774 | await Promise.all(matches.map((m) => _optionalChain([m, 'access', _60 => _60._lazyPromises, 'optionalAccess', _61 => _61.middleware])));
|
| 4775 | }
|
| 4776 | let dataStrategyArgs = {
|
| 4777 | request,
|
| 4778 | unstable_url: createDataFunctionUrl(request, path),
|
| 4779 | unstable_pattern: getRoutePattern(matches),
|
| 4780 | params: matches[0].params,
|
| 4781 | context: scopedContext,
|
| 4782 | matches
|
| 4783 | };
|
| 4784 | let runClientMiddleware = isStaticHandler ? () => {
|
| 4785 | throw new Error(
|
| 4786 | "You cannot call `runClientMiddleware()` from a static handler `dataStrategy`. Middleware is run outside of `dataStrategy` during SSR in order to bubble up the Response. You can enable middleware via the `respond` API in `query`/`queryRoute`"
|
| 4787 | );
|
| 4788 | } : (cb) => {
|
| 4789 | let typedDataStrategyArgs = dataStrategyArgs;
|
| 4790 | return runClientMiddlewarePipeline(typedDataStrategyArgs, () => {
|
| 4791 | return cb({
|
| 4792 | ...typedDataStrategyArgs,
|
| 4793 | fetcherKey,
|
| 4794 | runClientMiddleware: () => {
|
| 4795 | throw new Error(
|
| 4796 | "Cannot call `runClientMiddleware()` from within an `runClientMiddleware` handler"
|
| 4797 | );
|
| 4798 | }
|
| 4799 | });
|
| 4800 | });
|
| 4801 | };
|
| 4802 | let results = await dataStrategyImpl({
|
| 4803 | ...dataStrategyArgs,
|
| 4804 | fetcherKey,
|
| 4805 | runClientMiddleware
|
| 4806 | });
|
| 4807 | try {
|
| 4808 | await Promise.all(
|
| 4809 | matches.flatMap((m) => [
|
| 4810 | _optionalChain([m, 'access', _62 => _62._lazyPromises, 'optionalAccess', _63 => _63.handler]),
|
| 4811 | _optionalChain([m, 'access', _64 => _64._lazyPromises, 'optionalAccess', _65 => _65.route])
|
| 4812 | ])
|
| 4813 | );
|
| 4814 | } catch (e) {
|
| 4815 | }
|
| 4816 | return results;
|
| 4817 | }
|
| 4818 | async function callLoaderOrAction({
|
| 4819 | request,
|
| 4820 | path,
|
| 4821 | unstable_pattern,
|
| 4822 | match,
|
| 4823 | lazyHandlerPromise,
|
| 4824 | lazyRoutePromise,
|
| 4825 | handlerOverride,
|
| 4826 | scopedContext
|
| 4827 | }) {
|
| 4828 | let result;
|
| 4829 | let onReject;
|
| 4830 | let isAction = isMutationMethod(request.method);
|
| 4831 | let type = isAction ? "action" : "loader";
|
| 4832 | let runHandler = (handler) => {
|
| 4833 | let reject;
|
| 4834 | let abortPromise = new Promise((_, r) => reject = r);
|
| 4835 | onReject = () => reject();
|
| 4836 | request.signal.addEventListener("abort", onReject);
|
| 4837 | let actualHandler = (ctx) => {
|
| 4838 | if (typeof handler !== "function") {
|
| 4839 | return Promise.reject(
|
| 4840 | new Error(
|
| 4841 | `You cannot call the handler for a route which defines a boolean "${type}" [routeId: ${match.route.id}]`
|
| 4842 | )
|
| 4843 | );
|
| 4844 | }
|
| 4845 | return handler(
|
| 4846 | {
|
| 4847 | request,
|
| 4848 | unstable_url: createDataFunctionUrl(request, path),
|
| 4849 | unstable_pattern,
|
| 4850 | params: match.params,
|
| 4851 | context: scopedContext
|
| 4852 | },
|
| 4853 | ...ctx !== void 0 ? [ctx] : []
|
| 4854 | );
|
| 4855 | };
|
| 4856 | let handlerPromise = (async () => {
|
| 4857 | try {
|
| 4858 | let val = await (handlerOverride ? handlerOverride((ctx) => actualHandler(ctx)) : actualHandler());
|
| 4859 | return { type: "data", result: val };
|
| 4860 | } catch (e) {
|
| 4861 | return { type: "error", result: e };
|
| 4862 | }
|
| 4863 | })();
|
| 4864 | return Promise.race([handlerPromise, abortPromise]);
|
| 4865 | };
|
| 4866 | try {
|
| 4867 | let handler = isAction ? match.route.action : match.route.loader;
|
| 4868 | if (lazyHandlerPromise || lazyRoutePromise) {
|
| 4869 | if (handler) {
|
| 4870 | let handlerError;
|
| 4871 | let [value] = await Promise.all([
|
| 4872 |
|
| 4873 |
|
| 4874 |
|
| 4875 | runHandler(handler).catch((e) => {
|
| 4876 | handlerError = e;
|
| 4877 | }),
|
| 4878 |
|
| 4879 | lazyHandlerPromise,
|
| 4880 | lazyRoutePromise
|
| 4881 | ]);
|
| 4882 | if (handlerError !== void 0) {
|
| 4883 | throw handlerError;
|
| 4884 | }
|
| 4885 | result = value;
|
| 4886 | } else {
|
| 4887 | await lazyHandlerPromise;
|
| 4888 | let handler2 = isAction ? match.route.action : match.route.loader;
|
| 4889 | if (handler2) {
|
| 4890 | [result] = await Promise.all([runHandler(handler2), lazyRoutePromise]);
|
| 4891 | } else if (type === "action") {
|
| 4892 | let url = new URL(request.url);
|
| 4893 | let pathname = url.pathname + url.search;
|
| 4894 | throw getInternalRouterError(405, {
|
| 4895 | method: request.method,
|
| 4896 | pathname,
|
| 4897 | routeId: match.route.id
|
| 4898 | });
|
| 4899 | } else {
|
| 4900 | return { type: "data" , result: void 0 };
|
| 4901 | }
|
| 4902 | }
|
| 4903 | } else if (!handler) {
|
| 4904 | let url = new URL(request.url);
|
| 4905 | let pathname = url.pathname + url.search;
|
| 4906 | throw getInternalRouterError(404, {
|
| 4907 | pathname
|
| 4908 | });
|
| 4909 | } else {
|
| 4910 | result = await runHandler(handler);
|
| 4911 | }
|
| 4912 | } catch (e) {
|
| 4913 | return { type: "error" , result: e };
|
| 4914 | } finally {
|
| 4915 | if (onReject) {
|
| 4916 | request.signal.removeEventListener("abort", onReject);
|
| 4917 | }
|
| 4918 | }
|
| 4919 | return result;
|
| 4920 | }
|
| 4921 | async function parseResponseBody(response) {
|
| 4922 | let contentType = response.headers.get("Content-Type");
|
| 4923 | if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
| 4924 | return response.body == null ? null : response.json();
|
| 4925 | }
|
| 4926 | return response.text();
|
| 4927 | }
|
| 4928 | async function convertDataStrategyResultToDataResult(dataStrategyResult) {
|
| 4929 | let { result, type } = dataStrategyResult;
|
| 4930 | if (isResponse(result)) {
|
| 4931 | let data2;
|
| 4932 | try {
|
| 4933 | data2 = await parseResponseBody(result);
|
| 4934 | } catch (e) {
|
| 4935 | return { type: "error" , error: e };
|
| 4936 | }
|
| 4937 | if (type === "error" ) {
|
| 4938 | return {
|
| 4939 | type: "error" ,
|
| 4940 | error: new ErrorResponseImpl(result.status, result.statusText, data2),
|
| 4941 | statusCode: result.status,
|
| 4942 | headers: result.headers
|
| 4943 | };
|
| 4944 | }
|
| 4945 | return {
|
| 4946 | type: "data" ,
|
| 4947 | data: data2,
|
| 4948 | statusCode: result.status,
|
| 4949 | headers: result.headers
|
| 4950 | };
|
| 4951 | }
|
| 4952 | if (type === "error" ) {
|
| 4953 | if (isDataWithResponseInit(result)) {
|
| 4954 | if (result.data instanceof Error) {
|
| 4955 | return {
|
| 4956 | type: "error" ,
|
| 4957 | error: result.data,
|
| 4958 | statusCode: _optionalChain([result, 'access', _66 => _66.init, 'optionalAccess', _67 => _67.status]),
|
| 4959 | headers: _optionalChain([result, 'access', _68 => _68.init, 'optionalAccess', _69 => _69.headers]) ? new Headers(result.init.headers) : void 0
|
| 4960 | };
|
| 4961 | }
|
| 4962 | return {
|
| 4963 | type: "error" ,
|
| 4964 | error: dataWithResponseInitToErrorResponse(result),
|
| 4965 | statusCode: isRouteErrorResponse(result) ? result.status : void 0,
|
| 4966 | headers: _optionalChain([result, 'access', _70 => _70.init, 'optionalAccess', _71 => _71.headers]) ? new Headers(result.init.headers) : void 0
|
| 4967 | };
|
| 4968 | }
|
| 4969 | return {
|
| 4970 | type: "error" ,
|
| 4971 | error: result,
|
| 4972 | statusCode: isRouteErrorResponse(result) ? result.status : void 0
|
| 4973 | };
|
| 4974 | }
|
| 4975 | if (isDataWithResponseInit(result)) {
|
| 4976 | return {
|
| 4977 | type: "data" ,
|
| 4978 | data: result.data,
|
| 4979 | statusCode: _optionalChain([result, 'access', _72 => _72.init, 'optionalAccess', _73 => _73.status]),
|
| 4980 | headers: _optionalChain([result, 'access', _74 => _74.init, 'optionalAccess', _75 => _75.headers]) ? new Headers(result.init.headers) : void 0
|
| 4981 | };
|
| 4982 | }
|
| 4983 | return { type: "data" , data: result };
|
| 4984 | }
|
| 4985 | function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
|
| 4986 | let location = response.headers.get("Location");
|
| 4987 | invariant(
|
| 4988 | location,
|
| 4989 | "Redirects returned/thrown from loaders/actions must have a Location header"
|
| 4990 | );
|
| 4991 | if (!isAbsoluteUrl(location)) {
|
| 4992 | let trimmedMatches = matches.slice(
|
| 4993 | 0,
|
| 4994 | matches.findIndex((m) => m.route.id === routeId) + 1
|
| 4995 | );
|
| 4996 | location = normalizeTo(
|
| 4997 | new URL(request.url),
|
| 4998 | trimmedMatches,
|
| 4999 | basename,
|
| 5000 | location
|
| 5001 | );
|
| 5002 | response.headers.set("Location", location);
|
| 5003 | }
|
| 5004 | return response;
|
| 5005 | }
|
| 5006 | var invalidProtocols = [
|
| 5007 | "about:",
|
| 5008 | "blob:",
|
| 5009 | "chrome:",
|
| 5010 | "chrome-untrusted:",
|
| 5011 | "content:",
|
| 5012 | "data:",
|
| 5013 | "devtools:",
|
| 5014 | "file:",
|
| 5015 | "filesystem:",
|
| 5016 |
|
| 5017 | "javascript:"
|
| 5018 | ];
|
| 5019 | function normalizeRedirectLocation(location, currentUrl, basename, historyInstance) {
|
| 5020 | if (isAbsoluteUrl(location)) {
|
| 5021 | let normalizedLocation = location;
|
| 5022 | let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
|
| 5023 | if (invalidProtocols.includes(url.protocol)) {
|
| 5024 | throw new Error("Invalid redirect location");
|
| 5025 | }
|
| 5026 | let isSameBasename = stripBasename(url.pathname, basename) != null;
|
| 5027 | if (url.origin === currentUrl.origin && isSameBasename) {
|
| 5028 | return removeDoubleSlashes(url.pathname) + url.search + url.hash;
|
| 5029 | }
|
| 5030 | }
|
| 5031 | try {
|
| 5032 | let url = historyInstance.createURL(location);
|
| 5033 | if (invalidProtocols.includes(url.protocol)) {
|
| 5034 | throw new Error("Invalid redirect location");
|
| 5035 | }
|
| 5036 | } catch (e) {
|
| 5037 | }
|
| 5038 | return location;
|
| 5039 | }
|
| 5040 | function createClientSideRequest(history, location, signal, submission) {
|
| 5041 | let url = history.createURL(stripHashFromPath(location)).toString();
|
| 5042 | let init = { signal };
|
| 5043 | if (submission && isMutationMethod(submission.formMethod)) {
|
| 5044 | let { formMethod, formEncType } = submission;
|
| 5045 | init.method = formMethod.toUpperCase();
|
| 5046 | if (formEncType === "application/json") {
|
| 5047 | init.headers = new Headers({ "Content-Type": formEncType });
|
| 5048 | init.body = JSON.stringify(submission.json);
|
| 5049 | } else if (formEncType === "text/plain") {
|
| 5050 | init.body = submission.text;
|
| 5051 | } else if (formEncType === "application/x-www-form-urlencoded" && submission.formData) {
|
| 5052 | init.body = convertFormDataToSearchParams(submission.formData);
|
| 5053 | } else {
|
| 5054 | init.body = submission.formData;
|
| 5055 | }
|
| 5056 | }
|
| 5057 | return new Request(url, init);
|
| 5058 | }
|
| 5059 | function createDataFunctionUrl(request, path) {
|
| 5060 | let url = new URL(request.url);
|
| 5061 | let parsed = typeof path === "string" ? parsePath(path) : path;
|
| 5062 | url.pathname = parsed.pathname || "/";
|
| 5063 | if (parsed.search) {
|
| 5064 | let searchParams = new URLSearchParams(parsed.search);
|
| 5065 | let indexValues = searchParams.getAll("index");
|
| 5066 | searchParams.delete("index");
|
| 5067 | for (let value of indexValues.filter(Boolean)) {
|
| 5068 | searchParams.append("index", value);
|
| 5069 | }
|
| 5070 | url.search = searchParams.size ? `?${searchParams.toString()}` : "";
|
| 5071 | } else {
|
| 5072 | url.search = "";
|
| 5073 | }
|
| 5074 | url.hash = parsed.hash || "";
|
| 5075 | return url;
|
| 5076 | }
|
| 5077 | function convertFormDataToSearchParams(formData) {
|
| 5078 | let searchParams = new URLSearchParams();
|
| 5079 | for (let [key, value] of formData.entries()) {
|
| 5080 | searchParams.append(key, typeof value === "string" ? value : value.name);
|
| 5081 | }
|
| 5082 | return searchParams;
|
| 5083 | }
|
| 5084 | function convertSearchParamsToFormData(searchParams) {
|
| 5085 | let formData = new FormData();
|
| 5086 | for (let [key, value] of searchParams.entries()) {
|
| 5087 | formData.append(key, value);
|
| 5088 | }
|
| 5089 | return formData;
|
| 5090 | }
|
| 5091 | function processRouteLoaderData(matches, results, pendingActionResult, isStaticHandler = false, skipLoaderErrorBubbling = false) {
|
| 5092 | let loaderData = {};
|
| 5093 | let errors = null;
|
| 5094 | let statusCode;
|
| 5095 | let foundError = false;
|
| 5096 | let loaderHeaders = {};
|
| 5097 | let pendingError = pendingActionResult && isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : void 0;
|
| 5098 | matches.forEach((match) => {
|
| 5099 | if (!(match.route.id in results)) {
|
| 5100 | return;
|
| 5101 | }
|
| 5102 | let id = match.route.id;
|
| 5103 | let result = results[id];
|
| 5104 | invariant(
|
| 5105 | !isRedirectResult(result),
|
| 5106 | "Cannot handle redirect results in processLoaderData"
|
| 5107 | );
|
| 5108 | if (isErrorResult(result)) {
|
| 5109 | let error = result.error;
|
| 5110 | if (pendingError !== void 0) {
|
| 5111 | error = pendingError;
|
| 5112 | pendingError = void 0;
|
| 5113 | }
|
| 5114 | errors = errors || {};
|
| 5115 | if (skipLoaderErrorBubbling) {
|
| 5116 | errors[id] = error;
|
| 5117 | } else {
|
| 5118 | let boundaryMatch = findNearestBoundary(matches, id);
|
| 5119 | if (errors[boundaryMatch.route.id] == null) {
|
| 5120 | errors[boundaryMatch.route.id] = error;
|
| 5121 | }
|
| 5122 | }
|
| 5123 | if (!isStaticHandler) {
|
| 5124 | loaderData[id] = ResetLoaderDataSymbol;
|
| 5125 | }
|
| 5126 | if (!foundError) {
|
| 5127 | foundError = true;
|
| 5128 | statusCode = isRouteErrorResponse(result.error) ? result.error.status : 500;
|
| 5129 | }
|
| 5130 | if (result.headers) {
|
| 5131 | loaderHeaders[id] = result.headers;
|
| 5132 | }
|
| 5133 | } else {
|
| 5134 | loaderData[id] = result.data;
|
| 5135 | if (result.statusCode && result.statusCode !== 200 && !foundError) {
|
| 5136 | statusCode = result.statusCode;
|
| 5137 | }
|
| 5138 | if (result.headers) {
|
| 5139 | loaderHeaders[id] = result.headers;
|
| 5140 | }
|
| 5141 | }
|
| 5142 | });
|
| 5143 | if (pendingError !== void 0 && pendingActionResult) {
|
| 5144 | errors = { [pendingActionResult[0]]: pendingError };
|
| 5145 | if (pendingActionResult[2]) {
|
| 5146 | loaderData[pendingActionResult[2]] = void 0;
|
| 5147 | }
|
| 5148 | }
|
| 5149 | return {
|
| 5150 | loaderData,
|
| 5151 | errors,
|
| 5152 | statusCode: statusCode || 200,
|
| 5153 | loaderHeaders
|
| 5154 | };
|
| 5155 | }
|
| 5156 | function processLoaderData(state, matches, results, pendingActionResult, revalidatingFetchers, fetcherResults) {
|
| 5157 | let { loaderData, errors } = processRouteLoaderData(
|
| 5158 | matches,
|
| 5159 | results,
|
| 5160 | pendingActionResult
|
| 5161 | );
|
| 5162 | revalidatingFetchers.filter((f) => !f.matches || f.matches.some((m) => m.shouldLoad)).forEach((rf) => {
|
| 5163 | let { key, match, controller } = rf;
|
| 5164 | if (controller && controller.signal.aborted) {
|
| 5165 | return;
|
| 5166 | }
|
| 5167 | let result = fetcherResults[key];
|
| 5168 | invariant(result, "Did not find corresponding fetcher result");
|
| 5169 | if (isErrorResult(result)) {
|
| 5170 | let boundaryMatch = findNearestBoundary(state.matches, _optionalChain([match, 'optionalAccess', _76 => _76.route, 'access', _77 => _77.id]));
|
| 5171 | if (!(errors && errors[boundaryMatch.route.id])) {
|
| 5172 | errors = {
|
| 5173 | ...errors,
|
| 5174 | [boundaryMatch.route.id]: result.error
|
| 5175 | };
|
| 5176 | }
|
| 5177 | state.fetchers.delete(key);
|
| 5178 | } else if (isRedirectResult(result)) {
|
| 5179 | invariant(false, "Unhandled fetcher revalidation redirect");
|
| 5180 | } else {
|
| 5181 | let doneFetcher = getDoneFetcher(result.data);
|
| 5182 | state.fetchers.set(key, doneFetcher);
|
| 5183 | }
|
| 5184 | });
|
| 5185 | return { loaderData, errors };
|
| 5186 | }
|
| 5187 | function mergeLoaderData(loaderData, newLoaderData, matches, errors) {
|
| 5188 | let mergedLoaderData = Object.entries(newLoaderData).filter(([, v]) => v !== ResetLoaderDataSymbol).reduce((merged, [k, v]) => {
|
| 5189 | merged[k] = v;
|
| 5190 | return merged;
|
| 5191 | }, {});
|
| 5192 | for (let match of matches) {
|
| 5193 | let id = match.route.id;
|
| 5194 | if (!newLoaderData.hasOwnProperty(id) && loaderData.hasOwnProperty(id) && match.route.loader) {
|
| 5195 | mergedLoaderData[id] = loaderData[id];
|
| 5196 | }
|
| 5197 | if (errors && errors.hasOwnProperty(id)) {
|
| 5198 | break;
|
| 5199 | }
|
| 5200 | }
|
| 5201 | return mergedLoaderData;
|
| 5202 | }
|
| 5203 | function getActionDataForCommit(pendingActionResult) {
|
| 5204 | if (!pendingActionResult) {
|
| 5205 | return {};
|
| 5206 | }
|
| 5207 | return isErrorResult(pendingActionResult[1]) ? {
|
| 5208 |
|
| 5209 | actionData: {}
|
| 5210 | } : {
|
| 5211 | actionData: {
|
| 5212 | [pendingActionResult[0]]: pendingActionResult[1].data
|
| 5213 | }
|
| 5214 | };
|
| 5215 | }
|
| 5216 | function findNearestBoundary(matches, routeId) {
|
| 5217 | let eligibleMatches = routeId ? matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1) : [...matches];
|
| 5218 | return eligibleMatches.reverse().find((m) => m.route.hasErrorBoundary === true) || matches[0];
|
| 5219 | }
|
| 5220 | function getShortCircuitMatches(routes) {
|
| 5221 | let route = routes.length === 1 ? routes[0] : routes.find((r) => r.index || !r.path || r.path === "/") || {
|
| 5222 | id: `__shim-error-route__`
|
| 5223 | };
|
| 5224 | return {
|
| 5225 | matches: [
|
| 5226 | {
|
| 5227 | params: {},
|
| 5228 | pathname: "",
|
| 5229 | pathnameBase: "",
|
| 5230 | route
|
| 5231 | }
|
| 5232 | ],
|
| 5233 | route
|
| 5234 | };
|
| 5235 | }
|
| 5236 | function getInternalRouterError(status, {
|
| 5237 | pathname,
|
| 5238 | routeId,
|
| 5239 | method,
|
| 5240 | type,
|
| 5241 | message
|
| 5242 | } = {}) {
|
| 5243 | let statusText = "Unknown Server Error";
|
| 5244 | let errorMessage = "Unknown @remix-run/router error";
|
| 5245 | if (status === 400) {
|
| 5246 | statusText = "Bad Request";
|
| 5247 | if (method && pathname && routeId) {
|
| 5248 | 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.`;
|
| 5249 | } else if (type === "invalid-body") {
|
| 5250 | errorMessage = "Unable to encode submission body";
|
| 5251 | }
|
| 5252 | } else if (status === 403) {
|
| 5253 | statusText = "Forbidden";
|
| 5254 | errorMessage = `Route "${routeId}" does not match URL "${pathname}"`;
|
| 5255 | } else if (status === 404) {
|
| 5256 | statusText = "Not Found";
|
| 5257 | errorMessage = `No route matches URL "${pathname}"`;
|
| 5258 | } else if (status === 405) {
|
| 5259 | statusText = "Method Not Allowed";
|
| 5260 | if (method && pathname && routeId) {
|
| 5261 | 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.`;
|
| 5262 | } else if (method) {
|
| 5263 | errorMessage = `Invalid request method "${method.toUpperCase()}"`;
|
| 5264 | }
|
| 5265 | }
|
| 5266 | return new ErrorResponseImpl(
|
| 5267 | status || 500,
|
| 5268 | statusText,
|
| 5269 | new Error(errorMessage),
|
| 5270 | true
|
| 5271 | );
|
| 5272 | }
|
| 5273 | function findRedirect(results) {
|
| 5274 | let entries = Object.entries(results);
|
| 5275 | for (let i = entries.length - 1; i >= 0; i--) {
|
| 5276 | let [key, result] = entries[i];
|
| 5277 | if (isRedirectResult(result)) {
|
| 5278 | return { key, result };
|
| 5279 | }
|
| 5280 | }
|
| 5281 | }
|
| 5282 | function stripHashFromPath(path) {
|
| 5283 | let parsedPath = typeof path === "string" ? parsePath(path) : path;
|
| 5284 | return createPath({ ...parsedPath, hash: "" });
|
| 5285 | }
|
| 5286 | function isHashChangeOnly(a, b) {
|
| 5287 | if (a.pathname !== b.pathname || a.search !== b.search) {
|
| 5288 | return false;
|
| 5289 | }
|
| 5290 | if (a.hash === "") {
|
| 5291 | return b.hash !== "";
|
| 5292 | } else if (a.hash === b.hash) {
|
| 5293 | return true;
|
| 5294 | } else if (b.hash !== "") {
|
| 5295 | return true;
|
| 5296 | }
|
| 5297 | return false;
|
| 5298 | }
|
| 5299 | function dataWithResponseInitToResponse(data2) {
|
| 5300 | return Response.json(data2.data, _nullishCoalesce(data2.init, () => ( void 0)));
|
| 5301 | }
|
| 5302 | function dataWithResponseInitToErrorResponse(data2) {
|
| 5303 | return new ErrorResponseImpl(
|
| 5304 | _nullishCoalesce(_optionalChain([data2, 'access', _78 => _78.init, 'optionalAccess', _79 => _79.status]), () => ( 500)),
|
| 5305 | _nullishCoalesce(_optionalChain([data2, 'access', _80 => _80.init, 'optionalAccess', _81 => _81.statusText]), () => ( "Internal Server Error")),
|
| 5306 | data2.data
|
| 5307 | );
|
| 5308 | }
|
| 5309 | function isDataStrategyResults(result) {
|
| 5310 | return result != null && typeof result === "object" && Object.entries(result).every(
|
| 5311 | ([key, value]) => typeof key === "string" && isDataStrategyResult(value)
|
| 5312 | );
|
| 5313 | }
|
| 5314 | function isDataStrategyResult(result) {
|
| 5315 | return result != null && typeof result === "object" && "type" in result && "result" in result && (result.type === "data" || result.type === "error" );
|
| 5316 | }
|
| 5317 | function isRedirectDataStrategyResult(result) {
|
| 5318 | return isResponse(result.result) && redirectStatusCodes.has(result.result.status);
|
| 5319 | }
|
| 5320 | function isErrorResult(result) {
|
| 5321 | return result.type === "error" ;
|
| 5322 | }
|
| 5323 | function isRedirectResult(result) {
|
| 5324 | return (result && result.type) === "redirect" ;
|
| 5325 | }
|
| 5326 | function isDataWithResponseInit(value) {
|
| 5327 | return typeof value === "object" && value != null && "type" in value && "data" in value && "init" in value && value.type === "DataWithResponseInit";
|
| 5328 | }
|
| 5329 | function isResponse(value) {
|
| 5330 | return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
| 5331 | }
|
| 5332 | function isRedirectStatusCode(statusCode) {
|
| 5333 | return redirectStatusCodes.has(statusCode);
|
| 5334 | }
|
| 5335 | function isRedirectResponse(result) {
|
| 5336 | return isResponse(result) && isRedirectStatusCode(result.status) && result.headers.has("Location");
|
| 5337 | }
|
| 5338 | function isValidMethod(method) {
|
| 5339 | return validRequestMethods.has(method.toUpperCase());
|
| 5340 | }
|
| 5341 | function isMutationMethod(method) {
|
| 5342 | return validMutationMethods.has(method.toUpperCase());
|
| 5343 | }
|
| 5344 | function hasNakedIndexQuery(search) {
|
| 5345 | return new URLSearchParams(search).getAll("index").some((v) => v === "");
|
| 5346 | }
|
| 5347 | function getTargetMatch(matches, location) {
|
| 5348 | let search = typeof location === "string" ? parsePath(location).search : location.search;
|
| 5349 | if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
|
| 5350 | return matches[matches.length - 1];
|
| 5351 | }
|
| 5352 | let pathMatches = getPathContributingMatches(matches);
|
| 5353 | return pathMatches[pathMatches.length - 1];
|
| 5354 | }
|
| 5355 | function getSubmissionFromNavigation(navigation) {
|
| 5356 | let { formMethod, formAction, formEncType, text, formData, json } = navigation;
|
| 5357 | if (!formMethod || !formAction || !formEncType) {
|
| 5358 | return;
|
| 5359 | }
|
| 5360 | if (text != null) {
|
| 5361 | return {
|
| 5362 | formMethod,
|
| 5363 | formAction,
|
| 5364 | formEncType,
|
| 5365 | formData: void 0,
|
| 5366 | json: void 0,
|
| 5367 | text
|
| 5368 | };
|
| 5369 | } else if (formData != null) {
|
| 5370 | return {
|
| 5371 | formMethod,
|
| 5372 | formAction,
|
| 5373 | formEncType,
|
| 5374 | formData,
|
| 5375 | json: void 0,
|
| 5376 | text: void 0
|
| 5377 | };
|
| 5378 | } else if (json !== void 0) {
|
| 5379 | return {
|
| 5380 | formMethod,
|
| 5381 | formAction,
|
| 5382 | formEncType,
|
| 5383 | formData: void 0,
|
| 5384 | json,
|
| 5385 | text: void 0
|
| 5386 | };
|
| 5387 | }
|
| 5388 | }
|
| 5389 | function getLoadingNavigation(location, submission) {
|
| 5390 | if (submission) {
|
| 5391 | let navigation = {
|
| 5392 | state: "loading",
|
| 5393 | location,
|
| 5394 | formMethod: submission.formMethod,
|
| 5395 | formAction: submission.formAction,
|
| 5396 | formEncType: submission.formEncType,
|
| 5397 | formData: submission.formData,
|
| 5398 | json: submission.json,
|
| 5399 | text: submission.text
|
| 5400 | };
|
| 5401 | return navigation;
|
| 5402 | } else {
|
| 5403 | let navigation = {
|
| 5404 | state: "loading",
|
| 5405 | location,
|
| 5406 | formMethod: void 0,
|
| 5407 | formAction: void 0,
|
| 5408 | formEncType: void 0,
|
| 5409 | formData: void 0,
|
| 5410 | json: void 0,
|
| 5411 | text: void 0
|
| 5412 | };
|
| 5413 | return navigation;
|
| 5414 | }
|
| 5415 | }
|
| 5416 | function getSubmittingNavigation(location, submission) {
|
| 5417 | let navigation = {
|
| 5418 | state: "submitting",
|
| 5419 | location,
|
| 5420 | formMethod: submission.formMethod,
|
| 5421 | formAction: submission.formAction,
|
| 5422 | formEncType: submission.formEncType,
|
| 5423 | formData: submission.formData,
|
| 5424 | json: submission.json,
|
| 5425 | text: submission.text
|
| 5426 | };
|
| 5427 | return navigation;
|
| 5428 | }
|
| 5429 | function getLoadingFetcher(submission, data2) {
|
| 5430 | if (submission) {
|
| 5431 | let fetcher = {
|
| 5432 | state: "loading",
|
| 5433 | formMethod: submission.formMethod,
|
| 5434 | formAction: submission.formAction,
|
| 5435 | formEncType: submission.formEncType,
|
| 5436 | formData: submission.formData,
|
| 5437 | json: submission.json,
|
| 5438 | text: submission.text,
|
| 5439 | data: data2
|
| 5440 | };
|
| 5441 | return fetcher;
|
| 5442 | } else {
|
| 5443 | let fetcher = {
|
| 5444 | state: "loading",
|
| 5445 | formMethod: void 0,
|
| 5446 | formAction: void 0,
|
| 5447 | formEncType: void 0,
|
| 5448 | formData: void 0,
|
| 5449 | json: void 0,
|
| 5450 | text: void 0,
|
| 5451 | data: data2
|
| 5452 | };
|
| 5453 | return fetcher;
|
| 5454 | }
|
| 5455 | }
|
| 5456 | function getSubmittingFetcher(submission, existingFetcher) {
|
| 5457 | let fetcher = {
|
| 5458 | state: "submitting",
|
| 5459 | formMethod: submission.formMethod,
|
| 5460 | formAction: submission.formAction,
|
| 5461 | formEncType: submission.formEncType,
|
| 5462 | formData: submission.formData,
|
| 5463 | json: submission.json,
|
| 5464 | text: submission.text,
|
| 5465 | data: existingFetcher ? existingFetcher.data : void 0
|
| 5466 | };
|
| 5467 | return fetcher;
|
| 5468 | }
|
| 5469 | function getDoneFetcher(data2) {
|
| 5470 | let fetcher = {
|
| 5471 | state: "idle",
|
| 5472 | formMethod: void 0,
|
| 5473 | formAction: void 0,
|
| 5474 | formEncType: void 0,
|
| 5475 | formData: void 0,
|
| 5476 | json: void 0,
|
| 5477 | text: void 0,
|
| 5478 | data: data2
|
| 5479 | };
|
| 5480 | return fetcher;
|
| 5481 | }
|
| 5482 | function restoreAppliedTransitions(_window, transitions) {
|
| 5483 | try {
|
| 5484 | let sessionPositions = _window.sessionStorage.getItem(
|
| 5485 | TRANSITIONS_STORAGE_KEY
|
| 5486 | );
|
| 5487 | if (sessionPositions) {
|
| 5488 | let json = JSON.parse(sessionPositions);
|
| 5489 | for (let [k, v] of Object.entries(json || {})) {
|
| 5490 | if (v && Array.isArray(v)) {
|
| 5491 | transitions.set(k, new Set(v || []));
|
| 5492 | }
|
| 5493 | }
|
| 5494 | }
|
| 5495 | } catch (e) {
|
| 5496 | }
|
| 5497 | }
|
| 5498 | function persistAppliedTransitions(_window, transitions) {
|
| 5499 | if (transitions.size > 0) {
|
| 5500 | let json = {};
|
| 5501 | for (let [k, v] of transitions) {
|
| 5502 | json[k] = [...v];
|
| 5503 | }
|
| 5504 | try {
|
| 5505 | _window.sessionStorage.setItem(
|
| 5506 | TRANSITIONS_STORAGE_KEY,
|
| 5507 | JSON.stringify(json)
|
| 5508 | );
|
| 5509 | } catch (error) {
|
| 5510 | warning(
|
| 5511 | false,
|
| 5512 | `Failed to save applied view transitions in sessionStorage (${error}).`
|
| 5513 | );
|
| 5514 | }
|
| 5515 | }
|
| 5516 | }
|
| 5517 | function createDeferred() {
|
| 5518 | let resolve;
|
| 5519 | let reject;
|
| 5520 | let promise = new Promise((res, rej) => {
|
| 5521 | resolve = async (val) => {
|
| 5522 | res(val);
|
| 5523 | try {
|
| 5524 | await promise;
|
| 5525 | } catch (e) {
|
| 5526 | }
|
| 5527 | };
|
| 5528 | reject = async (error) => {
|
| 5529 | rej(error);
|
| 5530 | try {
|
| 5531 | await promise;
|
| 5532 | } catch (e) {
|
| 5533 | }
|
| 5534 | };
|
| 5535 | });
|
| 5536 | return {
|
| 5537 | promise,
|
| 5538 |
|
| 5539 | resolve,
|
| 5540 |
|
| 5541 | reject
|
| 5542 | };
|
| 5543 | }
|
| 5544 |
|
| 5545 |
|
| 5546 | var _react = require('react'); var React = _interopRequireWildcard(_react); var React2 = _interopRequireWildcard(_react); var React3 = _interopRequireWildcard(_react); var React8 = _interopRequireWildcard(_react); var React7 = _interopRequireWildcard(_react); var React6 = _interopRequireWildcard(_react); var React5 = _interopRequireWildcard(_react); var React4 = _interopRequireWildcard(_react); var React9 = _interopRequireWildcard(_react);
|
| 5547 |
|
| 5548 |
|
| 5549 | var HOLE = -1;
|
| 5550 | var NAN = -2;
|
| 5551 | var NEGATIVE_INFINITY = -3;
|
| 5552 | var NEGATIVE_ZERO = -4;
|
| 5553 | var NULL = -5;
|
| 5554 | var POSITIVE_INFINITY = -6;
|
| 5555 | var UNDEFINED = -7;
|
| 5556 | var TYPE_BIGINT = "B";
|
| 5557 | var TYPE_DATE = "D";
|
| 5558 | var TYPE_ERROR = "E";
|
| 5559 | var TYPE_MAP = "M";
|
| 5560 | var TYPE_NULL_OBJECT = "N";
|
| 5561 | var TYPE_PROMISE = "P";
|
| 5562 | var TYPE_REGEXP = "R";
|
| 5563 | var TYPE_SET = "S";
|
| 5564 | var TYPE_SYMBOL = "Y";
|
| 5565 | var TYPE_URL = "U";
|
| 5566 | var TYPE_PREVIOUS_RESOLVED = "Z";
|
| 5567 | var Deferred = class {
|
| 5568 | constructor() {
|
| 5569 | this.promise = new Promise((resolve, reject) => {
|
| 5570 | this.resolve = resolve;
|
| 5571 | this.reject = reject;
|
| 5572 | });
|
| 5573 | }
|
| 5574 | };
|
| 5575 | function createLineSplittingTransform() {
|
| 5576 | const decoder = new TextDecoder();
|
| 5577 | let leftover = "";
|
| 5578 | return new TransformStream({
|
| 5579 | transform(chunk, controller) {
|
| 5580 | const str = decoder.decode(chunk, { stream: true });
|
| 5581 | const parts = (leftover + str).split("\n");
|
| 5582 | leftover = parts.pop() || "";
|
| 5583 | for (const part of parts) {
|
| 5584 | controller.enqueue(part);
|
| 5585 | }
|
| 5586 | },
|
| 5587 | flush(controller) {
|
| 5588 | if (leftover) {
|
| 5589 | controller.enqueue(leftover);
|
| 5590 | }
|
| 5591 | }
|
| 5592 | });
|
| 5593 | }
|
| 5594 |
|
| 5595 |
|
| 5596 | var TIME_LIMIT_MS = 1;
|
| 5597 | var getNow = () => Date.now();
|
| 5598 | var yieldToMain = () => new Promise((resolve) => setTimeout(resolve, 0));
|
| 5599 | async function flatten(input) {
|
| 5600 | const { indices } = this;
|
| 5601 | const existing = indices.get(input);
|
| 5602 | if (existing) return [existing];
|
| 5603 | if (input === void 0) return UNDEFINED;
|
| 5604 | if (input === null) return NULL;
|
| 5605 | if (Number.isNaN(input)) return NAN;
|
| 5606 | if (input === Number.POSITIVE_INFINITY) return POSITIVE_INFINITY;
|
| 5607 | if (input === Number.NEGATIVE_INFINITY) return NEGATIVE_INFINITY;
|
| 5608 | if (input === 0 && 1 / input < 0) return NEGATIVE_ZERO;
|
| 5609 | const index = this.index++;
|
| 5610 | indices.set(input, index);
|
| 5611 | const stack = [[input, index]];
|
| 5612 | await stringify.call(this, stack);
|
| 5613 | return index;
|
| 5614 | }
|
| 5615 | async function stringify(stack) {
|
| 5616 | const { deferred, indices, plugins, postPlugins } = this;
|
| 5617 | const str = this.stringified;
|
| 5618 | let lastYieldTime = getNow();
|
| 5619 | const flattenValue = (value) => {
|
| 5620 | const existing = indices.get(value);
|
| 5621 | if (existing) return [existing];
|
| 5622 | if (value === void 0) return UNDEFINED;
|
| 5623 | if (value === null) return NULL;
|
| 5624 | if (Number.isNaN(value)) return NAN;
|
| 5625 | if (value === Number.POSITIVE_INFINITY) return POSITIVE_INFINITY;
|
| 5626 | if (value === Number.NEGATIVE_INFINITY) return NEGATIVE_INFINITY;
|
| 5627 | if (value === 0 && 1 / value < 0) return NEGATIVE_ZERO;
|
| 5628 | const index = this.index++;
|
| 5629 | indices.set(value, index);
|
| 5630 | stack.push([value, index]);
|
| 5631 | return index;
|
| 5632 | };
|
| 5633 | let i = 0;
|
| 5634 | while (stack.length > 0) {
|
| 5635 | const now = getNow();
|
| 5636 | if (++i % 6e3 === 0 && now - lastYieldTime >= TIME_LIMIT_MS) {
|
| 5637 | await yieldToMain();
|
| 5638 | lastYieldTime = getNow();
|
| 5639 | }
|
| 5640 | const [input, index] = stack.pop();
|
| 5641 | const partsForObj = (obj) => Object.keys(obj).map((k) => `"_${flattenValue(k)}":${flattenValue(obj[k])}`).join(",");
|
| 5642 | let error = null;
|
| 5643 | switch (typeof input) {
|
| 5644 | case "boolean":
|
| 5645 | case "number":
|
| 5646 | case "string":
|
| 5647 | str[index] = JSON.stringify(input);
|
| 5648 | break;
|
| 5649 | case "bigint":
|
| 5650 | str[index] = `["${TYPE_BIGINT}","${input}"]`;
|
| 5651 | break;
|
| 5652 | case "symbol": {
|
| 5653 | const keyFor = Symbol.keyFor(input);
|
| 5654 | if (!keyFor) {
|
| 5655 | error = new Error(
|
| 5656 | "Cannot encode symbol unless created with Symbol.for()"
|
| 5657 | );
|
| 5658 | } else {
|
| 5659 | str[index] = `["${TYPE_SYMBOL}",${JSON.stringify(keyFor)}]`;
|
| 5660 | }
|
| 5661 | break;
|
| 5662 | }
|
| 5663 | case "object": {
|
| 5664 | if (!input) {
|
| 5665 | str[index] = `${NULL}`;
|
| 5666 | break;
|
| 5667 | }
|
| 5668 | const isArray = Array.isArray(input);
|
| 5669 | let pluginHandled = false;
|
| 5670 | if (!isArray && plugins) {
|
| 5671 | for (const plugin of plugins) {
|
| 5672 | const pluginResult = plugin(input);
|
| 5673 | if (Array.isArray(pluginResult)) {
|
| 5674 | pluginHandled = true;
|
| 5675 | const [pluginIdentifier, ...rest] = pluginResult;
|
| 5676 | str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
| 5677 | if (rest.length > 0) {
|
| 5678 | str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
|
| 5679 | }
|
| 5680 | str[index] += "]";
|
| 5681 | break;
|
| 5682 | }
|
| 5683 | }
|
| 5684 | }
|
| 5685 | if (!pluginHandled) {
|
| 5686 | let result = isArray ? "[" : "{";
|
| 5687 | if (isArray) {
|
| 5688 | for (let i2 = 0; i2 < input.length; i2++)
|
| 5689 | result += (i2 ? "," : "") + (i2 in input ? flattenValue(input[i2]) : HOLE);
|
| 5690 | str[index] = `${result}]`;
|
| 5691 | } else if (input instanceof Date) {
|
| 5692 | const dateTime = input.getTime();
|
| 5693 | str[index] = `["${TYPE_DATE}",${Number.isNaN(dateTime) ? JSON.stringify("invalid") : dateTime}]`;
|
| 5694 | } else if (input instanceof URL) {
|
| 5695 | str[index] = `["${TYPE_URL}",${JSON.stringify(input.href)}]`;
|
| 5696 | } else if (input instanceof RegExp) {
|
| 5697 | str[index] = `["${TYPE_REGEXP}",${JSON.stringify(
|
| 5698 | input.source
|
| 5699 | )},${JSON.stringify(input.flags)}]`;
|
| 5700 | } else if (input instanceof Set) {
|
| 5701 | if (input.size > 0) {
|
| 5702 | str[index] = `["${TYPE_SET}",${[...input].map((val) => flattenValue(val)).join(",")}]`;
|
| 5703 | } else {
|
| 5704 | str[index] = `["${TYPE_SET}"]`;
|
| 5705 | }
|
| 5706 | } else if (input instanceof Map) {
|
| 5707 | if (input.size > 0) {
|
| 5708 | str[index] = `["${TYPE_MAP}",${[...input].flatMap(([k, v]) => [flattenValue(k), flattenValue(v)]).join(",")}]`;
|
| 5709 | } else {
|
| 5710 | str[index] = `["${TYPE_MAP}"]`;
|
| 5711 | }
|
| 5712 | } else if (input instanceof Promise) {
|
| 5713 | str[index] = `["${TYPE_PROMISE}",${index}]`;
|
| 5714 | deferred[index] = input;
|
| 5715 | } else if (input instanceof Error) {
|
| 5716 | str[index] = `["${TYPE_ERROR}",${JSON.stringify(input.message)}`;
|
| 5717 | if (input.name !== "Error") {
|
| 5718 | str[index] += `,${JSON.stringify(input.name)}`;
|
| 5719 | }
|
| 5720 | str[index] += "]";
|
| 5721 | } else if (Object.getPrototypeOf(input) === null) {
|
| 5722 | str[index] = `["${TYPE_NULL_OBJECT}",{${partsForObj(input)}}]`;
|
| 5723 | } else if (isPlainObject2(input)) {
|
| 5724 | str[index] = `{${partsForObj(input)}}`;
|
| 5725 | } else {
|
| 5726 | error = new Error("Cannot encode object with prototype");
|
| 5727 | }
|
| 5728 | }
|
| 5729 | break;
|
| 5730 | }
|
| 5731 | default: {
|
| 5732 | const isArray = Array.isArray(input);
|
| 5733 | let pluginHandled = false;
|
| 5734 | if (!isArray && plugins) {
|
| 5735 | for (const plugin of plugins) {
|
| 5736 | const pluginResult = plugin(input);
|
| 5737 | if (Array.isArray(pluginResult)) {
|
| 5738 | pluginHandled = true;
|
| 5739 | const [pluginIdentifier, ...rest] = pluginResult;
|
| 5740 | str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
| 5741 | if (rest.length > 0) {
|
| 5742 | str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
|
| 5743 | }
|
| 5744 | str[index] += "]";
|
| 5745 | break;
|
| 5746 | }
|
| 5747 | }
|
| 5748 | }
|
| 5749 | if (!pluginHandled) {
|
| 5750 | error = new Error("Cannot encode function or unexpected type");
|
| 5751 | }
|
| 5752 | }
|
| 5753 | }
|
| 5754 | if (error) {
|
| 5755 | let pluginHandled = false;
|
| 5756 | if (postPlugins) {
|
| 5757 | for (const plugin of postPlugins) {
|
| 5758 | const pluginResult = plugin(input);
|
| 5759 | if (Array.isArray(pluginResult)) {
|
| 5760 | pluginHandled = true;
|
| 5761 | const [pluginIdentifier, ...rest] = pluginResult;
|
| 5762 | str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
| 5763 | if (rest.length > 0) {
|
| 5764 | str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
|
| 5765 | }
|
| 5766 | str[index] += "]";
|
| 5767 | break;
|
| 5768 | }
|
| 5769 | }
|
| 5770 | }
|
| 5771 | if (!pluginHandled) {
|
| 5772 | throw error;
|
| 5773 | }
|
| 5774 | }
|
| 5775 | }
|
| 5776 | }
|
| 5777 | var objectProtoNames2 = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
| 5778 | function isPlainObject2(thing) {
|
| 5779 | const proto = Object.getPrototypeOf(thing);
|
| 5780 | return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames2;
|
| 5781 | }
|
| 5782 |
|
| 5783 |
|
| 5784 | var globalObj = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
|
| 5785 | function unflatten(parsed) {
|
| 5786 | const { hydrated, values } = this;
|
| 5787 | if (typeof parsed === "number") return hydrate.call(this, parsed);
|
| 5788 | if (!Array.isArray(parsed) || !parsed.length) throw new SyntaxError();
|
| 5789 | const startIndex = values.length;
|
| 5790 | for (const value of parsed) {
|
| 5791 | values.push(value);
|
| 5792 | }
|
| 5793 | hydrated.length = values.length;
|
| 5794 | return hydrate.call(this, startIndex);
|
| 5795 | }
|
| 5796 | function hydrate(index) {
|
| 5797 | const { hydrated, values, deferred, plugins } = this;
|
| 5798 | let result;
|
| 5799 | const stack = [
|
| 5800 | [
|
| 5801 | index,
|
| 5802 | (v) => {
|
| 5803 | result = v;
|
| 5804 | }
|
| 5805 | ]
|
| 5806 | ];
|
| 5807 | let postRun = [];
|
| 5808 | while (stack.length > 0) {
|
| 5809 | const [index2, set] = stack.pop();
|
| 5810 | switch (index2) {
|
| 5811 | case UNDEFINED:
|
| 5812 | set(void 0);
|
| 5813 | continue;
|
| 5814 | case NULL:
|
| 5815 | set(null);
|
| 5816 | continue;
|
| 5817 | case NAN:
|
| 5818 | set(NaN);
|
| 5819 | continue;
|
| 5820 | case POSITIVE_INFINITY:
|
| 5821 | set(Infinity);
|
| 5822 | continue;
|
| 5823 | case NEGATIVE_INFINITY:
|
| 5824 | set(-Infinity);
|
| 5825 | continue;
|
| 5826 | case NEGATIVE_ZERO:
|
| 5827 | set(-0);
|
| 5828 | continue;
|
| 5829 | }
|
| 5830 | if (hydrated[index2]) {
|
| 5831 | set(hydrated[index2]);
|
| 5832 | continue;
|
| 5833 | }
|
| 5834 | const value = values[index2];
|
| 5835 | if (!value || typeof value !== "object") {
|
| 5836 | hydrated[index2] = value;
|
| 5837 | set(value);
|
| 5838 | continue;
|
| 5839 | }
|
| 5840 | if (Array.isArray(value)) {
|
| 5841 | if (typeof value[0] === "string") {
|
| 5842 | const [type, b, c] = value;
|
| 5843 | switch (type) {
|
| 5844 | case TYPE_DATE:
|
| 5845 | set(hydrated[index2] = new Date(b));
|
| 5846 | continue;
|
| 5847 | case TYPE_URL:
|
| 5848 | set(hydrated[index2] = new URL(b));
|
| 5849 | continue;
|
| 5850 | case TYPE_BIGINT:
|
| 5851 | set(hydrated[index2] = BigInt(b));
|
| 5852 | continue;
|
| 5853 | case TYPE_REGEXP:
|
| 5854 | set(hydrated[index2] = new RegExp(b, c));
|
| 5855 | continue;
|
| 5856 | case TYPE_SYMBOL:
|
| 5857 | set(hydrated[index2] = Symbol.for(b));
|
| 5858 | continue;
|
| 5859 | case TYPE_SET:
|
| 5860 | const newSet = /* @__PURE__ */ new Set();
|
| 5861 | hydrated[index2] = newSet;
|
| 5862 | for (let i = value.length - 1; i > 0; i--)
|
| 5863 | stack.push([
|
| 5864 | value[i],
|
| 5865 | (v) => {
|
| 5866 | newSet.add(v);
|
| 5867 | }
|
| 5868 | ]);
|
| 5869 | set(newSet);
|
| 5870 | continue;
|
| 5871 | case TYPE_MAP:
|
| 5872 | const map = /* @__PURE__ */ new Map();
|
| 5873 | hydrated[index2] = map;
|
| 5874 | for (let i = value.length - 2; i > 0; i -= 2) {
|
| 5875 | const r = [];
|
| 5876 | stack.push([
|
| 5877 | value[i + 1],
|
| 5878 | (v) => {
|
| 5879 | r[1] = v;
|
| 5880 | }
|
| 5881 | ]);
|
| 5882 | stack.push([
|
| 5883 | value[i],
|
| 5884 | (k) => {
|
| 5885 | r[0] = k;
|
| 5886 | }
|
| 5887 | ]);
|
| 5888 | postRun.push(() => {
|
| 5889 | map.set(r[0], r[1]);
|
| 5890 | });
|
| 5891 | }
|
| 5892 | set(map);
|
| 5893 | continue;
|
| 5894 | case TYPE_NULL_OBJECT:
|
| 5895 | const obj = /* @__PURE__ */ Object.create(null);
|
| 5896 | hydrated[index2] = obj;
|
| 5897 | for (const key of Object.keys(b).reverse()) {
|
| 5898 | const r = [];
|
| 5899 | stack.push([
|
| 5900 | b[key],
|
| 5901 | (v) => {
|
| 5902 | r[1] = v;
|
| 5903 | }
|
| 5904 | ]);
|
| 5905 | stack.push([
|
| 5906 | Number(key.slice(1)),
|
| 5907 | (k) => {
|
| 5908 | r[0] = k;
|
| 5909 | }
|
| 5910 | ]);
|
| 5911 | postRun.push(() => {
|
| 5912 | obj[r[0]] = r[1];
|
| 5913 | });
|
| 5914 | }
|
| 5915 | set(obj);
|
| 5916 | continue;
|
| 5917 | case TYPE_PROMISE:
|
| 5918 | if (hydrated[b]) {
|
| 5919 | set(hydrated[index2] = hydrated[b]);
|
| 5920 | } else {
|
| 5921 | const d = new Deferred();
|
| 5922 | deferred[b] = d;
|
| 5923 | set(hydrated[index2] = d.promise);
|
| 5924 | }
|
| 5925 | continue;
|
| 5926 | case TYPE_ERROR:
|
| 5927 | const [, message, errorType] = value;
|
| 5928 | let error = errorType && globalObj && globalObj[errorType] ? new globalObj[errorType](message) : new Error(message);
|
| 5929 | hydrated[index2] = error;
|
| 5930 | set(error);
|
| 5931 | continue;
|
| 5932 | case TYPE_PREVIOUS_RESOLVED:
|
| 5933 | set(hydrated[index2] = hydrated[b]);
|
| 5934 | continue;
|
| 5935 | default:
|
| 5936 | if (Array.isArray(plugins)) {
|
| 5937 | const r = [];
|
| 5938 | const vals = value.slice(1);
|
| 5939 | for (let i = 0; i < vals.length; i++) {
|
| 5940 | const v = vals[i];
|
| 5941 | stack.push([
|
| 5942 | v,
|
| 5943 | (v2) => {
|
| 5944 | r[i] = v2;
|
| 5945 | }
|
| 5946 | ]);
|
| 5947 | }
|
| 5948 | postRun.push(() => {
|
| 5949 | for (const plugin of plugins) {
|
| 5950 | const result2 = plugin(value[0], ...r);
|
| 5951 | if (result2) {
|
| 5952 | set(hydrated[index2] = result2.value);
|
| 5953 | return;
|
| 5954 | }
|
| 5955 | }
|
| 5956 | throw new SyntaxError();
|
| 5957 | });
|
| 5958 | continue;
|
| 5959 | }
|
| 5960 | throw new SyntaxError();
|
| 5961 | }
|
| 5962 | } else {
|
| 5963 | const array = [];
|
| 5964 | hydrated[index2] = array;
|
| 5965 | for (let i = 0; i < value.length; i++) {
|
| 5966 | const n = value[i];
|
| 5967 | if (n !== HOLE) {
|
| 5968 | stack.push([
|
| 5969 | n,
|
| 5970 | (v) => {
|
| 5971 | array[i] = v;
|
| 5972 | }
|
| 5973 | ]);
|
| 5974 | }
|
| 5975 | }
|
| 5976 | set(array);
|
| 5977 | continue;
|
| 5978 | }
|
| 5979 | } else {
|
| 5980 | const object = {};
|
| 5981 | hydrated[index2] = object;
|
| 5982 | for (const key of Object.keys(value).reverse()) {
|
| 5983 | const r = [];
|
| 5984 | stack.push([
|
| 5985 | value[key],
|
| 5986 | (v) => {
|
| 5987 | r[1] = v;
|
| 5988 | }
|
| 5989 | ]);
|
| 5990 | stack.push([
|
| 5991 | Number(key.slice(1)),
|
| 5992 | (k) => {
|
| 5993 | r[0] = k;
|
| 5994 | }
|
| 5995 | ]);
|
| 5996 | postRun.push(() => {
|
| 5997 | object[r[0]] = r[1];
|
| 5998 | });
|
| 5999 | }
|
| 6000 | set(object);
|
| 6001 | continue;
|
| 6002 | }
|
| 6003 | }
|
| 6004 | while (postRun.length > 0) {
|
| 6005 | postRun.pop()();
|
| 6006 | }
|
| 6007 | return result;
|
| 6008 | }
|
| 6009 |
|
| 6010 |
|
| 6011 | async function decode(readable, options) {
|
| 6012 | const { plugins } = _nullishCoalesce(options, () => ( {}));
|
| 6013 | const done = new Deferred();
|
| 6014 | const reader = readable.pipeThrough(createLineSplittingTransform()).getReader();
|
| 6015 | const decoder = {
|
| 6016 | values: [],
|
| 6017 | hydrated: [],
|
| 6018 | deferred: {},
|
| 6019 | plugins
|
| 6020 | };
|
| 6021 | const decoded = await decodeInitial.call(decoder, reader);
|
| 6022 | let donePromise = done.promise;
|
| 6023 | if (decoded.done) {
|
| 6024 | done.resolve();
|
| 6025 | } else {
|
| 6026 | donePromise = decodeDeferred.call(decoder, reader).then(done.resolve).catch((reason) => {
|
| 6027 | for (const deferred of Object.values(decoder.deferred)) {
|
| 6028 | deferred.reject(reason);
|
| 6029 | }
|
| 6030 | done.reject(reason);
|
| 6031 | });
|
| 6032 | }
|
| 6033 | return {
|
| 6034 | done: donePromise.then(() => reader.closed),
|
| 6035 | value: decoded.value
|
| 6036 | };
|
| 6037 | }
|
| 6038 | async function decodeInitial(reader) {
|
| 6039 | const read = await reader.read();
|
| 6040 | if (!read.value) {
|
| 6041 | throw new SyntaxError();
|
| 6042 | }
|
| 6043 | let line;
|
| 6044 | try {
|
| 6045 | line = JSON.parse(read.value);
|
| 6046 | } catch (reason) {
|
| 6047 | throw new SyntaxError();
|
| 6048 | }
|
| 6049 | return {
|
| 6050 | done: read.done,
|
| 6051 | value: unflatten.call(this, line)
|
| 6052 | };
|
| 6053 | }
|
| 6054 | async function decodeDeferred(reader) {
|
| 6055 | let read = await reader.read();
|
| 6056 | while (!read.done) {
|
| 6057 | if (!read.value) continue;
|
| 6058 | const line = read.value;
|
| 6059 | switch (line[0]) {
|
| 6060 | case TYPE_PROMISE: {
|
| 6061 | const colonIndex = line.indexOf(":");
|
| 6062 | const deferredId = Number(line.slice(1, colonIndex));
|
| 6063 | const deferred = this.deferred[deferredId];
|
| 6064 | if (!deferred) {
|
| 6065 | throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
| 6066 | }
|
| 6067 | const lineData = line.slice(colonIndex + 1);
|
| 6068 | let jsonLine;
|
| 6069 | try {
|
| 6070 | jsonLine = JSON.parse(lineData);
|
| 6071 | } catch (reason) {
|
| 6072 | throw new SyntaxError();
|
| 6073 | }
|
| 6074 | const value = unflatten.call(this, jsonLine);
|
| 6075 | deferred.resolve(value);
|
| 6076 | break;
|
| 6077 | }
|
| 6078 | case TYPE_ERROR: {
|
| 6079 | const colonIndex = line.indexOf(":");
|
| 6080 | const deferredId = Number(line.slice(1, colonIndex));
|
| 6081 | const deferred = this.deferred[deferredId];
|
| 6082 | if (!deferred) {
|
| 6083 | throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
| 6084 | }
|
| 6085 | const lineData = line.slice(colonIndex + 1);
|
| 6086 | let jsonLine;
|
| 6087 | try {
|
| 6088 | jsonLine = JSON.parse(lineData);
|
| 6089 | } catch (reason) {
|
| 6090 | throw new SyntaxError();
|
| 6091 | }
|
| 6092 | const value = unflatten.call(this, jsonLine);
|
| 6093 | deferred.reject(value);
|
| 6094 | break;
|
| 6095 | }
|
| 6096 | default:
|
| 6097 | throw new SyntaxError();
|
| 6098 | }
|
| 6099 | read = await reader.read();
|
| 6100 | }
|
| 6101 | }
|
| 6102 | function encode(input, options) {
|
| 6103 | const { onComplete, plugins, postPlugins, signal } = _nullishCoalesce(options, () => ( {}));
|
| 6104 | const encoder = {
|
| 6105 | deferred: {},
|
| 6106 | index: 0,
|
| 6107 | indices: new Map(),
|
| 6108 | stringified: [],
|
| 6109 | plugins,
|
| 6110 | postPlugins,
|
| 6111 | signal
|
| 6112 | };
|
| 6113 | const textEncoder = new TextEncoder();
|
| 6114 | let lastSentIndex = 0;
|
| 6115 | const readable = new ReadableStream({
|
| 6116 | async start(controller) {
|
| 6117 | const id = await flatten.call(encoder, input);
|
| 6118 | if (Array.isArray(id)) {
|
| 6119 | throw new Error("This should never happen");
|
| 6120 | }
|
| 6121 | if (id < 0) {
|
| 6122 | controller.enqueue(textEncoder.encode(`${id}
|
| 6123 | `));
|
| 6124 | } else {
|
| 6125 | controller.enqueue(
|
| 6126 | textEncoder.encode(`[${encoder.stringified.join(",")}]
|
| 6127 | `)
|
| 6128 | );
|
| 6129 | lastSentIndex = encoder.stringified.length - 1;
|
| 6130 | }
|
| 6131 | const seenPromises = new WeakSet();
|
| 6132 | let processingChain = Promise.resolve();
|
| 6133 | if (Object.keys(encoder.deferred).length) {
|
| 6134 | let raceDone;
|
| 6135 | const racePromise = new Promise((resolve, reject) => {
|
| 6136 | raceDone = resolve;
|
| 6137 | if (signal) {
|
| 6138 | const rejectPromise = () => reject(signal.reason || new Error("Signal was aborted."));
|
| 6139 | if (signal.aborted) {
|
| 6140 | rejectPromise();
|
| 6141 | } else {
|
| 6142 | signal.addEventListener("abort", (event) => {
|
| 6143 | rejectPromise();
|
| 6144 | });
|
| 6145 | }
|
| 6146 | }
|
| 6147 | });
|
| 6148 | while (Object.keys(encoder.deferred).length > 0) {
|
| 6149 | for (const [deferredId, deferred] of Object.entries(
|
| 6150 | encoder.deferred
|
| 6151 | )) {
|
| 6152 | if (seenPromises.has(deferred)) continue;
|
| 6153 | seenPromises.add(
|
| 6154 |
|
| 6155 | encoder.deferred[Number(deferredId)] = Promise.race([
|
| 6156 | racePromise,
|
| 6157 | deferred
|
| 6158 | ]).then(
|
| 6159 | (resolved) => {
|
| 6160 | processingChain = processingChain.then(async () => {
|
| 6161 | const id2 = await flatten.call(encoder, resolved);
|
| 6162 | if (Array.isArray(id2)) {
|
| 6163 | controller.enqueue(
|
| 6164 | textEncoder.encode(
|
| 6165 | `${TYPE_PROMISE}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
|
| 6166 | `
|
| 6167 | )
|
| 6168 | );
|
| 6169 | encoder.index++;
|
| 6170 | lastSentIndex++;
|
| 6171 | } else if (id2 < 0) {
|
| 6172 | controller.enqueue(
|
| 6173 | textEncoder.encode(
|
| 6174 | `${TYPE_PROMISE}${deferredId}:${id2}
|
| 6175 | `
|
| 6176 | )
|
| 6177 | );
|
| 6178 | } else {
|
| 6179 | const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
| 6180 | controller.enqueue(
|
| 6181 | textEncoder.encode(
|
| 6182 | `${TYPE_PROMISE}${deferredId}:[${values}]
|
| 6183 | `
|
| 6184 | )
|
| 6185 | );
|
| 6186 | lastSentIndex = encoder.stringified.length - 1;
|
| 6187 | }
|
| 6188 | });
|
| 6189 | return processingChain;
|
| 6190 | },
|
| 6191 | (reason) => {
|
| 6192 | processingChain = processingChain.then(async () => {
|
| 6193 | if (!reason || typeof reason !== "object" || !(reason instanceof Error)) {
|
| 6194 | reason = new Error("An unknown error occurred");
|
| 6195 | }
|
| 6196 | const id2 = await flatten.call(encoder, reason);
|
| 6197 | if (Array.isArray(id2)) {
|
| 6198 | controller.enqueue(
|
| 6199 | textEncoder.encode(
|
| 6200 | `${TYPE_ERROR}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
|
| 6201 | `
|
| 6202 | )
|
| 6203 | );
|
| 6204 | encoder.index++;
|
| 6205 | lastSentIndex++;
|
| 6206 | } else if (id2 < 0) {
|
| 6207 | controller.enqueue(
|
| 6208 | textEncoder.encode(
|
| 6209 | `${TYPE_ERROR}${deferredId}:${id2}
|
| 6210 | `
|
| 6211 | )
|
| 6212 | );
|
| 6213 | } else {
|
| 6214 | const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
| 6215 | controller.enqueue(
|
| 6216 | textEncoder.encode(
|
| 6217 | `${TYPE_ERROR}${deferredId}:[${values}]
|
| 6218 | `
|
| 6219 | )
|
| 6220 | );
|
| 6221 | lastSentIndex = encoder.stringified.length - 1;
|
| 6222 | }
|
| 6223 | });
|
| 6224 | return processingChain;
|
| 6225 | }
|
| 6226 | ).finally(() => {
|
| 6227 | delete encoder.deferred[Number(deferredId)];
|
| 6228 | })
|
| 6229 | );
|
| 6230 | }
|
| 6231 | await Promise.race(Object.values(encoder.deferred));
|
| 6232 | }
|
| 6233 | raceDone();
|
| 6234 | }
|
| 6235 | await Promise.all(Object.values(encoder.deferred));
|
| 6236 | await processingChain;
|
| 6237 | controller.close();
|
| 6238 | _optionalChain([onComplete, 'optionalCall', _82 => _82()]);
|
| 6239 | }
|
| 6240 | });
|
| 6241 | return readable;
|
| 6242 | }
|
| 6243 |
|
| 6244 |
|
| 6245 | async function createRequestInit(request) {
|
| 6246 | let init = { signal: request.signal };
|
| 6247 | if (request.method !== "GET") {
|
| 6248 | init.method = request.method;
|
| 6249 | let contentType = request.headers.get("Content-Type");
|
| 6250 | if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
| 6251 | init.headers = { "Content-Type": contentType };
|
| 6252 | init.body = JSON.stringify(await request.json());
|
| 6253 | } else if (contentType && /\btext\/plain\b/.test(contentType)) {
|
| 6254 | init.headers = { "Content-Type": contentType };
|
| 6255 | init.body = await request.text();
|
| 6256 | } else if (contentType && /\bapplication\/x-www-form-urlencoded\b/.test(contentType)) {
|
| 6257 | init.body = new URLSearchParams(await request.text());
|
| 6258 | } else {
|
| 6259 | init.body = await request.formData();
|
| 6260 | }
|
| 6261 | }
|
| 6262 | return init;
|
| 6263 | }
|
| 6264 |
|
| 6265 |
|
| 6266 | var ESCAPE_LOOKUP = {
|
| 6267 | "&": "\\u0026",
|
| 6268 | ">": "\\u003e",
|
| 6269 | "<": "\\u003c",
|
| 6270 | "\u2028": "\\u2028",
|
| 6271 | "\u2029": "\\u2029"
|
| 6272 | };
|
| 6273 | var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
| 6274 | function escapeHtml(html) {
|
| 6275 | return html.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
| 6276 | }
|
| 6277 |
|
| 6278 |
|
| 6279 | function invariant2(value, message) {
|
| 6280 | if (value === false || value === null || typeof value === "undefined") {
|
| 6281 | throw new Error(message);
|
| 6282 | }
|
| 6283 | }
|
| 6284 |
|
| 6285 |
|
| 6286 | var SingleFetchRedirectSymbol = Symbol("SingleFetchRedirect");
|
| 6287 | var SingleFetchNoResultError = class extends Error {
|
| 6288 | };
|
| 6289 | var SINGLE_FETCH_REDIRECT_STATUS = 202;
|
| 6290 | var NO_BODY_STATUS_CODES = new Set([100, 101, 204, 205]);
|
| 6291 | function StreamTransfer({
|
| 6292 | context,
|
| 6293 | identifier,
|
| 6294 | reader,
|
| 6295 | textDecoder,
|
| 6296 | nonce
|
| 6297 | }) {
|
| 6298 | if (!context.renderMeta || !context.renderMeta.didRenderScripts) {
|
| 6299 | return null;
|
| 6300 | }
|
| 6301 | if (!context.renderMeta.streamCache) {
|
| 6302 | context.renderMeta.streamCache = {};
|
| 6303 | }
|
| 6304 | let { streamCache } = context.renderMeta;
|
| 6305 | let promise = streamCache[identifier];
|
| 6306 | if (!promise) {
|
| 6307 | promise = streamCache[identifier] = reader.read().then((result) => {
|
| 6308 | streamCache[identifier].result = {
|
| 6309 | done: result.done,
|
| 6310 | value: textDecoder.decode(result.value, { stream: true })
|
| 6311 | };
|
| 6312 | }).catch((e) => {
|
| 6313 | streamCache[identifier].error = e;
|
| 6314 | });
|
| 6315 | }
|
| 6316 | if (promise.error) {
|
| 6317 | throw promise.error;
|
| 6318 | }
|
| 6319 | if (promise.result === void 0) {
|
| 6320 | throw promise;
|
| 6321 | }
|
| 6322 | let { done, value } = promise.result;
|
| 6323 | let scriptTag = value ? React.createElement(
|
| 6324 | "script",
|
| 6325 | {
|
| 6326 | nonce,
|
| 6327 | dangerouslySetInnerHTML: {
|
| 6328 | __html: `window.__reactRouterContext.streamController.enqueue(${escapeHtml(
|
| 6329 | JSON.stringify(value)
|
| 6330 | )});`
|
| 6331 | }
|
| 6332 | }
|
| 6333 | ) : null;
|
| 6334 | if (done) {
|
| 6335 | return React.createElement(React.Fragment, null, scriptTag, React.createElement(
|
| 6336 | "script",
|
| 6337 | {
|
| 6338 | nonce,
|
| 6339 | dangerouslySetInnerHTML: {
|
| 6340 | __html: `window.__reactRouterContext.streamController.close();`
|
| 6341 | }
|
| 6342 | }
|
| 6343 | ));
|
| 6344 | } else {
|
| 6345 | return React.createElement(React.Fragment, null, scriptTag, React.createElement(React.Suspense, null, React.createElement(
|
| 6346 | StreamTransfer,
|
| 6347 | {
|
| 6348 | context,
|
| 6349 | identifier: identifier + 1,
|
| 6350 | reader,
|
| 6351 | textDecoder,
|
| 6352 | nonce
|
| 6353 | }
|
| 6354 | )));
|
| 6355 | }
|
| 6356 | }
|
| 6357 | function getTurboStreamSingleFetchDataStrategy(getRouter, manifest, routeModules, ssr, basename, trailingSlashAware) {
|
| 6358 | let dataStrategy = getSingleFetchDataStrategyImpl(
|
| 6359 | getRouter,
|
| 6360 | (match) => {
|
| 6361 | let manifestRoute = manifest.routes[match.route.id];
|
| 6362 | invariant2(manifestRoute, "Route not found in manifest");
|
| 6363 | let routeModule = routeModules[match.route.id];
|
| 6364 | return {
|
| 6365 | hasLoader: manifestRoute.hasLoader,
|
| 6366 | hasClientLoader: manifestRoute.hasClientLoader,
|
| 6367 | hasShouldRevalidate: Boolean(_optionalChain([routeModule, 'optionalAccess', _83 => _83.shouldRevalidate]))
|
| 6368 | };
|
| 6369 | },
|
| 6370 | fetchAndDecodeViaTurboStream,
|
| 6371 | ssr,
|
| 6372 | basename,
|
| 6373 | trailingSlashAware
|
| 6374 | );
|
| 6375 | return async (args) => args.runClientMiddleware(dataStrategy);
|
| 6376 | }
|
| 6377 | function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode, ssr, basename, trailingSlashAware, shouldAllowOptOut = () => true) {
|
| 6378 | return async (args) => {
|
| 6379 | let { request, matches, fetcherKey } = args;
|
| 6380 | let router = getRouter();
|
| 6381 | if (request.method !== "GET") {
|
| 6382 | return singleFetchActionStrategy(
|
| 6383 | args,
|
| 6384 | fetchAndDecode,
|
| 6385 | basename,
|
| 6386 | trailingSlashAware
|
| 6387 | );
|
| 6388 | }
|
| 6389 | let foundRevalidatingServerLoader = matches.some((m) => {
|
| 6390 | let { hasLoader, hasClientLoader } = getRouteInfo(m);
|
| 6391 | return m.shouldCallHandler() && hasLoader && !hasClientLoader;
|
| 6392 | });
|
| 6393 | if (!ssr && !foundRevalidatingServerLoader) {
|
| 6394 | return nonSsrStrategy(
|
| 6395 | args,
|
| 6396 | getRouteInfo,
|
| 6397 | fetchAndDecode,
|
| 6398 | basename,
|
| 6399 | trailingSlashAware
|
| 6400 | );
|
| 6401 | }
|
| 6402 | if (fetcherKey) {
|
| 6403 | return singleFetchLoaderFetcherStrategy(
|
| 6404 | args,
|
| 6405 | fetchAndDecode,
|
| 6406 | basename,
|
| 6407 | trailingSlashAware
|
| 6408 | );
|
| 6409 | }
|
| 6410 | return singleFetchLoaderNavigationStrategy(
|
| 6411 | args,
|
| 6412 | router,
|
| 6413 | getRouteInfo,
|
| 6414 | fetchAndDecode,
|
| 6415 | ssr,
|
| 6416 | basename,
|
| 6417 | trailingSlashAware,
|
| 6418 | shouldAllowOptOut
|
| 6419 | );
|
| 6420 | };
|
| 6421 | }
|
| 6422 | async function singleFetchActionStrategy(args, fetchAndDecode, basename, trailingSlashAware) {
|
| 6423 | let actionMatch = args.matches.find((m) => m.shouldCallHandler());
|
| 6424 | invariant2(actionMatch, "No action match found");
|
| 6425 | let actionStatus = void 0;
|
| 6426 | let result = await actionMatch.resolve(async (handler) => {
|
| 6427 | let result2 = await handler(async () => {
|
| 6428 | let { data: data2, status } = await fetchAndDecode(
|
| 6429 | args,
|
| 6430 | basename,
|
| 6431 | trailingSlashAware,
|
| 6432 | [actionMatch.route.id]
|
| 6433 | );
|
| 6434 | actionStatus = status;
|
| 6435 | return unwrapSingleFetchResult(data2, actionMatch.route.id);
|
| 6436 | });
|
| 6437 | return result2;
|
| 6438 | });
|
| 6439 | if (isResponse(result.result) || isRouteErrorResponse(result.result) || isDataWithResponseInit(result.result)) {
|
| 6440 | return { [actionMatch.route.id]: result };
|
| 6441 | }
|
| 6442 | return {
|
| 6443 | [actionMatch.route.id]: {
|
| 6444 | type: result.type,
|
| 6445 | result: data(result.result, actionStatus)
|
| 6446 | }
|
| 6447 | };
|
| 6448 | }
|
| 6449 | async function nonSsrStrategy(args, getRouteInfo, fetchAndDecode, basename, trailingSlashAware) {
|
| 6450 | let matchesToLoad = args.matches.filter((m) => m.shouldCallHandler());
|
| 6451 | let results = {};
|
| 6452 | await Promise.all(
|
| 6453 | matchesToLoad.map(
|
| 6454 | (m) => m.resolve(async (handler) => {
|
| 6455 | try {
|
| 6456 | let { hasClientLoader } = getRouteInfo(m);
|
| 6457 | let routeId = m.route.id;
|
| 6458 | let result = hasClientLoader ? await handler(async () => {
|
| 6459 | let { data: data2 } = await fetchAndDecode(
|
| 6460 | args,
|
| 6461 | basename,
|
| 6462 | trailingSlashAware,
|
| 6463 | [routeId]
|
| 6464 | );
|
| 6465 | return unwrapSingleFetchResult(data2, routeId);
|
| 6466 | }) : await handler();
|
| 6467 | results[m.route.id] = { type: "data", result };
|
| 6468 | } catch (e) {
|
| 6469 | results[m.route.id] = { type: "error", result: e };
|
| 6470 | }
|
| 6471 | })
|
| 6472 | )
|
| 6473 | );
|
| 6474 | return results;
|
| 6475 | }
|
| 6476 | async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, fetchAndDecode, ssr, basename, trailingSlashAware, shouldAllowOptOut = () => true) {
|
| 6477 | let routesParams = new Set();
|
| 6478 | let foundOptOutRoute = false;
|
| 6479 | let routeDfds = args.matches.map(() => createDeferred2());
|
| 6480 | let singleFetchDfd = createDeferred2();
|
| 6481 | let results = {};
|
| 6482 | let resolvePromise = Promise.all(
|
| 6483 | args.matches.map(
|
| 6484 | async (m, i) => m.resolve(async (handler) => {
|
| 6485 | routeDfds[i].resolve();
|
| 6486 | let routeId = m.route.id;
|
| 6487 | let { hasLoader, hasClientLoader, hasShouldRevalidate } = getRouteInfo(m);
|
| 6488 | let defaultShouldRevalidate = !m.shouldRevalidateArgs || m.shouldRevalidateArgs.actionStatus == null || m.shouldRevalidateArgs.actionStatus < 400;
|
| 6489 | let shouldCall = m.shouldCallHandler(defaultShouldRevalidate);
|
| 6490 | if (!shouldCall) {
|
| 6491 | foundOptOutRoute || (foundOptOutRoute = m.shouldRevalidateArgs != null &&
|
| 6492 | hasLoader &&
|
| 6493 | hasShouldRevalidate === true);
|
| 6494 | return;
|
| 6495 | }
|
| 6496 | if (shouldAllowOptOut(m) && hasClientLoader) {
|
| 6497 | if (hasLoader) {
|
| 6498 | foundOptOutRoute = true;
|
| 6499 | }
|
| 6500 | try {
|
| 6501 | let result = await handler(async () => {
|
| 6502 | let { data: data2 } = await fetchAndDecode(
|
| 6503 | args,
|
| 6504 | basename,
|
| 6505 | trailingSlashAware,
|
| 6506 | [routeId]
|
| 6507 | );
|
| 6508 | return unwrapSingleFetchResult(data2, routeId);
|
| 6509 | });
|
| 6510 | results[routeId] = { type: "data", result };
|
| 6511 | } catch (e) {
|
| 6512 | results[routeId] = { type: "error", result: e };
|
| 6513 | }
|
| 6514 | return;
|
| 6515 | }
|
| 6516 | if (hasLoader) {
|
| 6517 | routesParams.add(routeId);
|
| 6518 | }
|
| 6519 | try {
|
| 6520 | let result = await handler(async () => {
|
| 6521 | let data2 = await singleFetchDfd.promise;
|
| 6522 | return unwrapSingleFetchResult(data2, routeId);
|
| 6523 | });
|
| 6524 | results[routeId] = { type: "data", result };
|
| 6525 | } catch (e) {
|
| 6526 | results[routeId] = { type: "error", result: e };
|
| 6527 | }
|
| 6528 | })
|
| 6529 | )
|
| 6530 | );
|
| 6531 | await Promise.all(routeDfds.map((d) => d.promise));
|
| 6532 | let isInitialLoad = !router.state.initialized && router.state.navigation.state === "idle";
|
| 6533 | if ((isInitialLoad || routesParams.size === 0) && !window.__reactRouterHdrActive) {
|
| 6534 | singleFetchDfd.resolve({ routes: {} });
|
| 6535 | } else {
|
| 6536 | let targetRoutes = ssr && foundOptOutRoute && routesParams.size > 0 ? [...routesParams.keys()] : void 0;
|
| 6537 | try {
|
| 6538 | let data2 = await fetchAndDecode(
|
| 6539 | args,
|
| 6540 | basename,
|
| 6541 | trailingSlashAware,
|
| 6542 | targetRoutes
|
| 6543 | );
|
| 6544 | singleFetchDfd.resolve(data2.data);
|
| 6545 | } catch (e) {
|
| 6546 | singleFetchDfd.reject(e);
|
| 6547 | }
|
| 6548 | }
|
| 6549 | await resolvePromise;
|
| 6550 | await bubbleMiddlewareErrors(
|
| 6551 | singleFetchDfd.promise,
|
| 6552 | args.matches,
|
| 6553 | routesParams,
|
| 6554 | results
|
| 6555 | );
|
| 6556 | return results;
|
| 6557 | }
|
| 6558 | async function bubbleMiddlewareErrors(singleFetchPromise, matches, routesParams, results) {
|
| 6559 | try {
|
| 6560 | let middlewareError;
|
| 6561 | let fetchedData = await singleFetchPromise;
|
| 6562 | if ("routes" in fetchedData) {
|
| 6563 | for (let match of matches) {
|
| 6564 | if (match.route.id in fetchedData.routes) {
|
| 6565 | let routeResult = fetchedData.routes[match.route.id];
|
| 6566 | if ("error" in routeResult) {
|
| 6567 | middlewareError = routeResult.error;
|
| 6568 | if (_optionalChain([results, 'access', _84 => _84[match.route.id], 'optionalAccess', _85 => _85.result]) == null) {
|
| 6569 | results[match.route.id] = {
|
| 6570 | type: "error",
|
| 6571 | result: middlewareError
|
| 6572 | };
|
| 6573 | }
|
| 6574 | break;
|
| 6575 | }
|
| 6576 | }
|
| 6577 | }
|
| 6578 | }
|
| 6579 | if (middlewareError !== void 0) {
|
| 6580 | Array.from(routesParams.values()).forEach((routeId) => {
|
| 6581 | if (results[routeId].result instanceof SingleFetchNoResultError) {
|
| 6582 | results[routeId].result = middlewareError;
|
| 6583 | }
|
| 6584 | });
|
| 6585 | }
|
| 6586 | } catch (e) {
|
| 6587 | }
|
| 6588 | }
|
| 6589 | async function singleFetchLoaderFetcherStrategy(args, fetchAndDecode, basename, trailingSlashAware) {
|
| 6590 | let fetcherMatch = args.matches.find((m) => m.shouldCallHandler());
|
| 6591 | invariant2(fetcherMatch, "No fetcher match found");
|
| 6592 | let routeId = fetcherMatch.route.id;
|
| 6593 | let result = await fetcherMatch.resolve(
|
| 6594 | async (handler) => handler(async () => {
|
| 6595 | let { data: data2 } = await fetchAndDecode(args, basename, trailingSlashAware, [
|
| 6596 | routeId
|
| 6597 | ]);
|
| 6598 | return unwrapSingleFetchResult(data2, routeId);
|
| 6599 | })
|
| 6600 | );
|
| 6601 | return { [fetcherMatch.route.id]: result };
|
| 6602 | }
|
| 6603 | function stripIndexParam(url) {
|
| 6604 | let indexValues = url.searchParams.getAll("index");
|
| 6605 | url.searchParams.delete("index");
|
| 6606 | let indexValuesToKeep = [];
|
| 6607 | for (let indexValue of indexValues) {
|
| 6608 | if (indexValue) {
|
| 6609 | indexValuesToKeep.push(indexValue);
|
| 6610 | }
|
| 6611 | }
|
| 6612 | for (let toKeep of indexValuesToKeep) {
|
| 6613 | url.searchParams.append("index", toKeep);
|
| 6614 | }
|
| 6615 | return url;
|
| 6616 | }
|
| 6617 | function singleFetchUrl(reqUrl, basename, trailingSlashAware, extension) {
|
| 6618 | let url = typeof reqUrl === "string" ? new URL(
|
| 6619 | reqUrl,
|
| 6620 |
|
| 6621 |
|
| 6622 | typeof window === "undefined" ? "server://singlefetch/" : window.location.origin
|
| 6623 | ) : reqUrl;
|
| 6624 | if (trailingSlashAware) {
|
| 6625 | if (url.pathname.endsWith("/")) {
|
| 6626 | url.pathname = `${url.pathname}_.${extension}`;
|
| 6627 | } else {
|
| 6628 | url.pathname = `${url.pathname}.${extension}`;
|
| 6629 | }
|
| 6630 | } else {
|
| 6631 | if (url.pathname === "/") {
|
| 6632 | url.pathname = `_root.${extension}`;
|
| 6633 | } else if (basename && stripBasename(url.pathname, basename) === "/") {
|
| 6634 | url.pathname = `${removeTrailingSlash(basename)}/_root.${extension}`;
|
| 6635 | } else {
|
| 6636 | url.pathname = `${removeTrailingSlash(url.pathname)}.${extension}`;
|
| 6637 | }
|
| 6638 | }
|
| 6639 | return url;
|
| 6640 | }
|
| 6641 | async function fetchAndDecodeViaTurboStream(args, basename, trailingSlashAware, targetRoutes) {
|
| 6642 | let { request } = args;
|
| 6643 | let url = singleFetchUrl(request.url, basename, trailingSlashAware, "data");
|
| 6644 | if (request.method === "GET") {
|
| 6645 | url = stripIndexParam(url);
|
| 6646 | if (targetRoutes) {
|
| 6647 | url.searchParams.set("_routes", targetRoutes.join(","));
|
| 6648 | }
|
| 6649 | }
|
| 6650 | let res = await fetch(url, await createRequestInit(request));
|
| 6651 | if (res.status >= 400 && !res.headers.has("X-Remix-Response")) {
|
| 6652 | throw new ErrorResponseImpl(res.status, res.statusText, await res.text());
|
| 6653 | }
|
| 6654 | if (res.status === 204 && res.headers.has("X-Remix-Redirect")) {
|
| 6655 | return {
|
| 6656 | status: SINGLE_FETCH_REDIRECT_STATUS,
|
| 6657 | data: {
|
| 6658 | redirect: {
|
| 6659 | redirect: res.headers.get("X-Remix-Redirect"),
|
| 6660 | status: Number(res.headers.get("X-Remix-Status") || "302"),
|
| 6661 | revalidate: res.headers.get("X-Remix-Revalidate") === "true",
|
| 6662 | reload: res.headers.get("X-Remix-Reload-Document") === "true",
|
| 6663 | replace: res.headers.get("X-Remix-Replace") === "true"
|
| 6664 | }
|
| 6665 | }
|
| 6666 | };
|
| 6667 | }
|
| 6668 | if (NO_BODY_STATUS_CODES.has(res.status)) {
|
| 6669 | let routes = {};
|
| 6670 | if (targetRoutes && request.method !== "GET") {
|
| 6671 | routes[targetRoutes[0]] = { data: void 0 };
|
| 6672 | }
|
| 6673 | return {
|
| 6674 | status: res.status,
|
| 6675 | data: { routes }
|
| 6676 | };
|
| 6677 | }
|
| 6678 | invariant2(res.body, "No response body to decode");
|
| 6679 | try {
|
| 6680 | let decoded = await decodeViaTurboStream(res.body, window);
|
| 6681 | let data2;
|
| 6682 | if (request.method === "GET") {
|
| 6683 | let typed = decoded.value;
|
| 6684 | if (SingleFetchRedirectSymbol in typed) {
|
| 6685 | data2 = { redirect: typed[SingleFetchRedirectSymbol] };
|
| 6686 | } else {
|
| 6687 | data2 = { routes: typed };
|
| 6688 | }
|
| 6689 | } else {
|
| 6690 | let typed = decoded.value;
|
| 6691 | let routeId = _optionalChain([targetRoutes, 'optionalAccess', _86 => _86[0]]);
|
| 6692 | invariant2(routeId, "No routeId found for single fetch call decoding");
|
| 6693 | if ("redirect" in typed) {
|
| 6694 | data2 = { redirect: typed };
|
| 6695 | } else {
|
| 6696 | data2 = { routes: { [routeId]: typed } };
|
| 6697 | }
|
| 6698 | }
|
| 6699 | return { status: res.status, data: data2 };
|
| 6700 | } catch (e) {
|
| 6701 | throw new Error("Unable to decode turbo-stream response");
|
| 6702 | }
|
| 6703 | }
|
| 6704 | function decodeViaTurboStream(body, global) {
|
| 6705 | return decode(body, {
|
| 6706 | plugins: [
|
| 6707 | (type, ...rest) => {
|
| 6708 | if (type === "SanitizedError") {
|
| 6709 | let [name, message, stack] = rest;
|
| 6710 | let Constructor = Error;
|
| 6711 | if (name && name in global && typeof global[name] === "function") {
|
| 6712 | Constructor = global[name];
|
| 6713 | }
|
| 6714 | let error = new Constructor(message);
|
| 6715 | error.stack = stack;
|
| 6716 | return { value: error };
|
| 6717 | }
|
| 6718 | if (type === "ErrorResponse") {
|
| 6719 | let [data2, status, statusText] = rest;
|
| 6720 | return {
|
| 6721 | value: new ErrorResponseImpl(status, statusText, data2)
|
| 6722 | };
|
| 6723 | }
|
| 6724 | if (type === "SingleFetchRedirect") {
|
| 6725 | return { value: { [SingleFetchRedirectSymbol]: rest[0] } };
|
| 6726 | }
|
| 6727 | if (type === "SingleFetchClassInstance") {
|
| 6728 | return { value: rest[0] };
|
| 6729 | }
|
| 6730 | if (type === "SingleFetchFallback") {
|
| 6731 | return { value: void 0 };
|
| 6732 | }
|
| 6733 | }
|
| 6734 | ]
|
| 6735 | });
|
| 6736 | }
|
| 6737 | function unwrapSingleFetchResult(result, routeId) {
|
| 6738 | if ("redirect" in result) {
|
| 6739 | let {
|
| 6740 | redirect: location,
|
| 6741 | revalidate,
|
| 6742 | reload,
|
| 6743 | replace: replace2,
|
| 6744 | status
|
| 6745 | } = result.redirect;
|
| 6746 | throw redirect(location, {
|
| 6747 | status,
|
| 6748 | headers: {
|
| 6749 |
|
| 6750 | ...revalidate ? { "X-Remix-Revalidate": "yes" } : null,
|
| 6751 | ...reload ? { "X-Remix-Reload-Document": "yes" } : null,
|
| 6752 | ...replace2 ? { "X-Remix-Replace": "yes" } : null
|
| 6753 | }
|
| 6754 | });
|
| 6755 | }
|
| 6756 | let routeResult = result.routes[routeId];
|
| 6757 | if (routeResult == null) {
|
| 6758 | throw new SingleFetchNoResultError(
|
| 6759 | `No result found for routeId "${routeId}"`
|
| 6760 | );
|
| 6761 | } else if ("error" in routeResult) {
|
| 6762 | throw routeResult.error;
|
| 6763 | } else if ("data" in routeResult) {
|
| 6764 | return routeResult.data;
|
| 6765 | } else {
|
| 6766 | throw new Error(`Invalid response found for routeId "${routeId}"`);
|
| 6767 | }
|
| 6768 | }
|
| 6769 | function createDeferred2() {
|
| 6770 | let resolve;
|
| 6771 | let reject;
|
| 6772 | let promise = new Promise((res, rej) => {
|
| 6773 | resolve = async (val) => {
|
| 6774 | res(val);
|
| 6775 | try {
|
| 6776 | await promise;
|
| 6777 | } catch (e) {
|
| 6778 | }
|
| 6779 | };
|
| 6780 | reject = async (error) => {
|
| 6781 | rej(error);
|
| 6782 | try {
|
| 6783 | await promise;
|
| 6784 | } catch (e) {
|
| 6785 | }
|
| 6786 | };
|
| 6787 | });
|
| 6788 | return {
|
| 6789 | promise,
|
| 6790 |
|
| 6791 | resolve,
|
| 6792 |
|
| 6793 | reject
|
| 6794 | };
|
| 6795 | }
|
| 6796 |
|
| 6797 |
|
| 6798 |
|
| 6799 | var DataRouterContext = React2.createContext(null);
|
| 6800 | DataRouterContext.displayName = "DataRouter";
|
| 6801 | var DataRouterStateContext = React2.createContext(null);
|
| 6802 | DataRouterStateContext.displayName = "DataRouterState";
|
| 6803 | var RSCRouterContext = React2.createContext(false);
|
| 6804 | function useIsRSCRouterContext() {
|
| 6805 | return React2.useContext(RSCRouterContext);
|
| 6806 | }
|
| 6807 | var ViewTransitionContext = React2.createContext({
|
| 6808 | isTransitioning: false
|
| 6809 | });
|
| 6810 | ViewTransitionContext.displayName = "ViewTransition";
|
| 6811 | var FetchersContext = React2.createContext(
|
| 6812 | new Map()
|
| 6813 | );
|
| 6814 | FetchersContext.displayName = "Fetchers";
|
| 6815 | var AwaitContext = React2.createContext(null);
|
| 6816 | AwaitContext.displayName = "Await";
|
| 6817 | var AwaitContextProvider = (props) => React2.createElement(AwaitContext.Provider, props);
|
| 6818 | var NavigationContext = React2.createContext(
|
| 6819 | null
|
| 6820 | );
|
| 6821 | NavigationContext.displayName = "Navigation";
|
| 6822 | var LocationContext = React2.createContext(
|
| 6823 | null
|
| 6824 | );
|
| 6825 | LocationContext.displayName = "Location";
|
| 6826 | var RouteContext = React2.createContext({
|
| 6827 | outlet: null,
|
| 6828 | matches: [],
|
| 6829 | isDataRoute: false
|
| 6830 | });
|
| 6831 | RouteContext.displayName = "Route";
|
| 6832 | var RouteErrorContext = React2.createContext(null);
|
| 6833 | RouteErrorContext.displayName = "RouteError";
|
| 6834 | var ENABLE_DEV_WARNINGS = false;
|
| 6835 |
|
| 6836 |
|
| 6837 |
|
| 6838 |
|
| 6839 |
|
| 6840 | var ERROR_DIGEST_BASE = "REACT_ROUTER_ERROR";
|
| 6841 | var ERROR_DIGEST_REDIRECT = "REDIRECT";
|
| 6842 | var ERROR_DIGEST_ROUTE_ERROR_RESPONSE = "ROUTE_ERROR_RESPONSE";
|
| 6843 | function decodeRedirectErrorDigest(digest) {
|
| 6844 | if (digest.startsWith(`${ERROR_DIGEST_BASE}:${ERROR_DIGEST_REDIRECT}:{`)) {
|
| 6845 | try {
|
| 6846 | let parsed = JSON.parse(digest.slice(28));
|
| 6847 | if (typeof parsed === "object" && parsed && typeof parsed.status === "number" && typeof parsed.statusText === "string" && typeof parsed.location === "string" && typeof parsed.reloadDocument === "boolean" && typeof parsed.replace === "boolean") {
|
| 6848 | return parsed;
|
| 6849 | }
|
| 6850 | } catch (e2) {
|
| 6851 | }
|
| 6852 | }
|
| 6853 | }
|
| 6854 | function decodeRouteErrorResponseDigest(digest) {
|
| 6855 | if (digest.startsWith(
|
| 6856 | `${ERROR_DIGEST_BASE}:${ERROR_DIGEST_ROUTE_ERROR_RESPONSE}:{`
|
| 6857 | )) {
|
| 6858 | try {
|
| 6859 | let parsed = JSON.parse(digest.slice(40));
|
| 6860 | if (typeof parsed === "object" && parsed && typeof parsed.status === "number" && typeof parsed.statusText === "string") {
|
| 6861 | return new ErrorResponseImpl(
|
| 6862 | parsed.status,
|
| 6863 | parsed.statusText,
|
| 6864 | parsed.data
|
| 6865 | );
|
| 6866 | }
|
| 6867 | } catch (e3) {
|
| 6868 | }
|
| 6869 | }
|
| 6870 | }
|
| 6871 |
|
| 6872 |
|
| 6873 | function useHref(to, { relative } = {}) {
|
| 6874 | invariant(
|
| 6875 | useInRouterContext(),
|
| 6876 |
|
| 6877 |
|
| 6878 | `useHref() may be used only in the context of a <Router> component.`
|
| 6879 | );
|
| 6880 | let { basename, navigator } = React3.useContext(NavigationContext);
|
| 6881 | let { hash, pathname, search } = useResolvedPath(to, { relative });
|
| 6882 | let joinedPathname = pathname;
|
| 6883 | if (basename !== "/") {
|
| 6884 | joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
|
| 6885 | }
|
| 6886 | return navigator.createHref({ pathname: joinedPathname, search, hash });
|
| 6887 | }
|
| 6888 | function useInRouterContext() {
|
| 6889 | return React3.useContext(LocationContext) != null;
|
| 6890 | }
|
| 6891 | function useLocation() {
|
| 6892 | invariant(
|
| 6893 | useInRouterContext(),
|
| 6894 |
|
| 6895 |
|
| 6896 | `useLocation() may be used only in the context of a <Router> component.`
|
| 6897 | );
|
| 6898 | return React3.useContext(LocationContext).location;
|
| 6899 | }
|
| 6900 | function useNavigationType() {
|
| 6901 | return React3.useContext(LocationContext).navigationType;
|
| 6902 | }
|
| 6903 | function useMatch(pattern) {
|
| 6904 | invariant(
|
| 6905 | useInRouterContext(),
|
| 6906 |
|
| 6907 |
|
| 6908 | `useMatch() may be used only in the context of a <Router> component.`
|
| 6909 | );
|
| 6910 | let { pathname } = useLocation();
|
| 6911 | return React3.useMemo(
|
| 6912 | () => matchPath(pattern, decodePath(pathname)),
|
| 6913 | [pathname, pattern]
|
| 6914 | );
|
| 6915 | }
|
| 6916 | var navigateEffectWarning = `You should call navigate() in a React.useEffect(), not when your component is first rendered.`;
|
| 6917 | function useIsomorphicLayoutEffect(cb) {
|
| 6918 | let isStatic = React3.useContext(NavigationContext).static;
|
| 6919 | if (!isStatic) {
|
| 6920 | React3.useLayoutEffect(cb);
|
| 6921 | }
|
| 6922 | }
|
| 6923 | function useNavigate() {
|
| 6924 | let { isDataRoute } = React3.useContext(RouteContext);
|
| 6925 | return isDataRoute ? useNavigateStable() : useNavigateUnstable();
|
| 6926 | }
|
| 6927 | function useNavigateUnstable() {
|
| 6928 | invariant(
|
| 6929 | useInRouterContext(),
|
| 6930 |
|
| 6931 |
|
| 6932 | `useNavigate() may be used only in the context of a <Router> component.`
|
| 6933 | );
|
| 6934 | let dataRouterContext = React3.useContext(DataRouterContext);
|
| 6935 | let { basename, navigator } = React3.useContext(NavigationContext);
|
| 6936 | let { matches } = React3.useContext(RouteContext);
|
| 6937 | let { pathname: locationPathname } = useLocation();
|
| 6938 | let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
|
| 6939 | let activeRef = React3.useRef(false);
|
| 6940 | useIsomorphicLayoutEffect(() => {
|
| 6941 | activeRef.current = true;
|
| 6942 | });
|
| 6943 | let navigate = React3.useCallback(
|
| 6944 | (to, options = {}) => {
|
| 6945 | warning(activeRef.current, navigateEffectWarning);
|
| 6946 | if (!activeRef.current) return;
|
| 6947 | if (typeof to === "number") {
|
| 6948 | navigator.go(to);
|
| 6949 | return;
|
| 6950 | }
|
| 6951 | let path = resolveTo(
|
| 6952 | to,
|
| 6953 | JSON.parse(routePathnamesJson),
|
| 6954 | locationPathname,
|
| 6955 | options.relative === "path"
|
| 6956 | );
|
| 6957 | if (dataRouterContext == null && basename !== "/") {
|
| 6958 | path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
| 6959 | }
|
| 6960 | (!!options.replace ? navigator.replace : navigator.push)(
|
| 6961 | path,
|
| 6962 | options.state,
|
| 6963 | options
|
| 6964 | );
|
| 6965 | },
|
| 6966 | [
|
| 6967 | basename,
|
| 6968 | navigator,
|
| 6969 | routePathnamesJson,
|
| 6970 | locationPathname,
|
| 6971 | dataRouterContext
|
| 6972 | ]
|
| 6973 | );
|
| 6974 | return navigate;
|
| 6975 | }
|
| 6976 | var OutletContext = React3.createContext(null);
|
| 6977 | function useOutletContext() {
|
| 6978 | return React3.useContext(OutletContext);
|
| 6979 | }
|
| 6980 | function useOutlet(context) {
|
| 6981 | let outlet = React3.useContext(RouteContext).outlet;
|
| 6982 | return React3.useMemo(
|
| 6983 | () => outlet && React3.createElement(OutletContext.Provider, { value: context }, outlet),
|
| 6984 | [outlet, context]
|
| 6985 | );
|
| 6986 | }
|
| 6987 | function useParams() {
|
| 6988 | let { matches } = React3.useContext(RouteContext);
|
| 6989 | let routeMatch = matches[matches.length - 1];
|
| 6990 | return routeMatch ? routeMatch.params : {};
|
| 6991 | }
|
| 6992 | function useResolvedPath(to, { relative } = {}) {
|
| 6993 | let { matches } = React3.useContext(RouteContext);
|
| 6994 | let { pathname: locationPathname } = useLocation();
|
| 6995 | let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
|
| 6996 | return React3.useMemo(
|
| 6997 | () => resolveTo(
|
| 6998 | to,
|
| 6999 | JSON.parse(routePathnamesJson),
|
| 7000 | locationPathname,
|
| 7001 | relative === "path"
|
| 7002 | ),
|
| 7003 | [to, routePathnamesJson, locationPathname, relative]
|
| 7004 | );
|
| 7005 | }
|
| 7006 | function useRoutes(routes, locationArg) {
|
| 7007 | return useRoutesImpl(routes, locationArg);
|
| 7008 | }
|
| 7009 | function useRoutesImpl(routes, locationArg, dataRouterOpts) {
|
| 7010 | invariant(
|
| 7011 | useInRouterContext(),
|
| 7012 |
|
| 7013 |
|
| 7014 | `useRoutes() may be used only in the context of a <Router> component.`
|
| 7015 | );
|
| 7016 | let { navigator } = React3.useContext(NavigationContext);
|
| 7017 | let { matches: parentMatches } = React3.useContext(RouteContext);
|
| 7018 | let routeMatch = parentMatches[parentMatches.length - 1];
|
| 7019 | let parentParams = routeMatch ? routeMatch.params : {};
|
| 7020 | let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
| 7021 | let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
| 7022 | let parentRoute = routeMatch && routeMatch.route;
|
| 7023 | if (ENABLE_DEV_WARNINGS) {
|
| 7024 | let parentPath = parentRoute && parentRoute.path || "";
|
| 7025 | warningOnce(
|
| 7026 | parentPathname,
|
| 7027 | !parentRoute || parentPath.endsWith("*") || parentPath.endsWith("*?"),
|
| 7028 | `You rendered descendant <Routes> (or called \`useRoutes()\`) at "${parentPathname}" (under <Route path="${parentPath}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
|
| 7029 |
|
| 7030 | Please change the parent <Route path="${parentPath}"> to <Route path="${parentPath === "/" ? "*" : `${parentPath}/*`}">.`
|
| 7031 | );
|
| 7032 | }
|
| 7033 | let locationFromContext = useLocation();
|
| 7034 | let location;
|
| 7035 | if (locationArg) {
|
| 7036 | let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
| 7037 | invariant(
|
| 7038 | parentPathnameBase === "/" || _optionalChain([parsedLocationArg, 'access', _87 => _87.pathname, 'optionalAccess', _88 => _88.startsWith, 'call', _89 => _89(parentPathnameBase)]),
|
| 7039 | `When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${parentPathnameBase}" but pathname "${parsedLocationArg.pathname}" was given in the \`location\` prop.`
|
| 7040 | );
|
| 7041 | location = parsedLocationArg;
|
| 7042 | } else {
|
| 7043 | location = locationFromContext;
|
| 7044 | }
|
| 7045 | let pathname = location.pathname || "/";
|
| 7046 | let remainingPathname = pathname;
|
| 7047 | if (parentPathnameBase !== "/") {
|
| 7048 | let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
|
| 7049 | let segments = pathname.replace(/^\//, "").split("/");
|
| 7050 | remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
|
| 7051 | }
|
| 7052 | let matches = matchRoutes(routes, { pathname: remainingPathname });
|
| 7053 | if (ENABLE_DEV_WARNINGS) {
|
| 7054 | warning(
|
| 7055 | parentRoute || matches != null,
|
| 7056 | `No routes matched location "${location.pathname}${location.search}${location.hash}" `
|
| 7057 | );
|
| 7058 | warning(
|
| 7059 | matches == null || matches[matches.length - 1].route.element !== void 0 || matches[matches.length - 1].route.Component !== void 0 || matches[matches.length - 1].route.lazy !== void 0,
|
| 7060 | `Matched leaf route at location "${location.pathname}${location.search}${location.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
|
| 7061 | );
|
| 7062 | }
|
| 7063 | let renderedMatches = _renderMatches(
|
| 7064 | matches && matches.map(
|
| 7065 | (match) => Object.assign({}, match, {
|
| 7066 | params: Object.assign({}, parentParams, match.params),
|
| 7067 | pathname: joinPaths([
|
| 7068 | parentPathnameBase,
|
| 7069 |
|
| 7070 |
|
| 7071 |
|
| 7072 |
|
| 7073 | navigator.encodeLocation ? navigator.encodeLocation(
|
| 7074 | match.pathname.replace(/%/g, "%25").replace(/\?/g, "%3F").replace(/#/g, "%23")
|
| 7075 | ).pathname : match.pathname
|
| 7076 | ]),
|
| 7077 | pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
|
| 7078 | parentPathnameBase,
|
| 7079 |
|
| 7080 |
|
| 7081 |
|
| 7082 |
|
| 7083 | navigator.encodeLocation ? navigator.encodeLocation(
|
| 7084 | match.pathnameBase.replace(/%/g, "%25").replace(/\?/g, "%3F").replace(/#/g, "%23")
|
| 7085 | ).pathname : match.pathnameBase
|
| 7086 | ])
|
| 7087 | })
|
| 7088 | ),
|
| 7089 | parentMatches,
|
| 7090 | dataRouterOpts
|
| 7091 | );
|
| 7092 | if (locationArg && renderedMatches) {
|
| 7093 | return React3.createElement(
|
| 7094 | LocationContext.Provider,
|
| 7095 | {
|
| 7096 | value: {
|
| 7097 | location: {
|
| 7098 | pathname: "/",
|
| 7099 | search: "",
|
| 7100 | hash: "",
|
| 7101 | state: null,
|
| 7102 | key: "default",
|
| 7103 | unstable_mask: void 0,
|
| 7104 | ...location
|
| 7105 | },
|
| 7106 | navigationType: "POP"
|
| 7107 | }
|
| 7108 | },
|
| 7109 | renderedMatches
|
| 7110 | );
|
| 7111 | }
|
| 7112 | return renderedMatches;
|
| 7113 | }
|
| 7114 | function DefaultErrorComponent() {
|
| 7115 | let error = useRouteError();
|
| 7116 | let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
|
| 7117 | let stack = error instanceof Error ? error.stack : null;
|
| 7118 | let lightgrey = "rgba(200,200,200, 0.5)";
|
| 7119 | let preStyles = { padding: "0.5rem", backgroundColor: lightgrey };
|
| 7120 | let codeStyles = { padding: "2px 4px", backgroundColor: lightgrey };
|
| 7121 | let devInfo = null;
|
| 7122 | if (ENABLE_DEV_WARNINGS) {
|
| 7123 | console.error(
|
| 7124 | "Error handled by React Router default ErrorBoundary:",
|
| 7125 | error
|
| 7126 | );
|
| 7127 | devInfo = React3.createElement(React3.Fragment, null, React3.createElement("p", null, "\u{1F4BF} Hey developer \u{1F44B}"), React3.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", React3.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", React3.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
|
| 7128 | }
|
| 7129 | return React3.createElement(React3.Fragment, null, React3.createElement("h2", null, "Unexpected Application Error!"), React3.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? React3.createElement("pre", { style: preStyles }, stack) : null, devInfo);
|
| 7130 | }
|
| 7131 | var defaultErrorElement = React3.createElement(DefaultErrorComponent, null);
|
| 7132 | var RenderErrorBoundary = class extends React3.Component {
|
| 7133 | constructor(props) {
|
| 7134 | super(props);
|
| 7135 | this.state = {
|
| 7136 | location: props.location,
|
| 7137 | revalidation: props.revalidation,
|
| 7138 | error: props.error
|
| 7139 | };
|
| 7140 | }
|
| 7141 | static getDerivedStateFromError(error) {
|
| 7142 | return { error };
|
| 7143 | }
|
| 7144 | static getDerivedStateFromProps(props, state) {
|
| 7145 | if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
|
| 7146 | return {
|
| 7147 | error: props.error,
|
| 7148 | location: props.location,
|
| 7149 | revalidation: props.revalidation
|
| 7150 | };
|
| 7151 | }
|
| 7152 | return {
|
| 7153 | error: props.error !== void 0 ? props.error : state.error,
|
| 7154 | location: state.location,
|
| 7155 | revalidation: props.revalidation || state.revalidation
|
| 7156 | };
|
| 7157 | }
|
| 7158 | componentDidCatch(error, errorInfo) {
|
| 7159 | if (this.props.onError) {
|
| 7160 | this.props.onError(error, errorInfo);
|
| 7161 | } else {
|
| 7162 | console.error(
|
| 7163 | "React Router caught the following error during render",
|
| 7164 | error
|
| 7165 | );
|
| 7166 | }
|
| 7167 | }
|
| 7168 | render() {
|
| 7169 | let error = this.state.error;
|
| 7170 | if (this.context && typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
|
| 7171 | const decoded = decodeRouteErrorResponseDigest(error.digest);
|
| 7172 | if (decoded) error = decoded;
|
| 7173 | }
|
| 7174 | let result = error !== void 0 ? React3.createElement(RouteContext.Provider, { value: this.props.routeContext }, React3.createElement(
|
| 7175 | RouteErrorContext.Provider,
|
| 7176 | {
|
| 7177 | value: error,
|
| 7178 | children: this.props.component
|
| 7179 | }
|
| 7180 | )) : this.props.children;
|
| 7181 | if (this.context) {
|
| 7182 | return React3.createElement(RSCErrorHandler, { error }, result);
|
| 7183 | }
|
| 7184 | return result;
|
| 7185 | }
|
| 7186 | };
|
| 7187 | RenderErrorBoundary.contextType = RSCRouterContext;
|
| 7188 | var errorRedirectHandledMap = new WeakMap();
|
| 7189 | function RSCErrorHandler({
|
| 7190 | children,
|
| 7191 | error
|
| 7192 | }) {
|
| 7193 | let { basename } = React3.useContext(NavigationContext);
|
| 7194 | if (typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
|
| 7195 | let redirect2 = decodeRedirectErrorDigest(error.digest);
|
| 7196 | if (redirect2) {
|
| 7197 | let existingRedirect = errorRedirectHandledMap.get(error);
|
| 7198 | if (existingRedirect) throw existingRedirect;
|
| 7199 | let parsed = parseToInfo(redirect2.location, basename);
|
| 7200 | if (isBrowser && !errorRedirectHandledMap.get(error)) {
|
| 7201 | if (parsed.isExternal || redirect2.reloadDocument) {
|
| 7202 | window.location.href = parsed.absoluteURL || parsed.to;
|
| 7203 | } else {
|
| 7204 | const redirectPromise = Promise.resolve().then(
|
| 7205 | () => window.__reactRouterDataRouter.navigate(parsed.to, {
|
| 7206 | replace: redirect2.replace
|
| 7207 | })
|
| 7208 | );
|
| 7209 | errorRedirectHandledMap.set(error, redirectPromise);
|
| 7210 | throw redirectPromise;
|
| 7211 | }
|
| 7212 | }
|
| 7213 | return React3.createElement(
|
| 7214 | "meta",
|
| 7215 | {
|
| 7216 | httpEquiv: "refresh",
|
| 7217 | content: `0;url=${parsed.absoluteURL || parsed.to}`
|
| 7218 | }
|
| 7219 | );
|
| 7220 | }
|
| 7221 | }
|
| 7222 | return children;
|
| 7223 | }
|
| 7224 | function RenderedRoute({ routeContext, match, children }) {
|
| 7225 | let dataRouterContext = React3.useContext(DataRouterContext);
|
| 7226 | if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
|
| 7227 | dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
|
| 7228 | }
|
| 7229 | return React3.createElement(RouteContext.Provider, { value: routeContext }, children);
|
| 7230 | }
|
| 7231 | function _renderMatches(matches, parentMatches = [], dataRouterOpts) {
|
| 7232 | let dataRouterState = _optionalChain([dataRouterOpts, 'optionalAccess', _90 => _90.state]);
|
| 7233 | if (matches == null) {
|
| 7234 | if (!dataRouterState) {
|
| 7235 | return null;
|
| 7236 | }
|
| 7237 | if (dataRouterState.errors) {
|
| 7238 | matches = dataRouterState.matches;
|
| 7239 | } else if (parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
|
| 7240 | matches = dataRouterState.matches;
|
| 7241 | } else {
|
| 7242 | return null;
|
| 7243 | }
|
| 7244 | }
|
| 7245 | let renderedMatches = matches;
|
| 7246 | let errors = _optionalChain([dataRouterState, 'optionalAccess', _91 => _91.errors]);
|
| 7247 | if (errors != null) {
|
| 7248 | let errorIndex = renderedMatches.findIndex(
|
| 7249 | (m) => m.route.id && _optionalChain([errors, 'optionalAccess', _92 => _92[m.route.id]]) !== void 0
|
| 7250 | );
|
| 7251 | invariant(
|
| 7252 | errorIndex >= 0,
|
| 7253 | `Could not find a matching route for errors on route IDs: ${Object.keys(
|
| 7254 | errors
|
| 7255 | ).join(",")}`
|
| 7256 | );
|
| 7257 | renderedMatches = renderedMatches.slice(
|
| 7258 | 0,
|
| 7259 | Math.min(renderedMatches.length, errorIndex + 1)
|
| 7260 | );
|
| 7261 | }
|
| 7262 | let renderFallback = false;
|
| 7263 | let fallbackIndex = -1;
|
| 7264 | if (dataRouterOpts && dataRouterState) {
|
| 7265 | renderFallback = dataRouterState.renderFallback;
|
| 7266 | for (let i = 0; i < renderedMatches.length; i++) {
|
| 7267 | let match = renderedMatches[i];
|
| 7268 | if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
|
| 7269 | fallbackIndex = i;
|
| 7270 | }
|
| 7271 | if (match.route.id) {
|
| 7272 | let { loaderData, errors: errors2 } = dataRouterState;
|
| 7273 | let needsToRunLoader = match.route.loader && !loaderData.hasOwnProperty(match.route.id) && (!errors2 || errors2[match.route.id] === void 0);
|
| 7274 | if (match.route.lazy || needsToRunLoader) {
|
| 7275 | if (dataRouterOpts.isStatic) {
|
| 7276 | renderFallback = true;
|
| 7277 | }
|
| 7278 | if (fallbackIndex >= 0) {
|
| 7279 | renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
|
| 7280 | } else {
|
| 7281 | renderedMatches = [renderedMatches[0]];
|
| 7282 | }
|
| 7283 | break;
|
| 7284 | }
|
| 7285 | }
|
| 7286 | }
|
| 7287 | }
|
| 7288 | let onErrorHandler = _optionalChain([dataRouterOpts, 'optionalAccess', _93 => _93.onError]);
|
| 7289 | let onError = dataRouterState && onErrorHandler ? (error, errorInfo) => {
|
| 7290 | onErrorHandler(error, {
|
| 7291 | location: dataRouterState.location,
|
| 7292 | params: _nullishCoalesce(_optionalChain([dataRouterState, 'access', _94 => _94.matches, 'optionalAccess', _95 => _95[0], 'optionalAccess', _96 => _96.params]), () => ( {})),
|
| 7293 | unstable_pattern: getRoutePattern(dataRouterState.matches),
|
| 7294 | errorInfo
|
| 7295 | });
|
| 7296 | } : void 0;
|
| 7297 | return renderedMatches.reduceRight(
|
| 7298 | (outlet, match, index) => {
|
| 7299 | let error;
|
| 7300 | let shouldRenderHydrateFallback = false;
|
| 7301 | let errorElement = null;
|
| 7302 | let hydrateFallbackElement = null;
|
| 7303 | if (dataRouterState) {
|
| 7304 | error = errors && match.route.id ? errors[match.route.id] : void 0;
|
| 7305 | errorElement = match.route.errorElement || defaultErrorElement;
|
| 7306 | if (renderFallback) {
|
| 7307 | if (fallbackIndex < 0 && index === 0) {
|
| 7308 | warningOnce(
|
| 7309 | "route-fallback",
|
| 7310 | false,
|
| 7311 | "No `HydrateFallback` element provided to render during initial hydration"
|
| 7312 | );
|
| 7313 | shouldRenderHydrateFallback = true;
|
| 7314 | hydrateFallbackElement = null;
|
| 7315 | } else if (fallbackIndex === index) {
|
| 7316 | shouldRenderHydrateFallback = true;
|
| 7317 | hydrateFallbackElement = match.route.hydrateFallbackElement || null;
|
| 7318 | }
|
| 7319 | }
|
| 7320 | }
|
| 7321 | let matches2 = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
| 7322 | let getChildren = () => {
|
| 7323 | let children;
|
| 7324 | if (error) {
|
| 7325 | children = errorElement;
|
| 7326 | } else if (shouldRenderHydrateFallback) {
|
| 7327 | children = hydrateFallbackElement;
|
| 7328 | } else if (match.route.Component) {
|
| 7329 | children = React3.createElement(match.route.Component, null);
|
| 7330 | } else if (match.route.element) {
|
| 7331 | children = match.route.element;
|
| 7332 | } else {
|
| 7333 | children = outlet;
|
| 7334 | }
|
| 7335 | return React3.createElement(
|
| 7336 | RenderedRoute,
|
| 7337 | {
|
| 7338 | match,
|
| 7339 | routeContext: {
|
| 7340 | outlet,
|
| 7341 | matches: matches2,
|
| 7342 | isDataRoute: dataRouterState != null
|
| 7343 | },
|
| 7344 | children
|
| 7345 | }
|
| 7346 | );
|
| 7347 | };
|
| 7348 | return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? React3.createElement(
|
| 7349 | RenderErrorBoundary,
|
| 7350 | {
|
| 7351 | location: dataRouterState.location,
|
| 7352 | revalidation: dataRouterState.revalidation,
|
| 7353 | component: errorElement,
|
| 7354 | error,
|
| 7355 | children: getChildren(),
|
| 7356 | routeContext: { outlet: null, matches: matches2, isDataRoute: true },
|
| 7357 | onError
|
| 7358 | }
|
| 7359 | ) : getChildren();
|
| 7360 | },
|
| 7361 | null
|
| 7362 | );
|
| 7363 | }
|
| 7364 | function getDataRouterConsoleError(hookName) {
|
| 7365 | return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
|
| 7366 | }
|
| 7367 | function useDataRouterContext(hookName) {
|
| 7368 | let ctx = React3.useContext(DataRouterContext);
|
| 7369 | invariant(ctx, getDataRouterConsoleError(hookName));
|
| 7370 | return ctx;
|
| 7371 | }
|
| 7372 | function useDataRouterState(hookName) {
|
| 7373 | let state = React3.useContext(DataRouterStateContext);
|
| 7374 | invariant(state, getDataRouterConsoleError(hookName));
|
| 7375 | return state;
|
| 7376 | }
|
| 7377 | function useRouteContext(hookName) {
|
| 7378 | let route = React3.useContext(RouteContext);
|
| 7379 | invariant(route, getDataRouterConsoleError(hookName));
|
| 7380 | return route;
|
| 7381 | }
|
| 7382 | function useCurrentRouteId(hookName) {
|
| 7383 | let route = useRouteContext(hookName);
|
| 7384 | let thisRoute = route.matches[route.matches.length - 1];
|
| 7385 | invariant(
|
| 7386 | thisRoute.route.id,
|
| 7387 | `${hookName} can only be used on routes that contain a unique "id"`
|
| 7388 | );
|
| 7389 | return thisRoute.route.id;
|
| 7390 | }
|
| 7391 | function useRouteId() {
|
| 7392 | return useCurrentRouteId("useRouteId" );
|
| 7393 | }
|
| 7394 | function useNavigation() {
|
| 7395 | let state = useDataRouterState("useNavigation" );
|
| 7396 | return state.navigation;
|
| 7397 | }
|
| 7398 | function useRevalidator() {
|
| 7399 | let dataRouterContext = useDataRouterContext("useRevalidator" );
|
| 7400 | let state = useDataRouterState("useRevalidator" );
|
| 7401 | let revalidate = React3.useCallback(async () => {
|
| 7402 | await dataRouterContext.router.revalidate();
|
| 7403 | }, [dataRouterContext.router]);
|
| 7404 | return React3.useMemo(
|
| 7405 | () => ({ revalidate, state: state.revalidation }),
|
| 7406 | [revalidate, state.revalidation]
|
| 7407 | );
|
| 7408 | }
|
| 7409 | function useMatches() {
|
| 7410 | let { matches, loaderData } = useDataRouterState(
|
| 7411 | "useMatches"
|
| 7412 | );
|
| 7413 | return React3.useMemo(
|
| 7414 | () => matches.map((m) => convertRouteMatchToUiMatch(m, loaderData)),
|
| 7415 | [matches, loaderData]
|
| 7416 | );
|
| 7417 | }
|
| 7418 | function useLoaderData() {
|
| 7419 | let state = useDataRouterState("useLoaderData" );
|
| 7420 | let routeId = useCurrentRouteId("useLoaderData" );
|
| 7421 | return state.loaderData[routeId];
|
| 7422 | }
|
| 7423 | function useRouteLoaderData(routeId) {
|
| 7424 | let state = useDataRouterState("useRouteLoaderData" );
|
| 7425 | return state.loaderData[routeId];
|
| 7426 | }
|
| 7427 | function useActionData() {
|
| 7428 | let state = useDataRouterState("useActionData" );
|
| 7429 | let routeId = useCurrentRouteId("useLoaderData" );
|
| 7430 | return state.actionData ? state.actionData[routeId] : void 0;
|
| 7431 | }
|
| 7432 | function useRouteError() {
|
| 7433 | let error = React3.useContext(RouteErrorContext);
|
| 7434 | let state = useDataRouterState("useRouteError" );
|
| 7435 | let routeId = useCurrentRouteId("useRouteError" );
|
| 7436 | if (error !== void 0) {
|
| 7437 | return error;
|
| 7438 | }
|
| 7439 | return _optionalChain([state, 'access', _97 => _97.errors, 'optionalAccess', _98 => _98[routeId]]);
|
| 7440 | }
|
| 7441 | function useAsyncValue() {
|
| 7442 | let value = React3.useContext(AwaitContext);
|
| 7443 | return _optionalChain([value, 'optionalAccess', _99 => _99._data]);
|
| 7444 | }
|
| 7445 | function useAsyncError() {
|
| 7446 | let value = React3.useContext(AwaitContext);
|
| 7447 | return _optionalChain([value, 'optionalAccess', _100 => _100._error]);
|
| 7448 | }
|
| 7449 | var blockerId = 0;
|
| 7450 | function useBlocker(shouldBlock) {
|
| 7451 | let { router, basename } = useDataRouterContext("useBlocker" );
|
| 7452 | let state = useDataRouterState("useBlocker" );
|
| 7453 | let [blockerKey, setBlockerKey] = React3.useState("");
|
| 7454 | let blockerFunction = React3.useCallback(
|
| 7455 | (arg) => {
|
| 7456 | if (typeof shouldBlock !== "function") {
|
| 7457 | return !!shouldBlock;
|
| 7458 | }
|
| 7459 | if (basename === "/") {
|
| 7460 | return shouldBlock(arg);
|
| 7461 | }
|
| 7462 | let { currentLocation, nextLocation, historyAction } = arg;
|
| 7463 | return shouldBlock({
|
| 7464 | currentLocation: {
|
| 7465 | ...currentLocation,
|
| 7466 | pathname: stripBasename(currentLocation.pathname, basename) || currentLocation.pathname
|
| 7467 | },
|
| 7468 | nextLocation: {
|
| 7469 | ...nextLocation,
|
| 7470 | pathname: stripBasename(nextLocation.pathname, basename) || nextLocation.pathname
|
| 7471 | },
|
| 7472 | historyAction
|
| 7473 | });
|
| 7474 | },
|
| 7475 | [basename, shouldBlock]
|
| 7476 | );
|
| 7477 | React3.useEffect(() => {
|
| 7478 | let key = String(++blockerId);
|
| 7479 | setBlockerKey(key);
|
| 7480 | return () => router.deleteBlocker(key);
|
| 7481 | }, [router]);
|
| 7482 | React3.useEffect(() => {
|
| 7483 | if (blockerKey !== "") {
|
| 7484 | router.getBlocker(blockerKey, blockerFunction);
|
| 7485 | }
|
| 7486 | }, [router, blockerKey, blockerFunction]);
|
| 7487 | return blockerKey && state.blockers.has(blockerKey) ? state.blockers.get(blockerKey) : IDLE_BLOCKER;
|
| 7488 | }
|
| 7489 | function useNavigateStable() {
|
| 7490 | let { router } = useDataRouterContext("useNavigate" );
|
| 7491 | let id = useCurrentRouteId("useNavigate" );
|
| 7492 | let activeRef = React3.useRef(false);
|
| 7493 | useIsomorphicLayoutEffect(() => {
|
| 7494 | activeRef.current = true;
|
| 7495 | });
|
| 7496 | let navigate = React3.useCallback(
|
| 7497 | async (to, options = {}) => {
|
| 7498 | warning(activeRef.current, navigateEffectWarning);
|
| 7499 | if (!activeRef.current) return;
|
| 7500 | if (typeof to === "number") {
|
| 7501 | await router.navigate(to);
|
| 7502 | } else {
|
| 7503 | await router.navigate(to, { fromRouteId: id, ...options });
|
| 7504 | }
|
| 7505 | },
|
| 7506 | [router, id]
|
| 7507 | );
|
| 7508 | return navigate;
|
| 7509 | }
|
| 7510 | var alreadyWarned = {};
|
| 7511 | function warningOnce(key, cond, message) {
|
| 7512 | if (!cond && !alreadyWarned[key]) {
|
| 7513 | alreadyWarned[key] = true;
|
| 7514 | warning(false, message);
|
| 7515 | }
|
| 7516 | }
|
| 7517 | function useRoute(...args) {
|
| 7518 | const currentRouteId = useCurrentRouteId(
|
| 7519 | "useRoute"
|
| 7520 | );
|
| 7521 | const id = _nullishCoalesce(args[0], () => ( currentRouteId));
|
| 7522 | const state = useDataRouterState("useRoute" );
|
| 7523 | const route = state.matches.find(({ route: route2 }) => route2.id === id);
|
| 7524 | if (route === void 0) return void 0;
|
| 7525 | return {
|
| 7526 | handle: route.route.handle,
|
| 7527 | loaderData: state.loaderData[id],
|
| 7528 | actionData: _optionalChain([state, 'access', _101 => _101.actionData, 'optionalAccess', _102 => _102[id]])
|
| 7529 | };
|
| 7530 | }
|
| 7531 |
|
| 7532 |
|
| 7533 |
|
| 7534 |
|
| 7535 |
|
| 7536 |
|
| 7537 |
|
| 7538 |
|
| 7539 | async function loadRouteModule(route, routeModulesCache) {
|
| 7540 | if (route.id in routeModulesCache) {
|
| 7541 | return routeModulesCache[route.id];
|
| 7542 | }
|
| 7543 | try {
|
| 7544 | let routeModule = await Promise.resolve().then(() => _interopRequireWildcard(require(
|
| 7545 |
|
| 7546 |
|
| 7547 | route.module
|
| 7548 | )));
|
| 7549 | routeModulesCache[route.id] = routeModule;
|
| 7550 | return routeModule;
|
| 7551 | } catch (error) {
|
| 7552 | console.error(
|
| 7553 | `Error loading route module \`${route.module}\`, reloading page...`
|
| 7554 | );
|
| 7555 | console.error(error);
|
| 7556 | if (window.__reactRouterContext && window.__reactRouterContext.isSpaMode &&
|
| 7557 | void 0) {
|
| 7558 | throw error;
|
| 7559 | }
|
| 7560 | window.location.reload();
|
| 7561 | return new Promise(() => {
|
| 7562 | });
|
| 7563 | }
|
| 7564 | }
|
| 7565 |
|
| 7566 |
|
| 7567 | function getKeyedLinksForMatches(matches, routeModules, manifest) {
|
| 7568 | let descriptors = matches.map((match) => {
|
| 7569 | let module = routeModules[match.route.id];
|
| 7570 | let route = manifest.routes[match.route.id];
|
| 7571 | return [
|
| 7572 | route && route.css ? route.css.map((href) => ({ rel: "stylesheet", href })) : [],
|
| 7573 | _optionalChain([module, 'optionalAccess', _103 => _103.links, 'optionalCall', _104 => _104()]) || []
|
| 7574 | ];
|
| 7575 | }).flat(2);
|
| 7576 | let preloads = getModuleLinkHrefs(matches, manifest);
|
| 7577 | return dedupeLinkDescriptors(descriptors, preloads);
|
| 7578 | }
|
| 7579 | function getRouteCssDescriptors(route) {
|
| 7580 | if (!route.css) return [];
|
| 7581 | return route.css.map((href) => ({ rel: "stylesheet", href }));
|
| 7582 | }
|
| 7583 | async function prefetchRouteCss(route) {
|
| 7584 | if (!route.css) return;
|
| 7585 | let descriptors = getRouteCssDescriptors(route);
|
| 7586 | await Promise.all(descriptors.map(prefetchStyleLink));
|
| 7587 | }
|
| 7588 | async function prefetchStyleLinks(route, routeModule) {
|
| 7589 | if (!route.css && !routeModule.links || !isPreloadSupported()) return;
|
| 7590 | let descriptors = [];
|
| 7591 | if (route.css) {
|
| 7592 | descriptors.push(...getRouteCssDescriptors(route));
|
| 7593 | }
|
| 7594 | if (routeModule.links) {
|
| 7595 | descriptors.push(...routeModule.links());
|
| 7596 | }
|
| 7597 | if (descriptors.length === 0) return;
|
| 7598 | let styleLinks = [];
|
| 7599 | for (let descriptor of descriptors) {
|
| 7600 | if (!isPageLinkDescriptor(descriptor) && descriptor.rel === "stylesheet") {
|
| 7601 | styleLinks.push({
|
| 7602 | ...descriptor,
|
| 7603 | rel: "preload",
|
| 7604 | as: "style"
|
| 7605 | });
|
| 7606 | }
|
| 7607 | }
|
| 7608 | await Promise.all(styleLinks.map(prefetchStyleLink));
|
| 7609 | }
|
| 7610 | async function prefetchStyleLink(descriptor) {
|
| 7611 | return new Promise((resolve) => {
|
| 7612 | if (descriptor.media && !window.matchMedia(descriptor.media).matches || document.querySelector(
|
| 7613 | `link[rel="stylesheet"][href="${descriptor.href}"]`
|
| 7614 | )) {
|
| 7615 | return resolve();
|
| 7616 | }
|
| 7617 | let link = document.createElement("link");
|
| 7618 | Object.assign(link, descriptor);
|
| 7619 | function removeLink() {
|
| 7620 | if (document.head.contains(link)) {
|
| 7621 | document.head.removeChild(link);
|
| 7622 | }
|
| 7623 | }
|
| 7624 | link.onload = () => {
|
| 7625 | removeLink();
|
| 7626 | resolve();
|
| 7627 | };
|
| 7628 | link.onerror = () => {
|
| 7629 | removeLink();
|
| 7630 | resolve();
|
| 7631 | };
|
| 7632 | document.head.appendChild(link);
|
| 7633 | });
|
| 7634 | }
|
| 7635 | function isPageLinkDescriptor(object) {
|
| 7636 | return object != null && typeof object.page === "string";
|
| 7637 | }
|
| 7638 | function isHtmlLinkDescriptor(object) {
|
| 7639 | if (object == null) {
|
| 7640 | return false;
|
| 7641 | }
|
| 7642 | if (object.href == null) {
|
| 7643 | return object.rel === "preload" && typeof object.imageSrcSet === "string" && typeof object.imageSizes === "string";
|
| 7644 | }
|
| 7645 | return typeof object.rel === "string" && typeof object.href === "string";
|
| 7646 | }
|
| 7647 | async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
|
| 7648 | let links = await Promise.all(
|
| 7649 | matches.map(async (match) => {
|
| 7650 | let route = manifest.routes[match.route.id];
|
| 7651 | if (route) {
|
| 7652 | let mod = await loadRouteModule(route, routeModules);
|
| 7653 | return mod.links ? mod.links() : [];
|
| 7654 | }
|
| 7655 | return [];
|
| 7656 | })
|
| 7657 | );
|
| 7658 | return dedupeLinkDescriptors(
|
| 7659 | links.flat(1).filter(isHtmlLinkDescriptor).filter((link) => link.rel === "stylesheet" || link.rel === "preload").map(
|
| 7660 | (link) => link.rel === "stylesheet" ? { ...link, rel: "prefetch", as: "style" } : { ...link, rel: "prefetch" }
|
| 7661 | )
|
| 7662 | );
|
| 7663 | }
|
| 7664 | function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
|
| 7665 | let isNew = (match, index) => {
|
| 7666 | if (!currentMatches[index]) return true;
|
| 7667 | return match.route.id !== currentMatches[index].route.id;
|
| 7668 | };
|
| 7669 | let matchPathChanged = (match, index) => {
|
| 7670 | return (
|
| 7671 |
|
| 7672 | currentMatches[index].pathname !== match.pathname ||
|
| 7673 |
|
| 7674 | _optionalChain([currentMatches, 'access', _105 => _105[index], 'access', _106 => _106.route, 'access', _107 => _107.path, 'optionalAccess', _108 => _108.endsWith, 'call', _109 => _109("*")]) && currentMatches[index].params["*"] !== match.params["*"]
|
| 7675 | );
|
| 7676 | };
|
| 7677 | if (mode === "assets") {
|
| 7678 | return nextMatches.filter(
|
| 7679 | (match, index) => isNew(match, index) || matchPathChanged(match, index)
|
| 7680 | );
|
| 7681 | }
|
| 7682 | if (mode === "data") {
|
| 7683 | return nextMatches.filter((match, index) => {
|
| 7684 | let manifestRoute = manifest.routes[match.route.id];
|
| 7685 | if (!manifestRoute || !manifestRoute.hasLoader) {
|
| 7686 | return false;
|
| 7687 | }
|
| 7688 | if (isNew(match, index) || matchPathChanged(match, index)) {
|
| 7689 | return true;
|
| 7690 | }
|
| 7691 | if (match.route.shouldRevalidate) {
|
| 7692 | let routeChoice = match.route.shouldRevalidate({
|
| 7693 | currentUrl: new URL(
|
| 7694 | location.pathname + location.search + location.hash,
|
| 7695 | window.origin
|
| 7696 | ),
|
| 7697 | currentParams: _optionalChain([currentMatches, 'access', _110 => _110[0], 'optionalAccess', _111 => _111.params]) || {},
|
| 7698 | nextUrl: new URL(page, window.origin),
|
| 7699 | nextParams: match.params,
|
| 7700 | defaultShouldRevalidate: true
|
| 7701 | });
|
| 7702 | if (typeof routeChoice === "boolean") {
|
| 7703 | return routeChoice;
|
| 7704 | }
|
| 7705 | }
|
| 7706 | return true;
|
| 7707 | });
|
| 7708 | }
|
| 7709 | return [];
|
| 7710 | }
|
| 7711 | function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
|
| 7712 | return dedupeHrefs(
|
| 7713 | matches.map((match) => {
|
| 7714 | let route = manifest.routes[match.route.id];
|
| 7715 | if (!route) return [];
|
| 7716 | let hrefs = [route.module];
|
| 7717 | if (route.clientActionModule) {
|
| 7718 | hrefs = hrefs.concat(route.clientActionModule);
|
| 7719 | }
|
| 7720 | if (route.clientLoaderModule) {
|
| 7721 | hrefs = hrefs.concat(route.clientLoaderModule);
|
| 7722 | }
|
| 7723 | if (includeHydrateFallback && route.hydrateFallbackModule) {
|
| 7724 | hrefs = hrefs.concat(route.hydrateFallbackModule);
|
| 7725 | }
|
| 7726 | if (route.imports) {
|
| 7727 | hrefs = hrefs.concat(route.imports);
|
| 7728 | }
|
| 7729 | return hrefs;
|
| 7730 | }).flat(1)
|
| 7731 | );
|
| 7732 | }
|
| 7733 | function dedupeHrefs(hrefs) {
|
| 7734 | return [...new Set(hrefs)];
|
| 7735 | }
|
| 7736 | function sortKeys(obj) {
|
| 7737 | let sorted = {};
|
| 7738 | let keys = Object.keys(obj).sort();
|
| 7739 | for (let key of keys) {
|
| 7740 | sorted[key] = obj[key];
|
| 7741 | }
|
| 7742 | return sorted;
|
| 7743 | }
|
| 7744 | function dedupeLinkDescriptors(descriptors, preloads) {
|
| 7745 | let set = /* @__PURE__ */ new Set();
|
| 7746 | let preloadsSet = new Set(preloads);
|
| 7747 | return descriptors.reduce((deduped, descriptor) => {
|
| 7748 | let alreadyModulePreload = preloads && !isPageLinkDescriptor(descriptor) && descriptor.as === "script" && descriptor.href && preloadsSet.has(descriptor.href);
|
| 7749 | if (alreadyModulePreload) {
|
| 7750 | return deduped;
|
| 7751 | }
|
| 7752 | let key = JSON.stringify(sortKeys(descriptor));
|
| 7753 | if (!set.has(key)) {
|
| 7754 | set.add(key);
|
| 7755 | deduped.push({ key, link: descriptor });
|
| 7756 | }
|
| 7757 | return deduped;
|
| 7758 | }, []);
|
| 7759 | }
|
| 7760 | var _isPreloadSupported;
|
| 7761 | function isPreloadSupported() {
|
| 7762 | if (_isPreloadSupported !== void 0) {
|
| 7763 | return _isPreloadSupported;
|
| 7764 | }
|
| 7765 | let el = document.createElement("link");
|
| 7766 | _isPreloadSupported = el.relList.supports("preload");
|
| 7767 | el = null;
|
| 7768 | return _isPreloadSupported;
|
| 7769 | }
|
| 7770 |
|
| 7771 |
|
| 7772 | var alreadyWarned2 = {};
|
| 7773 | function warnOnce(condition, message) {
|
| 7774 | if (!condition && !alreadyWarned2[message]) {
|
| 7775 | alreadyWarned2[message] = true;
|
| 7776 | console.warn(message);
|
| 7777 | }
|
| 7778 | }
|
| 7779 |
|
| 7780 |
|
| 7781 |
|
| 7782 |
|
| 7783 |
|
| 7784 |
|
| 7785 |
|
| 7786 |
|
| 7787 |
|
| 7788 | function RemixRootDefaultHydrateFallback() {
|
| 7789 | return React4.createElement(BoundaryShell, { title: "Loading...", renderScripts: true }, ENABLE_DEV_WARNINGS ? React4.createElement(
|
| 7790 | "script",
|
| 7791 | {
|
| 7792 | dangerouslySetInnerHTML: {
|
| 7793 | __html: `
|
| 7794 | console.log(
|
| 7795 | "\u{1F4BF} Hey developer \u{1F44B}. You can provide a way better UX than this " +
|
| 7796 | "when your app is loading JS modules and/or running \`clientLoader\` " +
|
| 7797 | "functions. Check out https://reactrouter.com/start/framework/route-module#hydratefallback " +
|
| 7798 | "for more information."
|
| 7799 | );
|
| 7800 | `
|
| 7801 | }
|
| 7802 | }
|
| 7803 | ) : null);
|
| 7804 | }
|
| 7805 |
|
| 7806 |
|
| 7807 | function groupRoutesByParentId(manifest) {
|
| 7808 | let routes = {};
|
| 7809 | Object.values(manifest).forEach((route) => {
|
| 7810 | if (route) {
|
| 7811 | let parentId = route.parentId || "";
|
| 7812 | if (!routes[parentId]) {
|
| 7813 | routes[parentId] = [];
|
| 7814 | }
|
| 7815 | routes[parentId].push(route);
|
| 7816 | }
|
| 7817 | });
|
| 7818 | return routes;
|
| 7819 | }
|
| 7820 | function getRouteComponents(route, routeModule, isSpaMode) {
|
| 7821 | let Component4 = getRouteModuleComponent(routeModule);
|
| 7822 | let HydrateFallback = routeModule.HydrateFallback && (!isSpaMode || route.id === "root") ? routeModule.HydrateFallback : route.id === "root" ? RemixRootDefaultHydrateFallback : void 0;
|
| 7823 | let ErrorBoundary = routeModule.ErrorBoundary ? routeModule.ErrorBoundary : route.id === "root" ? () => React5.createElement(RemixRootDefaultErrorBoundary, { error: useRouteError() }) : void 0;
|
| 7824 | if (route.id === "root" && routeModule.Layout) {
|
| 7825 | return {
|
| 7826 | ...Component4 ? {
|
| 7827 | element: React5.createElement(routeModule.Layout, null, React5.createElement(Component4, null))
|
| 7828 | } : { Component: Component4 },
|
| 7829 | ...ErrorBoundary ? {
|
| 7830 | errorElement: React5.createElement(routeModule.Layout, null, React5.createElement(ErrorBoundary, null))
|
| 7831 | } : { ErrorBoundary },
|
| 7832 | ...HydrateFallback ? {
|
| 7833 | hydrateFallbackElement: React5.createElement(routeModule.Layout, null, React5.createElement(HydrateFallback, null))
|
| 7834 | } : { HydrateFallback }
|
| 7835 | };
|
| 7836 | }
|
| 7837 | return { Component: Component4, ErrorBoundary, HydrateFallback };
|
| 7838 | }
|
| 7839 | function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId = "", routesByParentId = groupRoutesByParentId(manifest), spaModeLazyPromise = Promise.resolve({ Component: () => null })) {
|
| 7840 | return (routesByParentId[parentId] || []).map((route) => {
|
| 7841 | let routeModule = routeModules[route.id];
|
| 7842 | invariant2(
|
| 7843 | routeModule,
|
| 7844 | "No `routeModule` available to create server routes"
|
| 7845 | );
|
| 7846 | let dataRoute = {
|
| 7847 | ...getRouteComponents(route, routeModule, isSpaMode),
|
| 7848 | caseSensitive: route.caseSensitive,
|
| 7849 | id: route.id,
|
| 7850 | index: route.index,
|
| 7851 | path: route.path,
|
| 7852 | handle: routeModule.handle,
|
| 7853 |
|
| 7854 |
|
| 7855 |
|
| 7856 |
|
| 7857 | lazy: isSpaMode ? () => spaModeLazyPromise : void 0,
|
| 7858 |
|
| 7859 |
|
| 7860 |
|
| 7861 |
|
| 7862 | loader: route.hasLoader || route.hasClientLoader ? () => null : void 0
|
| 7863 |
|
| 7864 |
|
| 7865 | };
|
| 7866 | let children = createServerRoutes(
|
| 7867 | manifest,
|
| 7868 | routeModules,
|
| 7869 | future,
|
| 7870 | isSpaMode,
|
| 7871 | route.id,
|
| 7872 | routesByParentId,
|
| 7873 | spaModeLazyPromise
|
| 7874 | );
|
| 7875 | if (children.length > 0) dataRoute.children = children;
|
| 7876 | return dataRoute;
|
| 7877 | });
|
| 7878 | }
|
| 7879 | function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation, manifest, routeModulesCache, initialState, ssr, isSpaMode) {
|
| 7880 | return createClientRoutes(
|
| 7881 | manifest,
|
| 7882 | routeModulesCache,
|
| 7883 | initialState,
|
| 7884 | ssr,
|
| 7885 | isSpaMode,
|
| 7886 | "",
|
| 7887 | groupRoutesByParentId(manifest),
|
| 7888 | needsRevalidation
|
| 7889 | );
|
| 7890 | }
|
| 7891 | function preventInvalidServerHandlerCall(type, route) {
|
| 7892 | if (type === "loader" && !route.hasLoader || type === "action" && !route.hasAction) {
|
| 7893 | let fn = type === "action" ? "serverAction()" : "serverLoader()";
|
| 7894 | let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${route.id}")`;
|
| 7895 | console.error(msg);
|
| 7896 | throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
|
| 7897 | }
|
| 7898 | }
|
| 7899 | function noActionDefinedError(type, routeId) {
|
| 7900 | let article = type === "clientAction" ? "a" : "an";
|
| 7901 | let msg = `Route "${routeId}" does not have ${article} ${type}, but you are trying to submit to it. To fix this, please add ${article} \`${type}\` function to the route`;
|
| 7902 | console.error(msg);
|
| 7903 | throw new ErrorResponseImpl(405, "Method Not Allowed", new Error(msg), true);
|
| 7904 | }
|
| 7905 | function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSpaMode, parentId = "", routesByParentId = groupRoutesByParentId(manifest), needsRevalidation) {
|
| 7906 | return (routesByParentId[parentId] || []).map((route) => {
|
| 7907 | let routeModule = routeModulesCache[route.id];
|
| 7908 | function fetchServerHandler(singleFetch) {
|
| 7909 | invariant2(
|
| 7910 | typeof singleFetch === "function",
|
| 7911 | "No single fetch function available for route handler"
|
| 7912 | );
|
| 7913 | return singleFetch();
|
| 7914 | }
|
| 7915 | function fetchServerLoader(singleFetch) {
|
| 7916 | if (!route.hasLoader) return Promise.resolve(null);
|
| 7917 | return fetchServerHandler(singleFetch);
|
| 7918 | }
|
| 7919 | function fetchServerAction(singleFetch) {
|
| 7920 | if (!route.hasAction) {
|
| 7921 | throw noActionDefinedError("action", route.id);
|
| 7922 | }
|
| 7923 | return fetchServerHandler(singleFetch);
|
| 7924 | }
|
| 7925 | function prefetchModule(modulePath) {
|
| 7926 | Promise.resolve().then(() => _interopRequireWildcard(require(
|
| 7927 |
|
| 7928 |
|
| 7929 | modulePath
|
| 7930 | )));
|
| 7931 | }
|
| 7932 | function prefetchRouteModuleChunks(route2) {
|
| 7933 | if (route2.clientActionModule) {
|
| 7934 | prefetchModule(route2.clientActionModule);
|
| 7935 | }
|
| 7936 | if (route2.clientLoaderModule) {
|
| 7937 | prefetchModule(route2.clientLoaderModule);
|
| 7938 | }
|
| 7939 | }
|
| 7940 | async function prefetchStylesAndCallHandler(handler) {
|
| 7941 | let cachedModule = routeModulesCache[route.id];
|
| 7942 | let linkPrefetchPromise = cachedModule ? prefetchStyleLinks(route, cachedModule) : Promise.resolve();
|
| 7943 | try {
|
| 7944 | return handler();
|
| 7945 | } finally {
|
| 7946 | await linkPrefetchPromise;
|
| 7947 | }
|
| 7948 | }
|
| 7949 | let dataRoute = {
|
| 7950 | id: route.id,
|
| 7951 | index: route.index,
|
| 7952 | path: route.path
|
| 7953 | };
|
| 7954 | if (routeModule) {
|
| 7955 | Object.assign(dataRoute, {
|
| 7956 | ...dataRoute,
|
| 7957 | ...getRouteComponents(route, routeModule, isSpaMode),
|
| 7958 | middleware: routeModule.clientMiddleware,
|
| 7959 | handle: routeModule.handle,
|
| 7960 | shouldRevalidate: getShouldRevalidateFunction(
|
| 7961 | dataRoute.path,
|
| 7962 | routeModule,
|
| 7963 | route,
|
| 7964 | ssr,
|
| 7965 | needsRevalidation
|
| 7966 | )
|
| 7967 | });
|
| 7968 | let hasInitialData = initialState && initialState.loaderData && route.id in initialState.loaderData;
|
| 7969 | let initialData = hasInitialData ? _optionalChain([initialState, 'optionalAccess', _112 => _112.loaderData, 'optionalAccess', _113 => _113[route.id]]) : void 0;
|
| 7970 | let hasInitialError = initialState && initialState.errors && route.id in initialState.errors;
|
| 7971 | let initialError = hasInitialError ? _optionalChain([initialState, 'optionalAccess', _114 => _114.errors, 'optionalAccess', _115 => _115[route.id]]) : void 0;
|
| 7972 | let isHydrationRequest = needsRevalidation == null && (_optionalChain([routeModule, 'access', _116 => _116.clientLoader, 'optionalAccess', _117 => _117.hydrate]) === true || !route.hasLoader);
|
| 7973 | dataRoute.loader = async ({
|
| 7974 | request,
|
| 7975 | params,
|
| 7976 | context,
|
| 7977 | unstable_pattern,
|
| 7978 | unstable_url
|
| 7979 | }, singleFetch) => {
|
| 7980 | try {
|
| 7981 | let result = await prefetchStylesAndCallHandler(async () => {
|
| 7982 | invariant2(
|
| 7983 | routeModule,
|
| 7984 | "No `routeModule` available for critical-route loader"
|
| 7985 | );
|
| 7986 | if (!routeModule.clientLoader) {
|
| 7987 | return fetchServerLoader(singleFetch);
|
| 7988 | }
|
| 7989 | return routeModule.clientLoader({
|
| 7990 | request,
|
| 7991 | params,
|
| 7992 | context,
|
| 7993 | unstable_pattern,
|
| 7994 | unstable_url,
|
| 7995 | async serverLoader() {
|
| 7996 | preventInvalidServerHandlerCall("loader", route);
|
| 7997 | if (isHydrationRequest) {
|
| 7998 | if (hasInitialData) {
|
| 7999 | return initialData;
|
| 8000 | }
|
| 8001 | if (hasInitialError) {
|
| 8002 | throw initialError;
|
| 8003 | }
|
| 8004 | }
|
| 8005 | return fetchServerLoader(singleFetch);
|
| 8006 | }
|
| 8007 | });
|
| 8008 | });
|
| 8009 | return result;
|
| 8010 | } finally {
|
| 8011 | isHydrationRequest = false;
|
| 8012 | }
|
| 8013 | };
|
| 8014 | dataRoute.loader.hydrate = shouldHydrateRouteLoader(
|
| 8015 | route.id,
|
| 8016 | routeModule.clientLoader,
|
| 8017 | route.hasLoader,
|
| 8018 | isSpaMode
|
| 8019 | );
|
| 8020 | dataRoute.action = ({
|
| 8021 | request,
|
| 8022 | params,
|
| 8023 | context,
|
| 8024 | unstable_pattern,
|
| 8025 | unstable_url
|
| 8026 | }, singleFetch) => {
|
| 8027 | return prefetchStylesAndCallHandler(async () => {
|
| 8028 | invariant2(
|
| 8029 | routeModule,
|
| 8030 | "No `routeModule` available for critical-route action"
|
| 8031 | );
|
| 8032 | if (!routeModule.clientAction) {
|
| 8033 | if (isSpaMode) {
|
| 8034 | throw noActionDefinedError("clientAction", route.id);
|
| 8035 | }
|
| 8036 | return fetchServerAction(singleFetch);
|
| 8037 | }
|
| 8038 | return routeModule.clientAction({
|
| 8039 | request,
|
| 8040 | params,
|
| 8041 | context,
|
| 8042 | unstable_pattern,
|
| 8043 | unstable_url,
|
| 8044 | async serverAction() {
|
| 8045 | preventInvalidServerHandlerCall("action", route);
|
| 8046 | return fetchServerAction(singleFetch);
|
| 8047 | }
|
| 8048 | });
|
| 8049 | });
|
| 8050 | };
|
| 8051 | } else {
|
| 8052 | if (!route.hasClientLoader) {
|
| 8053 | dataRoute.loader = (_, singleFetch) => prefetchStylesAndCallHandler(() => {
|
| 8054 | return fetchServerLoader(singleFetch);
|
| 8055 | });
|
| 8056 | }
|
| 8057 | if (!route.hasClientAction) {
|
| 8058 | dataRoute.action = (_, singleFetch) => prefetchStylesAndCallHandler(() => {
|
| 8059 | if (isSpaMode) {
|
| 8060 | throw noActionDefinedError("clientAction", route.id);
|
| 8061 | }
|
| 8062 | return fetchServerAction(singleFetch);
|
| 8063 | });
|
| 8064 | }
|
| 8065 | let lazyRoutePromise;
|
| 8066 | async function getLazyRoute() {
|
| 8067 | if (lazyRoutePromise) {
|
| 8068 | return await lazyRoutePromise;
|
| 8069 | }
|
| 8070 | lazyRoutePromise = (async () => {
|
| 8071 | if (route.clientLoaderModule || route.clientActionModule) {
|
| 8072 | await new Promise((resolve) => setTimeout(resolve, 0));
|
| 8073 | }
|
| 8074 | let routeModulePromise = loadRouteModuleWithBlockingLinks(
|
| 8075 | route,
|
| 8076 | routeModulesCache
|
| 8077 | );
|
| 8078 | prefetchRouteModuleChunks(route);
|
| 8079 | return await routeModulePromise;
|
| 8080 | })();
|
| 8081 | return await lazyRoutePromise;
|
| 8082 | }
|
| 8083 | dataRoute.lazy = {
|
| 8084 | loader: route.hasClientLoader ? async () => {
|
| 8085 | let { clientLoader } = route.clientLoaderModule ? await Promise.resolve().then(() => _interopRequireWildcard(require(
|
| 8086 |
|
| 8087 |
|
| 8088 | route.clientLoaderModule
|
| 8089 | ))) : await getLazyRoute();
|
| 8090 | invariant2(clientLoader, "No `clientLoader` export found");
|
| 8091 | return (args, singleFetch) => clientLoader({
|
| 8092 | ...args,
|
| 8093 | async serverLoader() {
|
| 8094 | preventInvalidServerHandlerCall("loader", route);
|
| 8095 | return fetchServerLoader(singleFetch);
|
| 8096 | }
|
| 8097 | });
|
| 8098 | } : void 0,
|
| 8099 | action: route.hasClientAction ? async () => {
|
| 8100 | let clientActionPromise = route.clientActionModule ? Promise.resolve().then(() => _interopRequireWildcard(require(
|
| 8101 |
|
| 8102 |
|
| 8103 | route.clientActionModule
|
| 8104 | ))) : getLazyRoute();
|
| 8105 | prefetchRouteModuleChunks(route);
|
| 8106 | let { clientAction } = await clientActionPromise;
|
| 8107 | invariant2(clientAction, "No `clientAction` export found");
|
| 8108 | return (args, singleFetch) => clientAction({
|
| 8109 | ...args,
|
| 8110 | async serverAction() {
|
| 8111 | preventInvalidServerHandlerCall("action", route);
|
| 8112 | return fetchServerAction(singleFetch);
|
| 8113 | }
|
| 8114 | });
|
| 8115 | } : void 0,
|
| 8116 | middleware: route.hasClientMiddleware ? async () => {
|
| 8117 | let { clientMiddleware } = route.clientMiddlewareModule ? await Promise.resolve().then(() => _interopRequireWildcard(require(
|
| 8118 |
|
| 8119 |
|
| 8120 | route.clientMiddlewareModule
|
| 8121 | ))) : await getLazyRoute();
|
| 8122 | invariant2(clientMiddleware, "No `clientMiddleware` export found");
|
| 8123 | return clientMiddleware;
|
| 8124 | } : void 0,
|
| 8125 | shouldRevalidate: async () => {
|
| 8126 | let lazyRoute = await getLazyRoute();
|
| 8127 | return getShouldRevalidateFunction(
|
| 8128 | dataRoute.path,
|
| 8129 | lazyRoute,
|
| 8130 | route,
|
| 8131 | ssr,
|
| 8132 | needsRevalidation
|
| 8133 | );
|
| 8134 | },
|
| 8135 | handle: async () => (await getLazyRoute()).handle,
|
| 8136 |
|
| 8137 |
|
| 8138 | Component: async () => (await getLazyRoute()).Component,
|
| 8139 | ErrorBoundary: route.hasErrorBoundary ? async () => (await getLazyRoute()).ErrorBoundary : void 0
|
| 8140 | };
|
| 8141 | }
|
| 8142 | let children = createClientRoutes(
|
| 8143 | manifest,
|
| 8144 | routeModulesCache,
|
| 8145 | initialState,
|
| 8146 | ssr,
|
| 8147 | isSpaMode,
|
| 8148 | route.id,
|
| 8149 | routesByParentId,
|
| 8150 | needsRevalidation
|
| 8151 | );
|
| 8152 | if (children.length > 0) dataRoute.children = children;
|
| 8153 | return dataRoute;
|
| 8154 | });
|
| 8155 | }
|
| 8156 | function getShouldRevalidateFunction(path, route, manifestRoute, ssr, needsRevalidation) {
|
| 8157 | if (needsRevalidation) {
|
| 8158 | return wrapShouldRevalidateForHdr(
|
| 8159 | manifestRoute.id,
|
| 8160 | route.shouldRevalidate,
|
| 8161 | needsRevalidation
|
| 8162 | );
|
| 8163 | }
|
| 8164 | if (!ssr && manifestRoute.hasLoader && !manifestRoute.hasClientLoader) {
|
| 8165 | let myParams = path ? compilePath(path)[1].map((p) => p.paramName) : [];
|
| 8166 | const didParamsChange = (opts) => myParams.some((p) => opts.currentParams[p] !== opts.nextParams[p]);
|
| 8167 | if (route.shouldRevalidate) {
|
| 8168 | let fn = route.shouldRevalidate;
|
| 8169 | return (opts) => fn({
|
| 8170 | ...opts,
|
| 8171 | defaultShouldRevalidate: didParamsChange(opts)
|
| 8172 | });
|
| 8173 | } else {
|
| 8174 | return (opts) => didParamsChange(opts);
|
| 8175 | }
|
| 8176 | }
|
| 8177 | return route.shouldRevalidate;
|
| 8178 | }
|
| 8179 | function wrapShouldRevalidateForHdr(routeId, routeShouldRevalidate, needsRevalidation) {
|
| 8180 | let handledRevalidation = false;
|
| 8181 | return (arg) => {
|
| 8182 | if (!handledRevalidation) {
|
| 8183 | handledRevalidation = true;
|
| 8184 | return needsRevalidation.has(routeId);
|
| 8185 | }
|
| 8186 | return routeShouldRevalidate ? routeShouldRevalidate(arg) : arg.defaultShouldRevalidate;
|
| 8187 | };
|
| 8188 | }
|
| 8189 | async function loadRouteModuleWithBlockingLinks(route, routeModules) {
|
| 8190 | let routeModulePromise = loadRouteModule(route, routeModules);
|
| 8191 | let prefetchRouteCssPromise = prefetchRouteCss(route);
|
| 8192 | let routeModule = await routeModulePromise;
|
| 8193 | await Promise.all([
|
| 8194 | prefetchRouteCssPromise,
|
| 8195 | prefetchStyleLinks(route, routeModule)
|
| 8196 | ]);
|
| 8197 | return {
|
| 8198 | Component: getRouteModuleComponent(routeModule),
|
| 8199 | ErrorBoundary: routeModule.ErrorBoundary,
|
| 8200 | clientMiddleware: routeModule.clientMiddleware,
|
| 8201 | clientAction: routeModule.clientAction,
|
| 8202 | clientLoader: routeModule.clientLoader,
|
| 8203 | handle: routeModule.handle,
|
| 8204 | links: routeModule.links,
|
| 8205 | meta: routeModule.meta,
|
| 8206 | shouldRevalidate: routeModule.shouldRevalidate
|
| 8207 | };
|
| 8208 | }
|
| 8209 | function getRouteModuleComponent(routeModule) {
|
| 8210 | if (routeModule.default == null) return void 0;
|
| 8211 | let isEmptyObject = typeof routeModule.default === "object" && Object.keys(routeModule.default).length === 0;
|
| 8212 | if (!isEmptyObject) {
|
| 8213 | return routeModule.default;
|
| 8214 | }
|
| 8215 | }
|
| 8216 | function shouldHydrateRouteLoader(routeId, clientLoader, hasLoader, isSpaMode) {
|
| 8217 | return isSpaMode && routeId !== "root" || clientLoader != null && (clientLoader.hydrate === true || hasLoader !== true);
|
| 8218 | }
|
| 8219 |
|
| 8220 |
|
| 8221 | var nextPaths = new Set();
|
| 8222 | var discoveredPathsMaxSize = 1e3;
|
| 8223 | var discoveredPaths = new Set();
|
| 8224 | var URL_LIMIT = 7680;
|
| 8225 | function isFogOfWarEnabled(routeDiscovery, ssr) {
|
| 8226 | return routeDiscovery.mode === "lazy" && ssr === true;
|
| 8227 | }
|
| 8228 | function getPartialManifest({ sri, ...manifest }, router) {
|
| 8229 | let routeIds = new Set(router.state.matches.map((m) => m.route.id));
|
| 8230 | let segments = router.state.location.pathname.split("/").filter(Boolean);
|
| 8231 | let paths = ["/"];
|
| 8232 | segments.pop();
|
| 8233 | while (segments.length > 0) {
|
| 8234 | paths.push(`/${segments.join("/")}`);
|
| 8235 | segments.pop();
|
| 8236 | }
|
| 8237 | paths.forEach((path) => {
|
| 8238 | let matches = matchRoutes(router.routes, path, router.basename);
|
| 8239 | if (matches) {
|
| 8240 | matches.forEach((m) => routeIds.add(m.route.id));
|
| 8241 | }
|
| 8242 | });
|
| 8243 | let initialRoutes = [...routeIds].reduce(
|
| 8244 | (acc, id) => Object.assign(acc, { [id]: manifest.routes[id] }),
|
| 8245 | {}
|
| 8246 | );
|
| 8247 | return {
|
| 8248 | ...manifest,
|
| 8249 | routes: initialRoutes,
|
| 8250 | sri: sri ? true : void 0
|
| 8251 | };
|
| 8252 | }
|
| 8253 | function getPatchRoutesOnNavigationFunction(getRouter, manifest, routeModules, ssr, routeDiscovery, isSpaMode, basename) {
|
| 8254 | if (!isFogOfWarEnabled(routeDiscovery, ssr)) {
|
| 8255 | return void 0;
|
| 8256 | }
|
| 8257 | return async ({ path, patch, signal, fetcherKey }) => {
|
| 8258 | if (discoveredPaths.has(path)) {
|
| 8259 | return;
|
| 8260 | }
|
| 8261 | let { state } = getRouter();
|
| 8262 | await fetchAndApplyManifestPatches(
|
| 8263 | [path],
|
| 8264 |
|
| 8265 |
|
| 8266 | fetcherKey ? window.location.href : createPath(state.navigation.location || state.location),
|
| 8267 | manifest,
|
| 8268 | routeModules,
|
| 8269 | ssr,
|
| 8270 | isSpaMode,
|
| 8271 | basename,
|
| 8272 | routeDiscovery.manifestPath,
|
| 8273 | patch,
|
| 8274 | signal
|
| 8275 | );
|
| 8276 | };
|
| 8277 | }
|
| 8278 | function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscovery, isSpaMode) {
|
| 8279 | React6.useEffect(() => {
|
| 8280 | if (!isFogOfWarEnabled(routeDiscovery, ssr) ||
|
| 8281 | _optionalChain([window, 'access', _118 => _118.navigator, 'optionalAccess', _119 => _119.connection, 'optionalAccess', _120 => _120.saveData]) === true) {
|
| 8282 | return;
|
| 8283 | }
|
| 8284 | function registerElement(el) {
|
| 8285 | let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
|
| 8286 | if (!path) {
|
| 8287 | return;
|
| 8288 | }
|
| 8289 | let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
|
| 8290 | if (!discoveredPaths.has(pathname)) {
|
| 8291 | nextPaths.add(pathname);
|
| 8292 | }
|
| 8293 | }
|
| 8294 | async function fetchPatches() {
|
| 8295 | document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
|
| 8296 | let lazyPaths = Array.from(nextPaths.keys()).filter((path) => {
|
| 8297 | if (discoveredPaths.has(path)) {
|
| 8298 | nextPaths.delete(path);
|
| 8299 | return false;
|
| 8300 | }
|
| 8301 | return true;
|
| 8302 | });
|
| 8303 | if (lazyPaths.length === 0) {
|
| 8304 | return;
|
| 8305 | }
|
| 8306 | try {
|
| 8307 | await fetchAndApplyManifestPatches(
|
| 8308 | lazyPaths,
|
| 8309 | null,
|
| 8310 | manifest,
|
| 8311 | routeModules,
|
| 8312 | ssr,
|
| 8313 | isSpaMode,
|
| 8314 | router.basename,
|
| 8315 | routeDiscovery.manifestPath,
|
| 8316 | router.patchRoutes
|
| 8317 | );
|
| 8318 | } catch (e) {
|
| 8319 | console.error("Failed to fetch manifest patches", e);
|
| 8320 | }
|
| 8321 | }
|
| 8322 | let debouncedFetchPatches = debounce(fetchPatches, 100);
|
| 8323 | fetchPatches();
|
| 8324 | let observer = new MutationObserver(() => debouncedFetchPatches());
|
| 8325 | observer.observe(document.documentElement, {
|
| 8326 | subtree: true,
|
| 8327 | childList: true,
|
| 8328 | attributes: true,
|
| 8329 | attributeFilter: ["data-discover", "href", "action"]
|
| 8330 | });
|
| 8331 | return () => observer.disconnect();
|
| 8332 | }, [ssr, isSpaMode, manifest, routeModules, router, routeDiscovery]);
|
| 8333 | }
|
| 8334 | function getManifestPath(_manifestPath, basename) {
|
| 8335 | let manifestPath = _manifestPath || "/__manifest";
|
| 8336 | return basename == null ? manifestPath : joinPaths([basename, manifestPath]);
|
| 8337 | }
|
| 8338 | var MANIFEST_VERSION_STORAGE_KEY = "react-router-manifest-version";
|
| 8339 | async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal) {
|
| 8340 | const searchParams = new URLSearchParams();
|
| 8341 | searchParams.set("paths", paths.sort().join(","));
|
| 8342 | searchParams.set("version", manifest.version);
|
| 8343 | let url = new URL(
|
| 8344 | getManifestPath(manifestPath, basename),
|
| 8345 | window.location.origin
|
| 8346 | );
|
| 8347 | url.search = searchParams.toString();
|
| 8348 | if (url.toString().length > URL_LIMIT) {
|
| 8349 | nextPaths.clear();
|
| 8350 | return;
|
| 8351 | }
|
| 8352 | let serverPatches;
|
| 8353 | try {
|
| 8354 | let res = await fetch(url, { signal });
|
| 8355 | if (!res.ok) {
|
| 8356 | throw new Error(`${res.status} ${res.statusText}`);
|
| 8357 | } else if (res.status === 204 && res.headers.has("X-Remix-Reload-Document")) {
|
| 8358 | if (!errorReloadPath) {
|
| 8359 | console.warn(
|
| 8360 | "Detected a manifest version mismatch during eager route discovery. The next navigation/fetch to an undiscovered route will result in a new document navigation to sync up with the latest manifest."
|
| 8361 | );
|
| 8362 | return;
|
| 8363 | }
|
| 8364 | try {
|
| 8365 | if (sessionStorage.getItem(MANIFEST_VERSION_STORAGE_KEY) === manifest.version) {
|
| 8366 | console.error(
|
| 8367 | "Unable to discover routes due to manifest version mismatch."
|
| 8368 | );
|
| 8369 | return;
|
| 8370 | }
|
| 8371 | sessionStorage.setItem(MANIFEST_VERSION_STORAGE_KEY, manifest.version);
|
| 8372 | } catch (e4) {
|
| 8373 | }
|
| 8374 | window.location.href = errorReloadPath;
|
| 8375 | console.warn("Detected manifest version mismatch, reloading...");
|
| 8376 | await new Promise(() => {
|
| 8377 | });
|
| 8378 | } else if (res.status >= 400) {
|
| 8379 | throw new Error(await res.text());
|
| 8380 | }
|
| 8381 | try {
|
| 8382 | sessionStorage.removeItem(MANIFEST_VERSION_STORAGE_KEY);
|
| 8383 | } catch (e5) {
|
| 8384 | }
|
| 8385 | serverPatches = await res.json();
|
| 8386 | } catch (e) {
|
| 8387 | if (_optionalChain([signal, 'optionalAccess', _121 => _121.aborted])) return;
|
| 8388 | throw e;
|
| 8389 | }
|
| 8390 | let knownRoutes = new Set(Object.keys(manifest.routes));
|
| 8391 | let patches = Object.values(serverPatches).reduce((acc, route) => {
|
| 8392 | if (route && !knownRoutes.has(route.id)) {
|
| 8393 | acc[route.id] = route;
|
| 8394 | }
|
| 8395 | return acc;
|
| 8396 | }, {});
|
| 8397 | Object.assign(manifest.routes, patches);
|
| 8398 | paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
|
| 8399 | let parentIds = new Set();
|
| 8400 | Object.values(patches).forEach((patch) => {
|
| 8401 | if (patch && (!patch.parentId || !patches[patch.parentId])) {
|
| 8402 | parentIds.add(patch.parentId);
|
| 8403 | }
|
| 8404 | });
|
| 8405 | parentIds.forEach(
|
| 8406 | (parentId) => patchRoutes(
|
| 8407 | parentId || null,
|
| 8408 | createClientRoutes(patches, routeModules, null, ssr, isSpaMode, parentId)
|
| 8409 | )
|
| 8410 | );
|
| 8411 | }
|
| 8412 | function addToFifoQueue(path, queue) {
|
| 8413 | if (queue.size >= discoveredPathsMaxSize) {
|
| 8414 | let first = queue.values().next().value;
|
| 8415 | queue.delete(first);
|
| 8416 | }
|
| 8417 | queue.add(path);
|
| 8418 | }
|
| 8419 | function debounce(callback, wait) {
|
| 8420 | let timeoutId;
|
| 8421 | return (...args) => {
|
| 8422 | window.clearTimeout(timeoutId);
|
| 8423 | timeoutId = window.setTimeout(() => callback(...args), wait);
|
| 8424 | };
|
| 8425 | }
|
| 8426 |
|
| 8427 |
|
| 8428 | function useDataRouterContext2() {
|
| 8429 | let context = React7.useContext(DataRouterContext);
|
| 8430 | invariant2(
|
| 8431 | context,
|
| 8432 | "You must render this element inside a <DataRouterContext.Provider> element"
|
| 8433 | );
|
| 8434 | return context;
|
| 8435 | }
|
| 8436 | function useDataRouterStateContext() {
|
| 8437 | let context = React7.useContext(DataRouterStateContext);
|
| 8438 | invariant2(
|
| 8439 | context,
|
| 8440 | "You must render this element inside a <DataRouterStateContext.Provider> element"
|
| 8441 | );
|
| 8442 | return context;
|
| 8443 | }
|
| 8444 | var FrameworkContext = React7.createContext(void 0);
|
| 8445 | FrameworkContext.displayName = "FrameworkContext";
|
| 8446 | function useFrameworkContext() {
|
| 8447 | let context = React7.useContext(FrameworkContext);
|
| 8448 | invariant2(
|
| 8449 | context,
|
| 8450 | "You must render this element inside a <HydratedRouter> element"
|
| 8451 | );
|
| 8452 | return context;
|
| 8453 | }
|
| 8454 | function usePrefetchBehavior(prefetch, theirElementProps) {
|
| 8455 | let frameworkContext = React7.useContext(FrameworkContext);
|
| 8456 | let [maybePrefetch, setMaybePrefetch] = React7.useState(false);
|
| 8457 | let [shouldPrefetch, setShouldPrefetch] = React7.useState(false);
|
| 8458 | let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
|
| 8459 | let ref = React7.useRef(null);
|
| 8460 | React7.useEffect(() => {
|
| 8461 | if (prefetch === "render") {
|
| 8462 | setShouldPrefetch(true);
|
| 8463 | }
|
| 8464 | if (prefetch === "viewport") {
|
| 8465 | let callback = (entries) => {
|
| 8466 | entries.forEach((entry) => {
|
| 8467 | setShouldPrefetch(entry.isIntersecting);
|
| 8468 | });
|
| 8469 | };
|
| 8470 | let observer = new IntersectionObserver(callback, { threshold: 0.5 });
|
| 8471 | if (ref.current) observer.observe(ref.current);
|
| 8472 | return () => {
|
| 8473 | observer.disconnect();
|
| 8474 | };
|
| 8475 | }
|
| 8476 | }, [prefetch]);
|
| 8477 | React7.useEffect(() => {
|
| 8478 | if (maybePrefetch) {
|
| 8479 | let id = setTimeout(() => {
|
| 8480 | setShouldPrefetch(true);
|
| 8481 | }, 100);
|
| 8482 | return () => {
|
| 8483 | clearTimeout(id);
|
| 8484 | };
|
| 8485 | }
|
| 8486 | }, [maybePrefetch]);
|
| 8487 | let setIntent = () => {
|
| 8488 | setMaybePrefetch(true);
|
| 8489 | };
|
| 8490 | let cancelIntent = () => {
|
| 8491 | setMaybePrefetch(false);
|
| 8492 | setShouldPrefetch(false);
|
| 8493 | };
|
| 8494 | if (!frameworkContext) {
|
| 8495 | return [false, ref, {}];
|
| 8496 | }
|
| 8497 | if (prefetch !== "intent") {
|
| 8498 | return [shouldPrefetch, ref, {}];
|
| 8499 | }
|
| 8500 | return [
|
| 8501 | shouldPrefetch,
|
| 8502 | ref,
|
| 8503 | {
|
| 8504 | onFocus: composeEventHandlers(onFocus, setIntent),
|
| 8505 | onBlur: composeEventHandlers(onBlur, cancelIntent),
|
| 8506 | onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
|
| 8507 | onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
|
| 8508 | onTouchStart: composeEventHandlers(onTouchStart, setIntent)
|
| 8509 | }
|
| 8510 | ];
|
| 8511 | }
|
| 8512 | function composeEventHandlers(theirHandler, ourHandler) {
|
| 8513 | return (event) => {
|
| 8514 | theirHandler && theirHandler(event);
|
| 8515 | if (!event.defaultPrevented) {
|
| 8516 | ourHandler(event);
|
| 8517 | }
|
| 8518 | };
|
| 8519 | }
|
| 8520 | function getActiveMatches(matches, errors, isSpaMode) {
|
| 8521 | if (isSpaMode && !isHydrated) {
|
| 8522 | return [matches[0]];
|
| 8523 | }
|
| 8524 | if (errors) {
|
| 8525 | let errorIdx = matches.findIndex((m) => errors[m.route.id] !== void 0);
|
| 8526 | return matches.slice(0, errorIdx + 1);
|
| 8527 | }
|
| 8528 | return matches;
|
| 8529 | }
|
| 8530 | var CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
|
| 8531 | function Links({ nonce, crossOrigin }) {
|
| 8532 | let { isSpaMode, manifest, routeModules, criticalCss } = useFrameworkContext();
|
| 8533 | let { errors, matches: routerMatches } = useDataRouterStateContext();
|
| 8534 | let matches = getActiveMatches(routerMatches, errors, isSpaMode);
|
| 8535 | let keyedLinks = React7.useMemo(
|
| 8536 | () => getKeyedLinksForMatches(matches, routeModules, manifest),
|
| 8537 | [matches, routeModules, manifest]
|
| 8538 | );
|
| 8539 | return React7.createElement(React7.Fragment, null, typeof criticalCss === "string" ? React7.createElement(
|
| 8540 | "style",
|
| 8541 | {
|
| 8542 | ...{ [CRITICAL_CSS_DATA_ATTRIBUTE]: "" },
|
| 8543 | nonce,
|
| 8544 | dangerouslySetInnerHTML: { __html: criticalCss }
|
| 8545 | }
|
| 8546 | ) : null, typeof criticalCss === "object" ? React7.createElement(
|
| 8547 | "link",
|
| 8548 | {
|
| 8549 | ...{ [CRITICAL_CSS_DATA_ATTRIBUTE]: "" },
|
| 8550 | rel: "stylesheet",
|
| 8551 | href: criticalCss.href,
|
| 8552 | nonce,
|
| 8553 | crossOrigin
|
| 8554 | }
|
| 8555 | ) : null, keyedLinks.map(
|
| 8556 | ({ key, link }) => isPageLinkDescriptor(link) ? React7.createElement(
|
| 8557 | PrefetchPageLinks,
|
| 8558 | {
|
| 8559 | key,
|
| 8560 | nonce,
|
| 8561 | ...link,
|
| 8562 | crossOrigin: _nullishCoalesce(link.crossOrigin, () => ( crossOrigin))
|
| 8563 | }
|
| 8564 | ) : React7.createElement(
|
| 8565 | "link",
|
| 8566 | {
|
| 8567 | key,
|
| 8568 | nonce,
|
| 8569 | ...link,
|
| 8570 | crossOrigin: _nullishCoalesce(link.crossOrigin, () => ( crossOrigin))
|
| 8571 | }
|
| 8572 | )
|
| 8573 | ));
|
| 8574 | }
|
| 8575 | function PrefetchPageLinks({ page, ...linkProps }) {
|
| 8576 | let rsc = useIsRSCRouterContext();
|
| 8577 | let { router } = useDataRouterContext2();
|
| 8578 | let matches = React7.useMemo(
|
| 8579 | () => matchRoutes(router.routes, page, router.basename),
|
| 8580 | [router.routes, page, router.basename]
|
| 8581 | );
|
| 8582 | if (!matches) {
|
| 8583 | return null;
|
| 8584 | }
|
| 8585 | if (rsc) {
|
| 8586 | return React7.createElement(RSCPrefetchPageLinksImpl, { page, matches, ...linkProps });
|
| 8587 | }
|
| 8588 | return React7.createElement(PrefetchPageLinksImpl, { page, matches, ...linkProps });
|
| 8589 | }
|
| 8590 | function useKeyedPrefetchLinks(matches) {
|
| 8591 | let { manifest, routeModules } = useFrameworkContext();
|
| 8592 | let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React7.useState([]);
|
| 8593 | React7.useEffect(() => {
|
| 8594 | let interrupted = false;
|
| 8595 | void getKeyedPrefetchLinks(matches, manifest, routeModules).then(
|
| 8596 | (links) => {
|
| 8597 | if (!interrupted) {
|
| 8598 | setKeyedPrefetchLinks(links);
|
| 8599 | }
|
| 8600 | }
|
| 8601 | );
|
| 8602 | return () => {
|
| 8603 | interrupted = true;
|
| 8604 | };
|
| 8605 | }, [matches, manifest, routeModules]);
|
| 8606 | return keyedPrefetchLinks;
|
| 8607 | }
|
| 8608 | function RSCPrefetchPageLinksImpl({
|
| 8609 | page,
|
| 8610 | matches: nextMatches,
|
| 8611 | ...linkProps
|
| 8612 | }) {
|
| 8613 | let location = useLocation();
|
| 8614 | let { future } = useFrameworkContext();
|
| 8615 | let { basename } = useDataRouterContext2();
|
| 8616 | let dataHrefs = React7.useMemo(() => {
|
| 8617 | if (page === location.pathname + location.search + location.hash) {
|
| 8618 | return [];
|
| 8619 | }
|
| 8620 | let url = singleFetchUrl(
|
| 8621 | page,
|
| 8622 | basename,
|
| 8623 | future.unstable_trailingSlashAwareDataRequests,
|
| 8624 | "rsc"
|
| 8625 | );
|
| 8626 | let hasSomeRoutesWithShouldRevalidate = false;
|
| 8627 | let targetRoutes = [];
|
| 8628 | for (let match of nextMatches) {
|
| 8629 | if (typeof match.route.shouldRevalidate === "function") {
|
| 8630 | hasSomeRoutesWithShouldRevalidate = true;
|
| 8631 | } else {
|
| 8632 | targetRoutes.push(match.route.id);
|
| 8633 | }
|
| 8634 | }
|
| 8635 | if (hasSomeRoutesWithShouldRevalidate && targetRoutes.length > 0) {
|
| 8636 | url.searchParams.set("_routes", targetRoutes.join(","));
|
| 8637 | }
|
| 8638 | return [url.pathname + url.search];
|
| 8639 | }, [
|
| 8640 | basename,
|
| 8641 | future.unstable_trailingSlashAwareDataRequests,
|
| 8642 | page,
|
| 8643 | location,
|
| 8644 | nextMatches
|
| 8645 | ]);
|
| 8646 | return React7.createElement(React7.Fragment, null, dataHrefs.map((href) => React7.createElement("link", { key: href, rel: "prefetch", as: "fetch", href, ...linkProps })));
|
| 8647 | }
|
| 8648 | function PrefetchPageLinksImpl({
|
| 8649 | page,
|
| 8650 | matches: nextMatches,
|
| 8651 | ...linkProps
|
| 8652 | }) {
|
| 8653 | let location = useLocation();
|
| 8654 | let { future, manifest, routeModules } = useFrameworkContext();
|
| 8655 | let { basename } = useDataRouterContext2();
|
| 8656 | let { loaderData, matches } = useDataRouterStateContext();
|
| 8657 | let newMatchesForData = React7.useMemo(
|
| 8658 | () => getNewMatchesForLinks(
|
| 8659 | page,
|
| 8660 | nextMatches,
|
| 8661 | matches,
|
| 8662 | manifest,
|
| 8663 | location,
|
| 8664 | "data"
|
| 8665 | ),
|
| 8666 | [page, nextMatches, matches, manifest, location]
|
| 8667 | );
|
| 8668 | let newMatchesForAssets = React7.useMemo(
|
| 8669 | () => getNewMatchesForLinks(
|
| 8670 | page,
|
| 8671 | nextMatches,
|
| 8672 | matches,
|
| 8673 | manifest,
|
| 8674 | location,
|
| 8675 | "assets"
|
| 8676 | ),
|
| 8677 | [page, nextMatches, matches, manifest, location]
|
| 8678 | );
|
| 8679 | let dataHrefs = React7.useMemo(() => {
|
| 8680 | if (page === location.pathname + location.search + location.hash) {
|
| 8681 | return [];
|
| 8682 | }
|
| 8683 | let routesParams = new Set();
|
| 8684 | let foundOptOutRoute = false;
|
| 8685 | nextMatches.forEach((m) => {
|
| 8686 | let manifestRoute = manifest.routes[m.route.id];
|
| 8687 | if (!manifestRoute || !manifestRoute.hasLoader) {
|
| 8688 | return;
|
| 8689 | }
|
| 8690 | if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && _optionalChain([routeModules, 'access', _122 => _122[m.route.id], 'optionalAccess', _123 => _123.shouldRevalidate])) {
|
| 8691 | foundOptOutRoute = true;
|
| 8692 | } else if (manifestRoute.hasClientLoader) {
|
| 8693 | foundOptOutRoute = true;
|
| 8694 | } else {
|
| 8695 | routesParams.add(m.route.id);
|
| 8696 | }
|
| 8697 | });
|
| 8698 | if (routesParams.size === 0) {
|
| 8699 | return [];
|
| 8700 | }
|
| 8701 | let url = singleFetchUrl(
|
| 8702 | page,
|
| 8703 | basename,
|
| 8704 | future.unstable_trailingSlashAwareDataRequests,
|
| 8705 | "data"
|
| 8706 | );
|
| 8707 | if (foundOptOutRoute && routesParams.size > 0) {
|
| 8708 | url.searchParams.set(
|
| 8709 | "_routes",
|
| 8710 | nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(",")
|
| 8711 | );
|
| 8712 | }
|
| 8713 | return [url.pathname + url.search];
|
| 8714 | }, [
|
| 8715 | basename,
|
| 8716 | future.unstable_trailingSlashAwareDataRequests,
|
| 8717 | loaderData,
|
| 8718 | location,
|
| 8719 | manifest,
|
| 8720 | newMatchesForData,
|
| 8721 | nextMatches,
|
| 8722 | page,
|
| 8723 | routeModules
|
| 8724 | ]);
|
| 8725 | let moduleHrefs = React7.useMemo(
|
| 8726 | () => getModuleLinkHrefs(newMatchesForAssets, manifest),
|
| 8727 | [newMatchesForAssets, manifest]
|
| 8728 | );
|
| 8729 | let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
|
| 8730 | return React7.createElement(React7.Fragment, null, dataHrefs.map((href) => React7.createElement("link", { key: href, rel: "prefetch", as: "fetch", href, ...linkProps })), moduleHrefs.map((href) => React7.createElement("link", { key: href, rel: "modulepreload", href, ...linkProps })), keyedPrefetchLinks.map(({ key, link }) => (
|
| 8731 |
|
| 8732 |
|
| 8733 | React7.createElement(
|
| 8734 | "link",
|
| 8735 | {
|
| 8736 | key,
|
| 8737 | nonce: linkProps.nonce,
|
| 8738 | ...link,
|
| 8739 | crossOrigin: _nullishCoalesce(link.crossOrigin, () => ( linkProps.crossOrigin))
|
| 8740 | }
|
| 8741 | )
|
| 8742 | )));
|
| 8743 | }
|
| 8744 | function Meta() {
|
| 8745 | let { isSpaMode, routeModules } = useFrameworkContext();
|
| 8746 | let {
|
| 8747 | errors,
|
| 8748 | matches: routerMatches,
|
| 8749 | loaderData
|
| 8750 | } = useDataRouterStateContext();
|
| 8751 | let location = useLocation();
|
| 8752 | let _matches = getActiveMatches(routerMatches, errors, isSpaMode);
|
| 8753 | let error = null;
|
| 8754 | if (errors) {
|
| 8755 | error = errors[_matches[_matches.length - 1].route.id];
|
| 8756 | }
|
| 8757 | let meta = [];
|
| 8758 | let leafMeta = null;
|
| 8759 | let matches = [];
|
| 8760 | for (let i = 0; i < _matches.length; i++) {
|
| 8761 | let _match = _matches[i];
|
| 8762 | let routeId = _match.route.id;
|
| 8763 | let data2 = loaderData[routeId];
|
| 8764 | let params = _match.params;
|
| 8765 | let routeModule = routeModules[routeId];
|
| 8766 | let routeMeta = [];
|
| 8767 | let match = {
|
| 8768 | id: routeId,
|
| 8769 | data: data2,
|
| 8770 | loaderData: data2,
|
| 8771 | meta: [],
|
| 8772 | params: _match.params,
|
| 8773 | pathname: _match.pathname,
|
| 8774 | handle: _match.route.handle,
|
| 8775 | error
|
| 8776 | };
|
| 8777 | matches[i] = match;
|
| 8778 | if (_optionalChain([routeModule, 'optionalAccess', _124 => _124.meta])) {
|
| 8779 | routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
|
| 8780 | data: data2,
|
| 8781 | loaderData: data2,
|
| 8782 | params,
|
| 8783 | location,
|
| 8784 | matches,
|
| 8785 | error
|
| 8786 | }) : Array.isArray(routeModule.meta) ? [...routeModule.meta] : routeModule.meta;
|
| 8787 | } else if (leafMeta) {
|
| 8788 | routeMeta = [...leafMeta];
|
| 8789 | }
|
| 8790 | routeMeta = routeMeta || [];
|
| 8791 | if (!Array.isArray(routeMeta)) {
|
| 8792 | throw new Error(
|
| 8793 | "The route at " + _match.route.path + " returns an invalid value. All route meta functions must return an array of meta objects.\n\nTo reference the meta function API, see https://reactrouter.com/start/framework/route-module#meta"
|
| 8794 | );
|
| 8795 | }
|
| 8796 | match.meta = routeMeta;
|
| 8797 | matches[i] = match;
|
| 8798 | meta = [...routeMeta];
|
| 8799 | leafMeta = meta;
|
| 8800 | }
|
| 8801 | return React7.createElement(React7.Fragment, null, meta.flat().map((metaProps) => {
|
| 8802 | if (!metaProps) {
|
| 8803 | return null;
|
| 8804 | }
|
| 8805 | if ("tagName" in metaProps) {
|
| 8806 | let { tagName, ...rest } = metaProps;
|
| 8807 | if (!isValidMetaTag(tagName)) {
|
| 8808 | console.warn(
|
| 8809 | `A meta object uses an invalid tagName: ${tagName}. Expected either 'link' or 'meta'`
|
| 8810 | );
|
| 8811 | return null;
|
| 8812 | }
|
| 8813 | let Comp = tagName;
|
| 8814 | return React7.createElement(Comp, { key: JSON.stringify(rest), ...rest });
|
| 8815 | }
|
| 8816 | if ("title" in metaProps) {
|
| 8817 | return React7.createElement("title", { key: "title" }, String(metaProps.title));
|
| 8818 | }
|
| 8819 | if ("charset" in metaProps) {
|
| 8820 | _nullishCoalesce(metaProps.charSet, () => ( (metaProps.charSet = metaProps.charset)));
|
| 8821 | delete metaProps.charset;
|
| 8822 | }
|
| 8823 | if ("charSet" in metaProps && metaProps.charSet != null) {
|
| 8824 | return typeof metaProps.charSet === "string" ? React7.createElement("meta", { key: "charSet", charSet: metaProps.charSet }) : null;
|
| 8825 | }
|
| 8826 | if ("script:ld+json" in metaProps) {
|
| 8827 | try {
|
| 8828 | let json = JSON.stringify(metaProps["script:ld+json"]);
|
| 8829 | return React7.createElement(
|
| 8830 | "script",
|
| 8831 | {
|
| 8832 | key: `script:ld+json:${json}`,
|
| 8833 | type: "application/ld+json",
|
| 8834 | dangerouslySetInnerHTML: { __html: escapeHtml(json) }
|
| 8835 | }
|
| 8836 | );
|
| 8837 | } catch (err) {
|
| 8838 | return null;
|
| 8839 | }
|
| 8840 | }
|
| 8841 | return React7.createElement("meta", { key: JSON.stringify(metaProps), ...metaProps });
|
| 8842 | }));
|
| 8843 | }
|
| 8844 | function isValidMetaTag(tagName) {
|
| 8845 | return typeof tagName === "string" && /^(meta|link)$/.test(tagName);
|
| 8846 | }
|
| 8847 | var isHydrated = false;
|
| 8848 | function setIsHydrated() {
|
| 8849 | isHydrated = true;
|
| 8850 | }
|
| 8851 | function Scripts(scriptProps) {
|
| 8852 | let {
|
| 8853 | manifest,
|
| 8854 | serverHandoffString,
|
| 8855 | isSpaMode,
|
| 8856 | renderMeta,
|
| 8857 | routeDiscovery,
|
| 8858 | ssr
|
| 8859 | } = useFrameworkContext();
|
| 8860 | let { router, static: isStatic, staticContext } = useDataRouterContext2();
|
| 8861 | let { matches: routerMatches } = useDataRouterStateContext();
|
| 8862 | let isRSCRouterContext = useIsRSCRouterContext();
|
| 8863 | let enableFogOfWar = isFogOfWarEnabled(routeDiscovery, ssr);
|
| 8864 | if (renderMeta) {
|
| 8865 | renderMeta.didRenderScripts = true;
|
| 8866 | }
|
| 8867 | let matches = getActiveMatches(routerMatches, null, isSpaMode);
|
| 8868 | React7.useEffect(() => {
|
| 8869 | setIsHydrated();
|
| 8870 | }, []);
|
| 8871 | let initialScripts = React7.useMemo(() => {
|
| 8872 | if (isRSCRouterContext) {
|
| 8873 | return null;
|
| 8874 | }
|
| 8875 | let streamScript = "window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());";
|
| 8876 | let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};${streamScript}` : " ";
|
| 8877 | let routeModulesScript = !isStatic ? " " : `${_optionalChain([manifest, 'access', _125 => _125.hmr, 'optionalAccess', _126 => _126.runtime]) ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
|
| 8878 | ${matches.map((match, routeIndex) => {
|
| 8879 | let routeVarName = `route${routeIndex}`;
|
| 8880 | let manifestEntry = manifest.routes[match.route.id];
|
| 8881 | invariant2(manifestEntry, `Route ${match.route.id} not found in manifest`);
|
| 8882 | let {
|
| 8883 | clientActionModule,
|
| 8884 | clientLoaderModule,
|
| 8885 | clientMiddlewareModule,
|
| 8886 | hydrateFallbackModule,
|
| 8887 | module
|
| 8888 | } = manifestEntry;
|
| 8889 | let chunks = [
|
| 8890 | ...clientActionModule ? [
|
| 8891 | {
|
| 8892 | module: clientActionModule,
|
| 8893 | varName: `${routeVarName}_clientAction`
|
| 8894 | }
|
| 8895 | ] : [],
|
| 8896 | ...clientLoaderModule ? [
|
| 8897 | {
|
| 8898 | module: clientLoaderModule,
|
| 8899 | varName: `${routeVarName}_clientLoader`
|
| 8900 | }
|
| 8901 | ] : [],
|
| 8902 | ...clientMiddlewareModule ? [
|
| 8903 | {
|
| 8904 | module: clientMiddlewareModule,
|
| 8905 | varName: `${routeVarName}_clientMiddleware`
|
| 8906 | }
|
| 8907 | ] : [],
|
| 8908 | ...hydrateFallbackModule ? [
|
| 8909 | {
|
| 8910 | module: hydrateFallbackModule,
|
| 8911 | varName: `${routeVarName}_HydrateFallback`
|
| 8912 | }
|
| 8913 | ] : [],
|
| 8914 | { module, varName: `${routeVarName}_main` }
|
| 8915 | ];
|
| 8916 | if (chunks.length === 1) {
|
| 8917 | return `import * as ${routeVarName} from ${JSON.stringify(module)};`;
|
| 8918 | }
|
| 8919 | let chunkImportsSnippet = chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n");
|
| 8920 | let mergedChunksSnippet = `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`;
|
| 8921 | return [chunkImportsSnippet, mergedChunksSnippet].join("\n");
|
| 8922 | }).join("\n")}
|
| 8923 | ${enableFogOfWar ? (
|
| 8924 | // Inline a minimal manifest with the SSR matches
|
| 8925 | `window.__reactRouterManifest = ${JSON.stringify(
|
| 8926 | getPartialManifest(manifest, router),
|
| 8927 | null,
|
| 8928 | 2
|
| 8929 | )};`
|
| 8930 | ) : ""}
|
| 8931 | window.__reactRouterRouteModules = {${matches.map((match, index) => `${JSON.stringify(match.route.id)}:route${index}`).join(",")}};
|
| 8932 |
|
| 8933 | import(${JSON.stringify(manifest.entry.module)});`;
|
| 8934 | return React7.createElement(React7.Fragment, null, React7.createElement(
|
| 8935 | "script",
|
| 8936 | {
|
| 8937 | ...scriptProps,
|
| 8938 | suppressHydrationWarning: true,
|
| 8939 | dangerouslySetInnerHTML: { __html: contextScript },
|
| 8940 | type: void 0
|
| 8941 | }
|
| 8942 | ), React7.createElement(
|
| 8943 | "script",
|
| 8944 | {
|
| 8945 | ...scriptProps,
|
| 8946 | suppressHydrationWarning: true,
|
| 8947 | dangerouslySetInnerHTML: { __html: routeModulesScript },
|
| 8948 | type: "module",
|
| 8949 | async: true
|
| 8950 | }
|
| 8951 | ));
|
| 8952 | }, []);
|
| 8953 | let preloads = isHydrated || isRSCRouterContext ? [] : dedupe(
|
| 8954 | manifest.entry.imports.concat(
|
| 8955 | getModuleLinkHrefs(matches, manifest, {
|
| 8956 | includeHydrateFallback: true
|
| 8957 | })
|
| 8958 | )
|
| 8959 | );
|
| 8960 | let sri = typeof manifest.sri === "object" ? manifest.sri : {};
|
| 8961 | warnOnce(
|
| 8962 | !isRSCRouterContext,
|
| 8963 | "The <Scripts /> element is a no-op when using RSC and can be safely removed."
|
| 8964 | );
|
| 8965 | return isHydrated || isRSCRouterContext ? null : React7.createElement(React7.Fragment, null, typeof manifest.sri === "object" ? React7.createElement(
|
| 8966 | "script",
|
| 8967 | {
|
| 8968 | ...scriptProps,
|
| 8969 | "rr-importmap": "",
|
| 8970 | type: "importmap",
|
| 8971 | suppressHydrationWarning: true,
|
| 8972 | dangerouslySetInnerHTML: {
|
| 8973 | __html: JSON.stringify({
|
| 8974 | integrity: sri
|
| 8975 | })
|
| 8976 | }
|
| 8977 | }
|
| 8978 | ) : null, !enableFogOfWar ? React7.createElement(
|
| 8979 | "link",
|
| 8980 | {
|
| 8981 | rel: "modulepreload",
|
| 8982 | href: manifest.url,
|
| 8983 | crossOrigin: scriptProps.crossOrigin,
|
| 8984 | integrity: sri[manifest.url],
|
| 8985 | suppressHydrationWarning: true
|
| 8986 | }
|
| 8987 | ) : null, React7.createElement(
|
| 8988 | "link",
|
| 8989 | {
|
| 8990 | rel: "modulepreload",
|
| 8991 | href: manifest.entry.module,
|
| 8992 | crossOrigin: scriptProps.crossOrigin,
|
| 8993 | integrity: sri[manifest.entry.module],
|
| 8994 | suppressHydrationWarning: true
|
| 8995 | }
|
| 8996 | ), preloads.map((path) => React7.createElement(
|
| 8997 | "link",
|
| 8998 | {
|
| 8999 | key: path,
|
| 9000 | rel: "modulepreload",
|
| 9001 | href: path,
|
| 9002 | crossOrigin: scriptProps.crossOrigin,
|
| 9003 | integrity: sri[path],
|
| 9004 | suppressHydrationWarning: true
|
| 9005 | }
|
| 9006 | )), initialScripts);
|
| 9007 | }
|
| 9008 | function dedupe(array) {
|
| 9009 | return [...new Set(array)];
|
| 9010 | }
|
| 9011 | function mergeRefs(...refs) {
|
| 9012 | return (value) => {
|
| 9013 | refs.forEach((ref) => {
|
| 9014 | if (typeof ref === "function") {
|
| 9015 | ref(value);
|
| 9016 | } else if (ref != null) {
|
| 9017 | ref.current = value;
|
| 9018 | }
|
| 9019 | });
|
| 9020 | };
|
| 9021 | }
|
| 9022 |
|
| 9023 |
|
| 9024 | var RemixErrorBoundary = class extends React8.Component {
|
| 9025 | constructor(props) {
|
| 9026 | super(props);
|
| 9027 | this.state = { error: props.error || null, location: props.location };
|
| 9028 | }
|
| 9029 | static getDerivedStateFromError(error) {
|
| 9030 | return { error };
|
| 9031 | }
|
| 9032 | static getDerivedStateFromProps(props, state) {
|
| 9033 | if (state.location !== props.location) {
|
| 9034 | return { error: props.error || null, location: props.location };
|
| 9035 | }
|
| 9036 | return { error: props.error || state.error, location: state.location };
|
| 9037 | }
|
| 9038 | render() {
|
| 9039 | if (this.state.error) {
|
| 9040 | return React8.createElement(
|
| 9041 | RemixRootDefaultErrorBoundary,
|
| 9042 | {
|
| 9043 | error: this.state.error,
|
| 9044 | isOutsideRemixApp: true
|
| 9045 | }
|
| 9046 | );
|
| 9047 | } else {
|
| 9048 | return this.props.children;
|
| 9049 | }
|
| 9050 | }
|
| 9051 | };
|
| 9052 | function RemixRootDefaultErrorBoundary({
|
| 9053 | error,
|
| 9054 | isOutsideRemixApp
|
| 9055 | }) {
|
| 9056 | console.error(error);
|
| 9057 | let heyDeveloper = React8.createElement(
|
| 9058 | "script",
|
| 9059 | {
|
| 9060 | dangerouslySetInnerHTML: {
|
| 9061 | __html: `
|
| 9062 | console.log(
|
| 9063 | "\u{1F4BF} Hey developer \u{1F44B}. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
|
| 9064 | );
|
| 9065 | `
|
| 9066 | }
|
| 9067 | }
|
| 9068 | );
|
| 9069 | if (isRouteErrorResponse(error)) {
|
| 9070 | return React8.createElement(BoundaryShell, { title: "Unhandled Thrown Response!" }, React8.createElement("h1", { style: { fontSize: "24px" } }, error.status, " ", error.statusText), ENABLE_DEV_WARNINGS ? heyDeveloper : null);
|
| 9071 | }
|
| 9072 | let errorInstance;
|
| 9073 | if (error instanceof Error) {
|
| 9074 | errorInstance = error;
|
| 9075 | } else {
|
| 9076 | let errorString = error == null ? "Unknown Error" : typeof error === "object" && "toString" in error ? error.toString() : JSON.stringify(error);
|
| 9077 | errorInstance = new Error(errorString);
|
| 9078 | }
|
| 9079 | return React8.createElement(
|
| 9080 | BoundaryShell,
|
| 9081 | {
|
| 9082 | title: "Application Error!",
|
| 9083 | isOutsideRemixApp
|
| 9084 | },
|
| 9085 | React8.createElement("h1", { style: { fontSize: "24px" } }, "Application Error"),
|
| 9086 | React8.createElement(
|
| 9087 | "pre",
|
| 9088 | {
|
| 9089 | style: {
|
| 9090 | padding: "2rem",
|
| 9091 | background: "hsla(10, 50%, 50%, 0.1)",
|
| 9092 | color: "red",
|
| 9093 | overflow: "auto"
|
| 9094 | }
|
| 9095 | },
|
| 9096 | errorInstance.stack
|
| 9097 | ),
|
| 9098 | heyDeveloper
|
| 9099 | );
|
| 9100 | }
|
| 9101 | function BoundaryShell({
|
| 9102 | title,
|
| 9103 | renderScripts,
|
| 9104 | isOutsideRemixApp,
|
| 9105 | children
|
| 9106 | }) {
|
| 9107 | let { routeModules } = useFrameworkContext();
|
| 9108 | if (_optionalChain([routeModules, 'access', _127 => _127.root, 'optionalAccess', _128 => _128.Layout]) && !isOutsideRemixApp) {
|
| 9109 | return children;
|
| 9110 | }
|
| 9111 | return React8.createElement("html", { lang: "en" }, React8.createElement("head", null, React8.createElement("meta", { charSet: "utf-8" }), React8.createElement(
|
| 9112 | "meta",
|
| 9113 | {
|
| 9114 | name: "viewport",
|
| 9115 | content: "width=device-width,initial-scale=1,viewport-fit=cover"
|
| 9116 | }
|
| 9117 | ), React8.createElement("title", null, title)), React8.createElement("body", null, React8.createElement("main", { style: { fontFamily: "system-ui, sans-serif", padding: "2rem" } }, children, renderScripts ? React8.createElement(Scripts, null) : null)));
|
| 9118 | }
|
| 9119 |
|
| 9120 |
|
| 9121 |
|
| 9122 | var USE_OPTIMISTIC = "useOptimistic";
|
| 9123 | var useOptimisticImpl = React9[USE_OPTIMISTIC];
|
| 9124 | var stableUseOptimisticSetter = () => void 0;
|
| 9125 | function useOptimisticSafe(val) {
|
| 9126 | if (useOptimisticImpl) {
|
| 9127 | return useOptimisticImpl(val);
|
| 9128 | } else {
|
| 9129 | return [val, stableUseOptimisticSetter];
|
| 9130 | }
|
| 9131 | }
|
| 9132 | function mapRouteProperties(route) {
|
| 9133 | let updates = {
|
| 9134 |
|
| 9135 |
|
| 9136 | hasErrorBoundary: route.hasErrorBoundary || route.ErrorBoundary != null || route.errorElement != null
|
| 9137 | };
|
| 9138 | if (route.Component) {
|
| 9139 | if (ENABLE_DEV_WARNINGS) {
|
| 9140 | if (route.element) {
|
| 9141 | warning(
|
| 9142 | false,
|
| 9143 | "You should not include both `Component` and `element` on your route - `Component` will be used."
|
| 9144 | );
|
| 9145 | }
|
| 9146 | }
|
| 9147 | Object.assign(updates, {
|
| 9148 | element: React9.createElement(route.Component),
|
| 9149 | Component: void 0
|
| 9150 | });
|
| 9151 | }
|
| 9152 | if (route.HydrateFallback) {
|
| 9153 | if (ENABLE_DEV_WARNINGS) {
|
| 9154 | if (route.hydrateFallbackElement) {
|
| 9155 | warning(
|
| 9156 | false,
|
| 9157 | "You should not include both `HydrateFallback` and `hydrateFallbackElement` on your route - `HydrateFallback` will be used."
|
| 9158 | );
|
| 9159 | }
|
| 9160 | }
|
| 9161 | Object.assign(updates, {
|
| 9162 | hydrateFallbackElement: React9.createElement(route.HydrateFallback),
|
| 9163 | HydrateFallback: void 0
|
| 9164 | });
|
| 9165 | }
|
| 9166 | if (route.ErrorBoundary) {
|
| 9167 | if (ENABLE_DEV_WARNINGS) {
|
| 9168 | if (route.errorElement) {
|
| 9169 | warning(
|
| 9170 | false,
|
| 9171 | "You should not include both `ErrorBoundary` and `errorElement` on your route - `ErrorBoundary` will be used."
|
| 9172 | );
|
| 9173 | }
|
| 9174 | }
|
| 9175 | Object.assign(updates, {
|
| 9176 | errorElement: React9.createElement(route.ErrorBoundary),
|
| 9177 | ErrorBoundary: void 0
|
| 9178 | });
|
| 9179 | }
|
| 9180 | return updates;
|
| 9181 | }
|
| 9182 | var hydrationRouteProperties = [
|
| 9183 | "HydrateFallback",
|
| 9184 | "hydrateFallbackElement"
|
| 9185 | ];
|
| 9186 | function createMemoryRouter(routes, opts) {
|
| 9187 | return createRouter({
|
| 9188 | basename: _optionalChain([opts, 'optionalAccess', _129 => _129.basename]),
|
| 9189 | getContext: _optionalChain([opts, 'optionalAccess', _130 => _130.getContext]),
|
| 9190 | future: _optionalChain([opts, 'optionalAccess', _131 => _131.future]),
|
| 9191 | history: createMemoryHistory({
|
| 9192 | initialEntries: _optionalChain([opts, 'optionalAccess', _132 => _132.initialEntries]),
|
| 9193 | initialIndex: _optionalChain([opts, 'optionalAccess', _133 => _133.initialIndex])
|
| 9194 | }),
|
| 9195 | hydrationData: _optionalChain([opts, 'optionalAccess', _134 => _134.hydrationData]),
|
| 9196 | routes,
|
| 9197 | hydrationRouteProperties,
|
| 9198 | mapRouteProperties,
|
| 9199 | dataStrategy: _optionalChain([opts, 'optionalAccess', _135 => _135.dataStrategy]),
|
| 9200 | patchRoutesOnNavigation: _optionalChain([opts, 'optionalAccess', _136 => _136.patchRoutesOnNavigation]),
|
| 9201 | unstable_instrumentations: _optionalChain([opts, 'optionalAccess', _137 => _137.unstable_instrumentations])
|
| 9202 | }).initialize();
|
| 9203 | }
|
| 9204 | var Deferred2 = class {
|
| 9205 | constructor() {
|
| 9206 | this.status = "pending";
|
| 9207 | this.promise = new Promise((resolve, reject) => {
|
| 9208 | this.resolve = (value) => {
|
| 9209 | if (this.status === "pending") {
|
| 9210 | this.status = "resolved";
|
| 9211 | resolve(value);
|
| 9212 | }
|
| 9213 | };
|
| 9214 | this.reject = (reason) => {
|
| 9215 | if (this.status === "pending") {
|
| 9216 | this.status = "rejected";
|
| 9217 | reject(reason);
|
| 9218 | }
|
| 9219 | };
|
| 9220 | });
|
| 9221 | }
|
| 9222 | };
|
| 9223 | function RouterProvider({
|
| 9224 | router,
|
| 9225 | flushSync: reactDomFlushSyncImpl,
|
| 9226 | onError,
|
| 9227 | unstable_useTransitions
|
| 9228 | }) {
|
| 9229 | let unstable_rsc = useIsRSCRouterContext();
|
| 9230 | unstable_useTransitions = unstable_rsc || unstable_useTransitions;
|
| 9231 | let [_state, setStateImpl] = React9.useState(router.state);
|
| 9232 | let [state, setOptimisticState] = useOptimisticSafe(_state);
|
| 9233 | let [pendingState, setPendingState] = React9.useState();
|
| 9234 | let [vtContext, setVtContext] = React9.useState({
|
| 9235 | isTransitioning: false
|
| 9236 | });
|
| 9237 | let [renderDfd, setRenderDfd] = React9.useState();
|
| 9238 | let [transition, setTransition] = React9.useState();
|
| 9239 | let [interruption, setInterruption] = React9.useState();
|
| 9240 | let fetcherData = React9.useRef( new Map());
|
| 9241 | let setState = React9.useCallback(
|
| 9242 | (newState, { deletedFetchers, newErrors, flushSync, viewTransitionOpts }) => {
|
| 9243 | if (newErrors && onError) {
|
| 9244 | Object.values(newErrors).forEach(
|
| 9245 | (error) => onError(error, {
|
| 9246 | location: newState.location,
|
| 9247 | params: _nullishCoalesce(_optionalChain([newState, 'access', _138 => _138.matches, 'access', _139 => _139[0], 'optionalAccess', _140 => _140.params]), () => ( {})),
|
| 9248 | unstable_pattern: getRoutePattern(newState.matches)
|
| 9249 | })
|
| 9250 | );
|
| 9251 | }
|
| 9252 | newState.fetchers.forEach((fetcher, key) => {
|
| 9253 | if (fetcher.data !== void 0) {
|
| 9254 | fetcherData.current.set(key, fetcher.data);
|
| 9255 | }
|
| 9256 | });
|
| 9257 | deletedFetchers.forEach((key) => fetcherData.current.delete(key));
|
| 9258 | warnOnce(
|
| 9259 | flushSync === false || reactDomFlushSyncImpl != null,
|
| 9260 | 'You provided the `flushSync` option to a router update, but you are not using the `<RouterProvider>` from `react-router/dom` so `ReactDOM.flushSync()` is unavailable. Please update your app to `import { RouterProvider } from "react-router/dom"` and ensure you have `react-dom` installed as a dependency to use the `flushSync` option.'
|
| 9261 | );
|
| 9262 | let isViewTransitionAvailable = router.window != null && router.window.document != null && typeof router.window.document.startViewTransition === "function";
|
| 9263 | warnOnce(
|
| 9264 | viewTransitionOpts == null || isViewTransitionAvailable,
|
| 9265 | "You provided the `viewTransition` option to a router update, but you do not appear to be running in a DOM environment as `window.startViewTransition` is not available."
|
| 9266 | );
|
| 9267 | if (!viewTransitionOpts || !isViewTransitionAvailable) {
|
| 9268 | if (reactDomFlushSyncImpl && flushSync) {
|
| 9269 | reactDomFlushSyncImpl(() => setStateImpl(newState));
|
| 9270 | } else if (unstable_useTransitions === false) {
|
| 9271 | setStateImpl(newState);
|
| 9272 | } else {
|
| 9273 | React9.startTransition(() => {
|
| 9274 | if (unstable_useTransitions === true) {
|
| 9275 | setOptimisticState((s) => getOptimisticRouterState(s, newState));
|
| 9276 | }
|
| 9277 | setStateImpl(newState);
|
| 9278 | });
|
| 9279 | }
|
| 9280 | return;
|
| 9281 | }
|
| 9282 | if (reactDomFlushSyncImpl && flushSync) {
|
| 9283 | reactDomFlushSyncImpl(() => {
|
| 9284 | if (transition) {
|
| 9285 | _optionalChain([renderDfd, 'optionalAccess', _141 => _141.resolve, 'call', _142 => _142()]);
|
| 9286 | transition.skipTransition();
|
| 9287 | }
|
| 9288 | setVtContext({
|
| 9289 | isTransitioning: true,
|
| 9290 | flushSync: true,
|
| 9291 | currentLocation: viewTransitionOpts.currentLocation,
|
| 9292 | nextLocation: viewTransitionOpts.nextLocation
|
| 9293 | });
|
| 9294 | });
|
| 9295 | let t = router.window.document.startViewTransition(() => {
|
| 9296 | reactDomFlushSyncImpl(() => setStateImpl(newState));
|
| 9297 | });
|
| 9298 | t.finished.finally(() => {
|
| 9299 | reactDomFlushSyncImpl(() => {
|
| 9300 | setRenderDfd(void 0);
|
| 9301 | setTransition(void 0);
|
| 9302 | setPendingState(void 0);
|
| 9303 | setVtContext({ isTransitioning: false });
|
| 9304 | });
|
| 9305 | });
|
| 9306 | reactDomFlushSyncImpl(() => setTransition(t));
|
| 9307 | return;
|
| 9308 | }
|
| 9309 | if (transition) {
|
| 9310 | _optionalChain([renderDfd, 'optionalAccess', _143 => _143.resolve, 'call', _144 => _144()]);
|
| 9311 | transition.skipTransition();
|
| 9312 | setInterruption({
|
| 9313 | state: newState,
|
| 9314 | currentLocation: viewTransitionOpts.currentLocation,
|
| 9315 | nextLocation: viewTransitionOpts.nextLocation
|
| 9316 | });
|
| 9317 | } else {
|
| 9318 | setPendingState(newState);
|
| 9319 | setVtContext({
|
| 9320 | isTransitioning: true,
|
| 9321 | flushSync: false,
|
| 9322 | currentLocation: viewTransitionOpts.currentLocation,
|
| 9323 | nextLocation: viewTransitionOpts.nextLocation
|
| 9324 | });
|
| 9325 | }
|
| 9326 | },
|
| 9327 | [
|
| 9328 | router.window,
|
| 9329 | reactDomFlushSyncImpl,
|
| 9330 | transition,
|
| 9331 | renderDfd,
|
| 9332 | unstable_useTransitions,
|
| 9333 | setOptimisticState,
|
| 9334 | onError
|
| 9335 | ]
|
| 9336 | );
|
| 9337 | React9.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
|
| 9338 | let initialized = state.initialized;
|
| 9339 | React9.useLayoutEffect(() => {
|
| 9340 | if (!initialized && router.state.initialized) {
|
| 9341 | setState(router.state, {
|
| 9342 | deletedFetchers: [],
|
| 9343 | flushSync: false,
|
| 9344 | newErrors: null
|
| 9345 | });
|
| 9346 | }
|
| 9347 | }, [initialized, setState, router.state]);
|
| 9348 | React9.useEffect(() => {
|
| 9349 | if (vtContext.isTransitioning && !vtContext.flushSync) {
|
| 9350 | setRenderDfd(new Deferred2());
|
| 9351 | }
|
| 9352 | }, [vtContext]);
|
| 9353 | React9.useEffect(() => {
|
| 9354 | if (renderDfd && pendingState && router.window) {
|
| 9355 | let newState = pendingState;
|
| 9356 | let renderPromise = renderDfd.promise;
|
| 9357 | let transition2 = router.window.document.startViewTransition(async () => {
|
| 9358 | if (unstable_useTransitions === false) {
|
| 9359 | setStateImpl(newState);
|
| 9360 | } else {
|
| 9361 | React9.startTransition(() => {
|
| 9362 | if (unstable_useTransitions === true) {
|
| 9363 | setOptimisticState((s) => getOptimisticRouterState(s, newState));
|
| 9364 | }
|
| 9365 | setStateImpl(newState);
|
| 9366 | });
|
| 9367 | }
|
| 9368 | await renderPromise;
|
| 9369 | });
|
| 9370 | transition2.finished.finally(() => {
|
| 9371 | setRenderDfd(void 0);
|
| 9372 | setTransition(void 0);
|
| 9373 | setPendingState(void 0);
|
| 9374 | setVtContext({ isTransitioning: false });
|
| 9375 | });
|
| 9376 | setTransition(transition2);
|
| 9377 | }
|
| 9378 | }, [
|
| 9379 | pendingState,
|
| 9380 | renderDfd,
|
| 9381 | router.window,
|
| 9382 | unstable_useTransitions,
|
| 9383 | setOptimisticState
|
| 9384 | ]);
|
| 9385 | React9.useEffect(() => {
|
| 9386 | if (renderDfd && pendingState && state.location.key === pendingState.location.key) {
|
| 9387 | renderDfd.resolve();
|
| 9388 | }
|
| 9389 | }, [renderDfd, transition, state.location, pendingState]);
|
| 9390 | React9.useEffect(() => {
|
| 9391 | if (!vtContext.isTransitioning && interruption) {
|
| 9392 | setPendingState(interruption.state);
|
| 9393 | setVtContext({
|
| 9394 | isTransitioning: true,
|
| 9395 | flushSync: false,
|
| 9396 | currentLocation: interruption.currentLocation,
|
| 9397 | nextLocation: interruption.nextLocation
|
| 9398 | });
|
| 9399 | setInterruption(void 0);
|
| 9400 | }
|
| 9401 | }, [vtContext.isTransitioning, interruption]);
|
| 9402 | let navigator = React9.useMemo(() => {
|
| 9403 | return {
|
| 9404 | createHref: router.createHref,
|
| 9405 | encodeLocation: router.encodeLocation,
|
| 9406 | go: (n) => router.navigate(n),
|
| 9407 | push: (to, state2, opts) => router.navigate(to, {
|
| 9408 | state: state2,
|
| 9409 | preventScrollReset: _optionalChain([opts, 'optionalAccess', _145 => _145.preventScrollReset])
|
| 9410 | }),
|
| 9411 | replace: (to, state2, opts) => router.navigate(to, {
|
| 9412 | replace: true,
|
| 9413 | state: state2,
|
| 9414 | preventScrollReset: _optionalChain([opts, 'optionalAccess', _146 => _146.preventScrollReset])
|
| 9415 | })
|
| 9416 | };
|
| 9417 | }, [router]);
|
| 9418 | let basename = router.basename || "/";
|
| 9419 | let dataRouterContext = React9.useMemo(
|
| 9420 | () => ({
|
| 9421 | router,
|
| 9422 | navigator,
|
| 9423 | static: false,
|
| 9424 | basename,
|
| 9425 | onError
|
| 9426 | }),
|
| 9427 | [router, navigator, basename, onError]
|
| 9428 | );
|
| 9429 | return React9.createElement(React9.Fragment, null, React9.createElement(DataRouterContext.Provider, { value: dataRouterContext }, React9.createElement(DataRouterStateContext.Provider, { value: state }, React9.createElement(FetchersContext.Provider, { value: fetcherData.current }, React9.createElement(ViewTransitionContext.Provider, { value: vtContext }, React9.createElement(
|
| 9430 | Router,
|
| 9431 | {
|
| 9432 | basename,
|
| 9433 | location: state.location,
|
| 9434 | navigationType: state.historyAction,
|
| 9435 | navigator,
|
| 9436 | unstable_useTransitions
|
| 9437 | },
|
| 9438 | React9.createElement(
|
| 9439 | MemoizedDataRoutes,
|
| 9440 | {
|
| 9441 | routes: router.routes,
|
| 9442 | future: router.future,
|
| 9443 | state,
|
| 9444 | isStatic: false,
|
| 9445 | onError
|
| 9446 | }
|
| 9447 | )
|
| 9448 | ))))), null);
|
| 9449 | }
|
| 9450 | function getOptimisticRouterState(currentState, newState) {
|
| 9451 | return {
|
| 9452 |
|
| 9453 |
|
| 9454 |
|
| 9455 | ...currentState,
|
| 9456 |
|
| 9457 |
|
| 9458 | navigation: newState.navigation.state !== "idle" ? newState.navigation : currentState.navigation,
|
| 9459 | revalidation: newState.revalidation !== "idle" ? newState.revalidation : currentState.revalidation,
|
| 9460 | actionData: newState.navigation.state !== "submitting" ? newState.actionData : currentState.actionData,
|
| 9461 | fetchers: newState.fetchers
|
| 9462 | };
|
| 9463 | }
|
| 9464 | var MemoizedDataRoutes = React9.memo(DataRoutes);
|
| 9465 | function DataRoutes({
|
| 9466 | routes,
|
| 9467 | future,
|
| 9468 | state,
|
| 9469 | isStatic,
|
| 9470 | onError
|
| 9471 | }) {
|
| 9472 | return useRoutesImpl(routes, void 0, { state, isStatic, onError, future });
|
| 9473 | }
|
| 9474 | function MemoryRouter({
|
| 9475 | basename,
|
| 9476 | children,
|
| 9477 | initialEntries,
|
| 9478 | initialIndex,
|
| 9479 | unstable_useTransitions
|
| 9480 | }) {
|
| 9481 | let historyRef = React9.useRef();
|
| 9482 | if (historyRef.current == null) {
|
| 9483 | historyRef.current = createMemoryHistory({
|
| 9484 | initialEntries,
|
| 9485 | initialIndex,
|
| 9486 | v5Compat: true
|
| 9487 | });
|
| 9488 | }
|
| 9489 | let history = historyRef.current;
|
| 9490 | let [state, setStateImpl] = React9.useState({
|
| 9491 | action: history.action,
|
| 9492 | location: history.location
|
| 9493 | });
|
| 9494 | let setState = React9.useCallback(
|
| 9495 | (newState) => {
|
| 9496 | if (unstable_useTransitions === false) {
|
| 9497 | setStateImpl(newState);
|
| 9498 | } else {
|
| 9499 | React9.startTransition(() => setStateImpl(newState));
|
| 9500 | }
|
| 9501 | },
|
| 9502 | [unstable_useTransitions]
|
| 9503 | );
|
| 9504 | React9.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
| 9505 | return React9.createElement(
|
| 9506 | Router,
|
| 9507 | {
|
| 9508 | basename,
|
| 9509 | children,
|
| 9510 | location: state.location,
|
| 9511 | navigationType: state.action,
|
| 9512 | navigator: history,
|
| 9513 | unstable_useTransitions
|
| 9514 | }
|
| 9515 | );
|
| 9516 | }
|
| 9517 | function Navigate({
|
| 9518 | to,
|
| 9519 | replace: replace2,
|
| 9520 | state,
|
| 9521 | relative
|
| 9522 | }) {
|
| 9523 | invariant(
|
| 9524 | useInRouterContext(),
|
| 9525 |
|
| 9526 |
|
| 9527 | `<Navigate> may be used only in the context of a <Router> component.`
|
| 9528 | );
|
| 9529 | let { static: isStatic } = React9.useContext(NavigationContext);
|
| 9530 | warning(
|
| 9531 | !isStatic,
|
| 9532 | `<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`
|
| 9533 | );
|
| 9534 | let { matches } = React9.useContext(RouteContext);
|
| 9535 | let { pathname: locationPathname } = useLocation();
|
| 9536 | let navigate = useNavigate();
|
| 9537 | let path = resolveTo(
|
| 9538 | to,
|
| 9539 | getResolveToMatches(matches),
|
| 9540 | locationPathname,
|
| 9541 | relative === "path"
|
| 9542 | );
|
| 9543 | let jsonPath = JSON.stringify(path);
|
| 9544 | React9.useEffect(() => {
|
| 9545 | navigate(JSON.parse(jsonPath), { replace: replace2, state, relative });
|
| 9546 | }, [navigate, jsonPath, relative, replace2, state]);
|
| 9547 | return null;
|
| 9548 | }
|
| 9549 | function Outlet(props) {
|
| 9550 | return useOutlet(props.context);
|
| 9551 | }
|
| 9552 | function Route(props) {
|
| 9553 | invariant(
|
| 9554 | false,
|
| 9555 | `A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`
|
| 9556 | );
|
| 9557 | }
|
| 9558 | function Router({
|
| 9559 | basename: basenameProp = "/",
|
| 9560 | children = null,
|
| 9561 | location: locationProp,
|
| 9562 | navigationType = "POP" /* Pop */,
|
| 9563 | navigator,
|
| 9564 | static: staticProp = false,
|
| 9565 | unstable_useTransitions
|
| 9566 | }) {
|
| 9567 | invariant(
|
| 9568 | !useInRouterContext(),
|
| 9569 | `You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`
|
| 9570 | );
|
| 9571 | let basename = basenameProp.replace(/^\/*/, "/");
|
| 9572 | let navigationContext = React9.useMemo(
|
| 9573 | () => ({
|
| 9574 | basename,
|
| 9575 | navigator,
|
| 9576 | static: staticProp,
|
| 9577 | unstable_useTransitions,
|
| 9578 | future: {}
|
| 9579 | }),
|
| 9580 | [basename, navigator, staticProp, unstable_useTransitions]
|
| 9581 | );
|
| 9582 | if (typeof locationProp === "string") {
|
| 9583 | locationProp = parsePath(locationProp);
|
| 9584 | }
|
| 9585 | let {
|
| 9586 | pathname = "/",
|
| 9587 | search = "",
|
| 9588 | hash = "",
|
| 9589 | state = null,
|
| 9590 | key = "default",
|
| 9591 | unstable_mask
|
| 9592 | } = locationProp;
|
| 9593 | let locationContext = React9.useMemo(() => {
|
| 9594 | let trailingPathname = stripBasename(pathname, basename);
|
| 9595 | if (trailingPathname == null) {
|
| 9596 | return null;
|
| 9597 | }
|
| 9598 | return {
|
| 9599 | location: {
|
| 9600 | pathname: trailingPathname,
|
| 9601 | search,
|
| 9602 | hash,
|
| 9603 | state,
|
| 9604 | key,
|
| 9605 | unstable_mask
|
| 9606 | },
|
| 9607 | navigationType
|
| 9608 | };
|
| 9609 | }, [
|
| 9610 | basename,
|
| 9611 | pathname,
|
| 9612 | search,
|
| 9613 | hash,
|
| 9614 | state,
|
| 9615 | key,
|
| 9616 | navigationType,
|
| 9617 | unstable_mask
|
| 9618 | ]);
|
| 9619 | warning(
|
| 9620 | locationContext != null,
|
| 9621 | `<Router basename="${basename}"> is not able to match the URL "${pathname}${search}${hash}" because it does not start with the basename, so the <Router> won't render anything.`
|
| 9622 | );
|
| 9623 | if (locationContext == null) {
|
| 9624 | return null;
|
| 9625 | }
|
| 9626 | return React9.createElement(NavigationContext.Provider, { value: navigationContext }, React9.createElement(LocationContext.Provider, { children, value: locationContext }));
|
| 9627 | }
|
| 9628 | function Routes({
|
| 9629 | children,
|
| 9630 | location
|
| 9631 | }) {
|
| 9632 | return useRoutes(createRoutesFromChildren(children), location);
|
| 9633 | }
|
| 9634 | function Await({
|
| 9635 | children,
|
| 9636 | errorElement,
|
| 9637 | resolve
|
| 9638 | }) {
|
| 9639 | let dataRouterContext = React9.useContext(DataRouterContext);
|
| 9640 | let dataRouterStateContext = React9.useContext(DataRouterStateContext);
|
| 9641 | let onError = React9.useCallback(
|
| 9642 | (error, errorInfo) => {
|
| 9643 | if (dataRouterContext && dataRouterContext.onError && dataRouterStateContext) {
|
| 9644 | dataRouterContext.onError(error, {
|
| 9645 | location: dataRouterStateContext.location,
|
| 9646 | params: _optionalChain([dataRouterStateContext, 'access', _147 => _147.matches, 'access', _148 => _148[0], 'optionalAccess', _149 => _149.params]) || {},
|
| 9647 | unstable_pattern: getRoutePattern(dataRouterStateContext.matches),
|
| 9648 | errorInfo
|
| 9649 | });
|
| 9650 | }
|
| 9651 | },
|
| 9652 | [dataRouterContext, dataRouterStateContext]
|
| 9653 | );
|
| 9654 | return React9.createElement(
|
| 9655 | AwaitErrorBoundary,
|
| 9656 | {
|
| 9657 | resolve,
|
| 9658 | errorElement,
|
| 9659 | onError
|
| 9660 | },
|
| 9661 | React9.createElement(ResolveAwait, null, children)
|
| 9662 | );
|
| 9663 | }
|
| 9664 | var AwaitErrorBoundary = class extends React9.Component {
|
| 9665 | constructor(props) {
|
| 9666 | super(props);
|
| 9667 | this.state = { error: null };
|
| 9668 | }
|
| 9669 | static getDerivedStateFromError(error) {
|
| 9670 | return { error };
|
| 9671 | }
|
| 9672 | componentDidCatch(error, errorInfo) {
|
| 9673 | if (this.props.onError) {
|
| 9674 | this.props.onError(error, errorInfo);
|
| 9675 | } else {
|
| 9676 | console.error(
|
| 9677 | "<Await> caught the following error during render",
|
| 9678 | error,
|
| 9679 | errorInfo
|
| 9680 | );
|
| 9681 | }
|
| 9682 | }
|
| 9683 | render() {
|
| 9684 | let { children, errorElement, resolve } = this.props;
|
| 9685 | let promise = null;
|
| 9686 | let status = 0 ;
|
| 9687 | if (!(resolve instanceof Promise)) {
|
| 9688 | status = 1 ;
|
| 9689 | promise = Promise.resolve();
|
| 9690 | Object.defineProperty(promise, "_tracked", { get: () => true });
|
| 9691 | Object.defineProperty(promise, "_data", { get: () => resolve });
|
| 9692 | } else if (this.state.error) {
|
| 9693 | status = 2 ;
|
| 9694 | let renderError = this.state.error;
|
| 9695 | promise = Promise.reject().catch(() => {
|
| 9696 | });
|
| 9697 | Object.defineProperty(promise, "_tracked", { get: () => true });
|
| 9698 | Object.defineProperty(promise, "_error", { get: () => renderError });
|
| 9699 | } else if (resolve._tracked) {
|
| 9700 | promise = resolve;
|
| 9701 | status = "_error" in promise ? 2 : "_data" in promise ? 1 : 0 ;
|
| 9702 | } else {
|
| 9703 | status = 0 ;
|
| 9704 | Object.defineProperty(resolve, "_tracked", { get: () => true });
|
| 9705 | promise = resolve.then(
|
| 9706 | (data2) => Object.defineProperty(resolve, "_data", { get: () => data2 }),
|
| 9707 | (error) => {
|
| 9708 | _optionalChain([this, 'access', _150 => _150.props, 'access', _151 => _151.onError, 'optionalCall', _152 => _152(error)]);
|
| 9709 | Object.defineProperty(resolve, "_error", { get: () => error });
|
| 9710 | }
|
| 9711 | );
|
| 9712 | }
|
| 9713 | if (status === 2 && !errorElement) {
|
| 9714 | throw promise._error;
|
| 9715 | }
|
| 9716 | if (status === 2 ) {
|
| 9717 | return React9.createElement(AwaitContext.Provider, { value: promise, children: errorElement });
|
| 9718 | }
|
| 9719 | if (status === 1 ) {
|
| 9720 | return React9.createElement(AwaitContext.Provider, { value: promise, children });
|
| 9721 | }
|
| 9722 | throw promise;
|
| 9723 | }
|
| 9724 | };
|
| 9725 | function ResolveAwait({
|
| 9726 | children
|
| 9727 | }) {
|
| 9728 | let data2 = useAsyncValue();
|
| 9729 | let toRender = typeof children === "function" ? children(data2) : children;
|
| 9730 | return React9.createElement(React9.Fragment, null, toRender);
|
| 9731 | }
|
| 9732 | function createRoutesFromChildren(children, parentPath = []) {
|
| 9733 | let routes = [];
|
| 9734 | React9.Children.forEach(children, (element, index) => {
|
| 9735 | if (!React9.isValidElement(element)) {
|
| 9736 | return;
|
| 9737 | }
|
| 9738 | let treePath = [...parentPath, index];
|
| 9739 | if (element.type === React9.Fragment) {
|
| 9740 | routes.push.apply(
|
| 9741 | routes,
|
| 9742 | createRoutesFromChildren(element.props.children, treePath)
|
| 9743 | );
|
| 9744 | return;
|
| 9745 | }
|
| 9746 | invariant(
|
| 9747 | element.type === Route,
|
| 9748 | `[${typeof element.type === "string" ? element.type : element.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`
|
| 9749 | );
|
| 9750 | invariant(
|
| 9751 | !element.props.index || !element.props.children,
|
| 9752 | "An index route cannot have child routes."
|
| 9753 | );
|
| 9754 | let route = {
|
| 9755 | id: element.props.id || treePath.join("-"),
|
| 9756 | caseSensitive: element.props.caseSensitive,
|
| 9757 | element: element.props.element,
|
| 9758 | Component: element.props.Component,
|
| 9759 | index: element.props.index,
|
| 9760 | path: element.props.path,
|
| 9761 | middleware: element.props.middleware,
|
| 9762 | loader: element.props.loader,
|
| 9763 | action: element.props.action,
|
| 9764 | hydrateFallbackElement: element.props.hydrateFallbackElement,
|
| 9765 | HydrateFallback: element.props.HydrateFallback,
|
| 9766 | errorElement: element.props.errorElement,
|
| 9767 | ErrorBoundary: element.props.ErrorBoundary,
|
| 9768 | hasErrorBoundary: element.props.hasErrorBoundary === true || element.props.ErrorBoundary != null || element.props.errorElement != null,
|
| 9769 | shouldRevalidate: element.props.shouldRevalidate,
|
| 9770 | handle: element.props.handle,
|
| 9771 | lazy: element.props.lazy
|
| 9772 | };
|
| 9773 | if (element.props.children) {
|
| 9774 | route.children = createRoutesFromChildren(
|
| 9775 | element.props.children,
|
| 9776 | treePath
|
| 9777 | );
|
| 9778 | }
|
| 9779 | routes.push(route);
|
| 9780 | });
|
| 9781 | return routes;
|
| 9782 | }
|
| 9783 | var createRoutesFromElements = createRoutesFromChildren;
|
| 9784 | function renderMatches(matches) {
|
| 9785 | return _renderMatches(matches);
|
| 9786 | }
|
| 9787 | function useRouteComponentProps() {
|
| 9788 | return {
|
| 9789 | params: useParams(),
|
| 9790 | loaderData: useLoaderData(),
|
| 9791 | actionData: useActionData(),
|
| 9792 | matches: useMatches()
|
| 9793 | };
|
| 9794 | }
|
| 9795 | function WithComponentProps({
|
| 9796 | children
|
| 9797 | }) {
|
| 9798 | const props = useRouteComponentProps();
|
| 9799 | return React9.cloneElement(children, props);
|
| 9800 | }
|
| 9801 | function withComponentProps(Component4) {
|
| 9802 | return function WithComponentProps2() {
|
| 9803 | const props = useRouteComponentProps();
|
| 9804 | return React9.createElement(Component4, props);
|
| 9805 | };
|
| 9806 | }
|
| 9807 | function useHydrateFallbackProps() {
|
| 9808 | return {
|
| 9809 | params: useParams(),
|
| 9810 | loaderData: useLoaderData(),
|
| 9811 | actionData: useActionData()
|
| 9812 | };
|
| 9813 | }
|
| 9814 | function WithHydrateFallbackProps({
|
| 9815 | children
|
| 9816 | }) {
|
| 9817 | const props = useHydrateFallbackProps();
|
| 9818 | return React9.cloneElement(children, props);
|
| 9819 | }
|
| 9820 | function withHydrateFallbackProps(HydrateFallback) {
|
| 9821 | return function WithHydrateFallbackProps2() {
|
| 9822 | const props = useHydrateFallbackProps();
|
| 9823 | return React9.createElement(HydrateFallback, props);
|
| 9824 | };
|
| 9825 | }
|
| 9826 | function useErrorBoundaryProps() {
|
| 9827 | return {
|
| 9828 | params: useParams(),
|
| 9829 | loaderData: useLoaderData(),
|
| 9830 | actionData: useActionData(),
|
| 9831 | error: useRouteError()
|
| 9832 | };
|
| 9833 | }
|
| 9834 | function WithErrorBoundaryProps({
|
| 9835 | children
|
| 9836 | }) {
|
| 9837 | const props = useErrorBoundaryProps();
|
| 9838 | return React9.cloneElement(children, props);
|
| 9839 | }
|
| 9840 | function withErrorBoundaryProps(ErrorBoundary) {
|
| 9841 | return function WithErrorBoundaryProps2() {
|
| 9842 | const props = useErrorBoundaryProps();
|
| 9843 | return React9.createElement(ErrorBoundary, props);
|
| 9844 | };
|
| 9845 | }
|
| 9846 |
|
| 9847 |
|
| 9848 |
|
| 9849 |
|
| 9850 |
|
| 9851 |
|
| 9852 |
|
| 9853 |
|
| 9854 |
|
| 9855 |
|
| 9856 |
|
| 9857 |
|
| 9858 |
|
| 9859 |
|
| 9860 |
|
| 9861 |
|
| 9862 |
|
| 9863 |
|
| 9864 |
|
| 9865 |
|
| 9866 |
|
| 9867 |
|
| 9868 |
|
| 9869 |
|
| 9870 |
|
| 9871 |
|
| 9872 |
|
| 9873 |
|
| 9874 |
|
| 9875 |
|
| 9876 |
|
| 9877 |
|
| 9878 |
|
| 9879 |
|
| 9880 |
|
| 9881 |
|
| 9882 |
|
| 9883 |
|
| 9884 |
|
| 9885 |
|
| 9886 |
|
| 9887 |
|
| 9888 |
|
| 9889 |
|
| 9890 |
|
| 9891 |
|
| 9892 |
|
| 9893 |
|
| 9894 |
|
| 9895 |
|
| 9896 |
|
| 9897 |
|
| 9898 |
|
| 9899 |
|
| 9900 |
|
| 9901 |
|
| 9902 |
|
| 9903 |
|
| 9904 |
|
| 9905 |
|
| 9906 |
|
| 9907 |
|
| 9908 |
|
| 9909 |
|
| 9910 |
|
| 9911 |
|
| 9912 |
|
| 9913 |
|
| 9914 |
|
| 9915 |
|
| 9916 |
|
| 9917 |
|
| 9918 |
|
| 9919 |
|
| 9920 |
|
| 9921 |
|
| 9922 |
|
| 9923 |
|
| 9924 |
|
| 9925 |
|
| 9926 |
|
| 9927 |
|
| 9928 |
|
| 9929 |
|
| 9930 |
|
| 9931 |
|
| 9932 |
|
| 9933 |
|
| 9934 |
|
| 9935 |
|
| 9936 |
|
| 9937 |
|
| 9938 |
|
| 9939 |
|
| 9940 |
|
| 9941 |
|
| 9942 |
|
| 9943 |
|
| 9944 |
|
| 9945 |
|
| 9946 |
|
| 9947 |
|
| 9948 |
|
| 9949 |
|
| 9950 |
|
| 9951 |
|
| 9952 |
|
| 9953 |
|
| 9954 |
|
| 9955 |
|
| 9956 |
|
| 9957 |
|
| 9958 |
|
| 9959 |
|
| 9960 |
|
| 9961 |
|
| 9962 |
|
| 9963 |
|
| 9964 |
|
| 9965 |
|
| 9966 |
|
| 9967 |
|
| 9968 |
|
| 9969 |
|
| 9970 |
|
| 9971 |
|
| 9972 |
|
| 9973 | exports.Action = Action; exports.createMemoryHistory = createMemoryHistory; exports.createBrowserHistory = createBrowserHistory; exports.createHashHistory = createHashHistory; exports.invariant = invariant; exports.warning = warning; exports.createPath = createPath; exports.parsePath = parsePath; exports.createContext = createContext; exports.RouterContextProvider = RouterContextProvider; exports.convertRoutesToDataRoutes = convertRoutesToDataRoutes; exports.matchRoutes = matchRoutes; exports.generatePath = generatePath; exports.matchPath = matchPath; exports.stripBasename = stripBasename; exports.resolvePath = resolvePath; exports.resolveTo = resolveTo; exports.joinPaths = joinPaths; exports.data = data; exports.redirect = redirect; exports.redirectDocument = redirectDocument; exports.replace = replace; exports.ErrorResponseImpl = ErrorResponseImpl; exports.isRouteErrorResponse = isRouteErrorResponse; exports.parseToInfo = parseToInfo; exports.escapeHtml = escapeHtml; exports.encode = encode; exports.instrumentHandler = instrumentHandler; exports.IDLE_NAVIGATION = IDLE_NAVIGATION; exports.IDLE_FETCHER = IDLE_FETCHER; exports.IDLE_BLOCKER = IDLE_BLOCKER; exports.createRouter = createRouter; exports.createStaticHandler = createStaticHandler; exports.getStaticContextFromError = getStaticContextFromError; exports.invalidProtocols = invalidProtocols; exports.isDataWithResponseInit = isDataWithResponseInit; exports.isResponse = isResponse; exports.isRedirectStatusCode = isRedirectStatusCode; exports.isRedirectResponse = isRedirectResponse; exports.isMutationMethod = isMutationMethod; exports.createRequestInit = createRequestInit; exports.SingleFetchRedirectSymbol = SingleFetchRedirectSymbol; exports.SINGLE_FETCH_REDIRECT_STATUS = SINGLE_FETCH_REDIRECT_STATUS; exports.NO_BODY_STATUS_CODES = NO_BODY_STATUS_CODES; exports.StreamTransfer = StreamTransfer; exports.getTurboStreamSingleFetchDataStrategy = getTurboStreamSingleFetchDataStrategy; exports.getSingleFetchDataStrategyImpl = getSingleFetchDataStrategyImpl; exports.stripIndexParam = stripIndexParam; exports.singleFetchUrl = singleFetchUrl; exports.decodeViaTurboStream = decodeViaTurboStream; exports.DataRouterContext = DataRouterContext; exports.DataRouterStateContext = DataRouterStateContext; exports.RSCRouterContext = RSCRouterContext; exports.ViewTransitionContext = ViewTransitionContext; exports.FetchersContext = FetchersContext; exports.AwaitContextProvider = AwaitContextProvider; exports.NavigationContext = NavigationContext; exports.LocationContext = LocationContext; exports.RouteContext = RouteContext; exports.ENABLE_DEV_WARNINGS = ENABLE_DEV_WARNINGS; exports.warnOnce = warnOnce; exports.decodeRedirectErrorDigest = decodeRedirectErrorDigest; exports.decodeRouteErrorResponseDigest = decodeRouteErrorResponseDigest; exports.useHref = useHref; exports.useInRouterContext = useInRouterContext; exports.useLocation = useLocation; exports.useNavigationType = useNavigationType; exports.useMatch = useMatch; exports.useNavigate = useNavigate; exports.useOutletContext = useOutletContext; exports.useOutlet = useOutlet; exports.useParams = useParams; exports.useResolvedPath = useResolvedPath; exports.useRoutes = useRoutes; exports.useRouteId = useRouteId; exports.useNavigation = useNavigation; exports.useRevalidator = useRevalidator; exports.useMatches = useMatches; exports.useLoaderData = useLoaderData; exports.useRouteLoaderData = useRouteLoaderData; exports.useActionData = useActionData; exports.useRouteError = useRouteError; exports.useAsyncValue = useAsyncValue; exports.useAsyncError = useAsyncError; exports.useBlocker = useBlocker; exports.useRoute = useRoute; exports.RemixErrorBoundary = RemixErrorBoundary; exports.createServerRoutes = createServerRoutes; exports.createClientRoutesWithHMRRevalidationOptOut = createClientRoutesWithHMRRevalidationOptOut; exports.noActionDefinedError = noActionDefinedError; exports.createClientRoutes = createClientRoutes; exports.shouldHydrateRouteLoader = shouldHydrateRouteLoader; exports.getPatchRoutesOnNavigationFunction = getPatchRoutesOnNavigationFunction; exports.useFogOFWarDiscovery = useFogOFWarDiscovery; exports.getManifestPath = getManifestPath; exports.FrameworkContext = FrameworkContext; exports.usePrefetchBehavior = usePrefetchBehavior; exports.CRITICAL_CSS_DATA_ATTRIBUTE = CRITICAL_CSS_DATA_ATTRIBUTE; exports.Links = Links; exports.PrefetchPageLinks = PrefetchPageLinks; exports.Meta = Meta; exports.setIsHydrated = setIsHydrated; exports.Scripts = Scripts; exports.mergeRefs = mergeRefs; exports.mapRouteProperties = mapRouteProperties; exports.hydrationRouteProperties = hydrationRouteProperties; exports.createMemoryRouter = createMemoryRouter; exports.RouterProvider = RouterProvider; exports.DataRoutes = DataRoutes; exports.MemoryRouter = MemoryRouter; exports.Navigate = Navigate; exports.Outlet = Outlet; exports.Route = Route; exports.Router = Router; exports.Routes = Routes; exports.Await = Await; exports.createRoutesFromChildren = createRoutesFromChildren; exports.createRoutesFromElements = createRoutesFromElements; exports.renderMatches = renderMatches; exports.WithComponentProps = WithComponentProps; exports.withComponentProps = withComponentProps; exports.WithHydrateFallbackProps = WithHydrateFallbackProps; exports.withHydrateFallbackProps = withHydrateFallbackProps; exports.WithErrorBoundaryProps = WithErrorBoundaryProps; exports.withErrorBoundaryProps = withErrorBoundaryProps;
|