react-router 7.15.1 → 7.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/CHANGELOG.md +73 -2
  2. package/dist/development/{browser-BOdXz9dK.d.ts → browser-7x6a6gQP.d.ts} +2 -2
  3. package/dist/development/{browser-3AnU12UI.d.mts → browser-CiGxXXOl.d.mts} +2 -2
  4. package/dist/development/{chunk-D6LUOGOQ.js → chunk-2ZBLYC7V.js} +265 -57
  5. package/dist/development/{chunk-4N6VE7H7.mjs → chunk-6KYCQHYJ.mjs} +268 -60
  6. package/dist/{production/chunk-Y6IFXO7V.js → development/chunk-IFHLIXZW.js} +7 -7
  7. package/dist/development/{chunk-RJYABSBD.mjs → chunk-JAHXRPFV.mjs} +71 -122
  8. package/dist/development/{chunk-66UKHEGQ.js → chunk-NDF5KBLP.js} +112 -108
  9. package/dist/{production/context-ByvtofY2.d.mts → development/context-BlYKn1tE.d.mts} +24 -5
  10. package/dist/development/{data-BqZ2x964.d.ts → data-CjO11-hU.d.ts} +10 -2
  11. package/dist/{production/data-BVUf681J.d.mts → development/data-DEjBmEfD.d.mts} +10 -2
  12. package/dist/development/dom-export.d.mts +4 -4
  13. package/dist/development/dom-export.d.ts +4 -4
  14. package/dist/development/dom-export.js +61 -46
  15. package/dist/development/dom-export.mjs +39 -24
  16. package/dist/{production/index-react-server-client-BS5F89FR.d.ts → development/index-react-server-client-BaaZU3sM.d.ts} +32 -9
  17. package/dist/{production/index-react-server-client-DY04-103.d.mts → development/index-react-server-client-KK-TR-t7.d.mts} +20 -6
  18. package/dist/development/index-react-server-client.d.mts +3 -3
  19. package/dist/development/index-react-server-client.d.ts +3 -3
  20. package/dist/development/index-react-server-client.js +4 -4
  21. package/dist/development/index-react-server-client.mjs +2 -2
  22. package/dist/development/index-react-server.d.mts +20 -2
  23. package/dist/development/index-react-server.d.ts +20 -2
  24. package/dist/development/index-react-server.js +212 -144
  25. package/dist/development/index-react-server.mjs +211 -143
  26. package/dist/development/index.d.mts +22 -15
  27. package/dist/development/index.d.ts +22 -15
  28. package/dist/development/index.js +160 -211
  29. package/dist/development/index.mjs +3 -5
  30. package/dist/{production/instrumentation-cRWWLfsU.d.ts → development/instrumentation-CPkMwccd.d.ts} +12 -2
  31. package/dist/development/lib/types/internal.d.mts +2 -2
  32. package/dist/development/lib/types/internal.d.ts +2 -2
  33. package/dist/development/lib/types/internal.js +1 -1
  34. package/dist/development/lib/types/internal.mjs +1 -1
  35. package/dist/development/{register-Df8okEea.d.mts → register-CmkRspdl.d.mts} +1 -1
  36. package/dist/development/{register-Bsscfj79.d.ts → register-roq_0qYo.d.ts} +1 -1
  37. package/dist/production/{browser-BOdXz9dK.d.ts → browser-7x6a6gQP.d.ts} +2 -2
  38. package/dist/production/{browser-3AnU12UI.d.mts → browser-CiGxXXOl.d.mts} +2 -2
  39. package/dist/production/{chunk-PNZCCTKT.js → chunk-75HN637G.js} +112 -108
  40. package/dist/production/{chunk-JAKZPQZC.mjs → chunk-7RTFRKQW.mjs} +268 -60
  41. package/dist/production/{chunk-HUBUW7R3.js → chunk-HNBICOIU.js} +265 -57
  42. package/dist/production/{chunk-6S4627ZB.mjs → chunk-IAM5GYT3.mjs} +71 -122
  43. package/dist/{development/chunk-4YRVXM2U.js → production/chunk-K3NA4NUH.js} +7 -7
  44. package/dist/{development/context-ByvtofY2.d.mts → production/context-BlYKn1tE.d.mts} +24 -5
  45. package/dist/production/{data-BqZ2x964.d.ts → data-CjO11-hU.d.ts} +10 -2
  46. package/dist/{development/data-BVUf681J.d.mts → production/data-DEjBmEfD.d.mts} +10 -2
  47. package/dist/production/dom-export.d.mts +4 -4
  48. package/dist/production/dom-export.d.ts +4 -4
  49. package/dist/production/dom-export.js +61 -46
  50. package/dist/production/dom-export.mjs +39 -24
  51. package/dist/{development/index-react-server-client-BS5F89FR.d.ts → production/index-react-server-client-BaaZU3sM.d.ts} +32 -9
  52. package/dist/{development/index-react-server-client-DY04-103.d.mts → production/index-react-server-client-KK-TR-t7.d.mts} +20 -6
  53. package/dist/production/index-react-server-client.d.mts +3 -3
  54. package/dist/production/index-react-server-client.d.ts +3 -3
  55. package/dist/production/index-react-server-client.js +4 -4
  56. package/dist/production/index-react-server-client.mjs +2 -2
  57. package/dist/production/index-react-server.d.mts +20 -2
  58. package/dist/production/index-react-server.d.ts +20 -2
  59. package/dist/production/index-react-server.js +212 -144
  60. package/dist/production/index-react-server.mjs +211 -143
  61. package/dist/production/index.d.mts +22 -15
  62. package/dist/production/index.d.ts +22 -15
  63. package/dist/production/index.js +160 -211
  64. package/dist/production/index.mjs +3 -5
  65. package/dist/{development/instrumentation-cRWWLfsU.d.ts → production/instrumentation-CPkMwccd.d.ts} +12 -2
  66. package/dist/production/lib/types/internal.d.mts +2 -2
  67. package/dist/production/lib/types/internal.d.ts +2 -2
  68. package/dist/production/lib/types/internal.js +1 -1
  69. package/dist/production/lib/types/internal.mjs +1 -1
  70. package/dist/production/{register-Df8okEea.d.mts → register-CmkRspdl.d.mts} +1 -1
  71. package/dist/production/{register-Bsscfj79.d.ts → register-roq_0qYo.d.ts} +1 -1
  72. package/docs/explanation/backend-for-frontend.md +50 -0
  73. package/docs/explanation/code-splitting.md +61 -0
  74. package/docs/explanation/concurrency.md +135 -0
  75. package/docs/explanation/form-vs-fetcher.md +292 -0
  76. package/docs/explanation/hot-module-replacement.md +137 -0
  77. package/docs/explanation/hydration.md +14 -0
  78. package/docs/explanation/index-query-param.md +86 -0
  79. package/docs/explanation/index.md +4 -0
  80. package/docs/explanation/lazy-route-discovery.md +78 -0
  81. package/docs/explanation/location.md +6 -0
  82. package/docs/explanation/progressive-enhancement.md +150 -0
  83. package/docs/explanation/race-conditions.md +88 -0
  84. package/docs/explanation/react-transitions.md +160 -0
  85. package/docs/explanation/route-matching.md +7 -0
  86. package/docs/explanation/server-client-execution.md +4 -0
  87. package/docs/explanation/sessions-and-cookies.md +465 -0
  88. package/docs/explanation/special-files.md +16 -0
  89. package/docs/explanation/state-management.md +524 -0
  90. package/docs/explanation/styling.md +87 -0
  91. package/docs/explanation/type-safety.md +82 -0
  92. package/docs/how-to/accessibility.md +44 -0
  93. package/docs/how-to/client-data.md +199 -0
  94. package/docs/how-to/data-strategy.md +317 -0
  95. package/docs/how-to/error-boundary.md +231 -0
  96. package/docs/how-to/error-reporting.md +142 -0
  97. package/docs/how-to/fetchers.md +307 -0
  98. package/docs/how-to/file-route-conventions.md +410 -0
  99. package/docs/how-to/file-uploads.md +217 -0
  100. package/docs/how-to/form-validation.md +120 -0
  101. package/docs/how-to/headers.md +165 -0
  102. package/docs/how-to/index.md +4 -0
  103. package/docs/how-to/instrumentation.md +556 -0
  104. package/docs/how-to/meta.md +40 -0
  105. package/docs/how-to/middleware.md +763 -0
  106. package/docs/how-to/navigation-blocking.md +233 -0
  107. package/docs/how-to/optimize-revalidation.md +12 -0
  108. package/docs/how-to/pre-rendering.md +225 -0
  109. package/docs/how-to/presets.md +103 -0
  110. package/docs/how-to/react-server-components.md +899 -0
  111. package/docs/how-to/resource-routes.md +126 -0
  112. package/docs/how-to/route-module-type-safety.md +100 -0
  113. package/docs/how-to/search-params.md +4 -0
  114. package/docs/how-to/security.md +32 -0
  115. package/docs/how-to/server-bundles.md +66 -0
  116. package/docs/how-to/spa.md +120 -0
  117. package/docs/how-to/status.md +63 -0
  118. package/docs/how-to/suspense.md +132 -0
  119. package/docs/how-to/using-handle.md +117 -0
  120. package/docs/how-to/view-transitions.md +237 -0
  121. package/docs/how-to/webhook.md +50 -0
  122. package/docs/index.md +39 -0
  123. package/docs/start/data/actions.md +138 -0
  124. package/docs/start/data/custom.md +198 -0
  125. package/docs/start/data/data-loading.md +44 -0
  126. package/docs/start/data/index.md +4 -0
  127. package/docs/start/data/installation.md +56 -0
  128. package/docs/start/data/navigating.md +12 -0
  129. package/docs/start/data/pending-ui.md +12 -0
  130. package/docs/start/data/route-object.md +268 -0
  131. package/docs/start/data/routing.md +281 -0
  132. package/docs/start/data/testing.md +8 -0
  133. package/docs/start/declarative/index.md +4 -0
  134. package/docs/start/declarative/installation.md +43 -0
  135. package/docs/start/declarative/navigating.md +133 -0
  136. package/docs/start/declarative/routing.md +237 -0
  137. package/docs/start/declarative/url-values.md +65 -0
  138. package/docs/start/framework/actions.md +174 -0
  139. package/docs/start/framework/data-loading.md +201 -0
  140. package/docs/start/framework/deploying.md +100 -0
  141. package/docs/start/framework/index.md +4 -0
  142. package/docs/start/framework/installation.md +41 -0
  143. package/docs/start/framework/navigating.md +182 -0
  144. package/docs/start/framework/pending-ui.md +142 -0
  145. package/docs/start/framework/rendering.md +59 -0
  146. package/docs/start/framework/route-module.md +527 -0
  147. package/docs/start/framework/routing.md +362 -0
  148. package/docs/start/framework/testing.md +133 -0
  149. package/docs/start/index.md +4 -0
  150. package/docs/start/modes.md +201 -0
  151. package/docs/upgrading/component-routes.md +363 -0
  152. package/docs/upgrading/future.md +490 -0
  153. package/docs/upgrading/index.md +4 -0
  154. package/docs/upgrading/remix.md +403 -0
  155. package/docs/upgrading/router-provider.md +442 -0
  156. package/docs/upgrading/v6.md +382 -0
  157. package/package.json +2 -1
@@ -1,12 +1,12 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
- import * as React2 from 'react';
2
+ import * as React3 from 'react';
3
3
  import { splitCookiesString } from 'set-cookie-parser';
4
4
  import { UNSAFE_AwaitContextProvider, UNSAFE_WithComponentProps, Outlet as Outlet$1, UNSAFE_WithErrorBoundaryProps, UNSAFE_WithHydrateFallbackProps } from 'react-router/internal/react-server-client';
5
5
  export { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, unstable_HistoryRouter } from 'react-router/internal/react-server-client';
6
6
  import { serialize, parse } from 'cookie';
7
7
 
8
8
  /**
9
- * react-router v7.15.1
9
+ * react-router v7.18.5
10
10
  *
11
11
  * Copyright (c) Remix Software Inc.
12
12
  *
@@ -22,6 +22,9 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
22
22
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
23
23
  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);
24
24
 
25
+ // lib/router/url.ts
26
+ var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|[\\/]{2})/i;
27
+
25
28
  // lib/router/history.ts
26
29
  function invariant(value, message) {
27
30
  if (value === false || value === null || typeof value === "undefined") {
@@ -481,7 +484,18 @@ function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "",
481
484
  branches.push({
482
485
  path,
483
486
  score: computeScore(path, route.index),
484
- routesMeta
487
+ routesMeta: routesMeta.map((meta2, i) => {
488
+ let [matcher, params] = compilePath(
489
+ meta2.relativePath,
490
+ meta2.caseSensitive,
491
+ i === routesMeta.length - 1
492
+ );
493
+ return {
494
+ ...meta2,
495
+ matcher,
496
+ compiledParams: params
497
+ };
498
+ })
485
499
  });
486
500
  };
487
501
  routes.forEach((route, index) => {
@@ -570,9 +584,19 @@ function matchRouteBranch(branch, pathname, allowPartial = false) {
570
584
  let meta = routesMeta[i];
571
585
  let end = i === routesMeta.length - 1;
572
586
  let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
573
- let match = matchPath(
574
- { path: meta.relativePath, caseSensitive: meta.caseSensitive, end },
575
- remainingPathname
587
+ let pattern = {
588
+ path: meta.relativePath,
589
+ caseSensitive: meta.caseSensitive,
590
+ end
591
+ };
592
+ let match = (
593
+ // Use precomputed matcher if it exists
594
+ meta.matcher && meta.compiledParams ? matchPathImpl(
595
+ pattern,
596
+ remainingPathname,
597
+ meta.matcher,
598
+ meta.compiledParams
599
+ ) : matchPath(pattern, remainingPathname)
576
600
  );
577
601
  let route = meta.route;
578
602
  if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
@@ -613,16 +637,22 @@ function matchPath(pattern, pathname) {
613
637
  pattern.caseSensitive,
614
638
  pattern.end
615
639
  );
640
+ return matchPathImpl(pattern, pathname, matcher, compiledParams);
641
+ }
642
+ function matchPathImpl(pattern, pathname, matcher, compiledParams) {
616
643
  let match = pathname.match(matcher);
617
644
  if (!match) return null;
618
645
  let matchedPathname = match[0];
619
- let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
646
+ let pathnameBase = removeTrailingSlash(matchedPathname, 1);
620
647
  let captureGroups = match.slice(1);
621
648
  let params = compiledParams.reduce(
622
649
  (memo, { paramName, isOptional }, index) => {
623
650
  if (paramName === "*") {
624
651
  let splatValue = captureGroups[index] || "";
625
- pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
652
+ pathnameBase = removeTrailingSlash(
653
+ matchedPathname.slice(0, matchedPathname.length - splatValue.length),
654
+ 1
655
+ );
626
656
  }
627
657
  const value = captureGroups[index];
628
658
  if (isOptional && !value) {
@@ -701,7 +731,6 @@ function prependBasename({
701
731
  }) {
702
732
  return pathname === "/" ? basename : joinPaths([basename, pathname]);
703
733
  }
704
- var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
705
734
  var isAbsoluteUrl = (url) => ABSOLUTE_URL_REGEX.test(url);
706
735
  function resolvePath(to, fromPathname = "/") {
707
736
  let {
@@ -712,7 +741,7 @@ function resolvePath(to, fromPathname = "/") {
712
741
  let pathname;
713
742
  if (toPathname) {
714
743
  toPathname = removeDoubleSlashes(toPathname);
715
- if (toPathname.startsWith("/")) {
744
+ if (toPathname.startsWith("/") || toPathname.startsWith("\\")) {
716
745
  pathname = resolvePathname(toPathname.substring(1), "/");
717
746
  } else {
718
747
  pathname = resolvePathname(toPathname, fromPathname);
@@ -798,9 +827,15 @@ function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = fal
798
827
  }
799
828
  return path;
800
829
  }
801
- var removeDoubleSlashes = (path) => path.replace(/\/\/+/g, "/");
830
+ var removeDoubleSlashes = (path) => path.replace(/[\\/]{2,}/g, "/");
802
831
  var joinPaths = (paths) => removeDoubleSlashes(paths.join("/"));
803
- var removeTrailingSlash = (path) => path.replace(/\/+$/, "");
832
+ function removeTrailingSlash(path, minLength = 0) {
833
+ let end = path.length;
834
+ while (end > minLength && path.charCodeAt(end - 1) === 47) {
835
+ end--;
836
+ }
837
+ return end === path.length ? path : path.slice(0, end);
838
+ }
804
839
  var normalizePathname = (pathname) => removeTrailingSlash(pathname).replace(/^\/*/, "/");
805
840
  var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
806
841
  var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
@@ -910,6 +945,10 @@ function createStaticHandler(routes, opts) {
910
945
  manifest
911
946
  );
912
947
  let routeBranches = flattenAndRankRoutes(dataRoutes);
948
+ let matchCost = routeBranches.reduce(
949
+ (total, branch) => total + branch.routesMeta.length,
950
+ 0
951
+ );
913
952
  async function query(request, {
914
953
  requestContext,
915
954
  filterMatchesToLoad,
@@ -1529,6 +1568,7 @@ function createStaticHandler(routes, opts) {
1529
1568
  }
1530
1569
  return {
1531
1570
  dataRoutes,
1571
+ _matchCost: matchCost,
1532
1572
  _internalRouteBranches: routeBranches,
1533
1573
  query,
1534
1574
  queryRoute
@@ -2448,29 +2488,99 @@ function prependCookies(parentHeaders, childHeaders) {
2448
2488
  }
2449
2489
  var SINGLE_FETCH_REDIRECT_STATUS = 202;
2450
2490
 
2491
+ // lib/server-runtime/warnings.ts
2492
+ var alreadyWarned = {};
2493
+ function warnOnce(condition, message) {
2494
+ if (!condition && !alreadyWarned[message]) {
2495
+ alreadyWarned[message] = true;
2496
+ console.warn(message);
2497
+ }
2498
+ }
2499
+
2500
+ // lib/errors.ts
2501
+ var ERROR_DIGEST_BASE = "REACT_ROUTER_ERROR";
2502
+ var ERROR_DIGEST_REDIRECT = "REDIRECT";
2503
+ var ERROR_DIGEST_ROUTE_ERROR_RESPONSE = "ROUTE_ERROR_RESPONSE";
2504
+ function createRedirectErrorDigest(response) {
2505
+ return `${ERROR_DIGEST_BASE}:${ERROR_DIGEST_REDIRECT}:${JSON.stringify({
2506
+ status: response.status,
2507
+ statusText: response.statusText,
2508
+ location: response.headers.get("Location"),
2509
+ reloadDocument: response.headers.get("X-Remix-Reload-Document") === "true",
2510
+ replace: response.headers.get("X-Remix-Replace") === "true"
2511
+ })}`;
2512
+ }
2513
+ function createRouteErrorResponseDigest(response) {
2514
+ let status = 500;
2515
+ let statusText = "";
2516
+ let data2;
2517
+ if (isDataWithResponseInit(response)) {
2518
+ status = response.init?.status ?? status;
2519
+ statusText = response.init?.statusText ?? statusText;
2520
+ data2 = response.data;
2521
+ } else {
2522
+ status = response.status;
2523
+ statusText = response.statusText;
2524
+ data2 = void 0;
2525
+ }
2526
+ return `${ERROR_DIGEST_BASE}:${ERROR_DIGEST_ROUTE_ERROR_RESPONSE}:${JSON.stringify(
2527
+ {
2528
+ status,
2529
+ statusText,
2530
+ data: data2
2531
+ }
2532
+ )}`;
2533
+ }
2534
+
2535
+ // lib/dom/ssr/fog-of-war.ts
2536
+ var URL_LIMIT = 7680;
2537
+ function getPathsWithAncestors(paths) {
2538
+ let result = /* @__PURE__ */ new Set();
2539
+ paths.forEach((path) => {
2540
+ if (!path.startsWith("/")) {
2541
+ path = `/${path}`;
2542
+ }
2543
+ for (let i = 1; i < path.length; i++) {
2544
+ if (path[i] === "/") {
2545
+ result.add(path.slice(0, i));
2546
+ }
2547
+ }
2548
+ result.add(path);
2549
+ });
2550
+ return Array.from(result);
2551
+ }
2552
+ var MANIFEST_MATCH_COST_LIMIT = 5e4;
2553
+ var MANIFEST_MATCH_COST_SEGMENT_THRESHOLD = 10;
2554
+ function shouldUseInitialRouteDiscovery(pathname, matchCost = 0) {
2555
+ let segmentCount = pathname.split("/").length - 1;
2556
+ let ancestorCount = Math.max(segmentCount - 1, 0);
2557
+ return ancestorCount * pathname.length + 1 > URL_LIMIT || segmentCount > MANIFEST_MATCH_COST_SEGMENT_THRESHOLD && segmentCount * matchCost > MANIFEST_MATCH_COST_LIMIT;
2558
+ }
2559
+
2451
2560
  // lib/actions.ts
2452
- function throwIfPotentialCSRFAttack(headers, allowedActionOrigins) {
2453
- let originHeader = headers.get("origin");
2561
+ function throwIfPotentialCSRFAttack(request, allowedActionOrigins) {
2562
+ let originHeader = request.headers.get("origin");
2454
2563
  let originDomain = null;
2564
+ let originUrl = null;
2455
2565
  try {
2456
- originDomain = typeof originHeader === "string" && originHeader !== "null" ? new URL(originHeader).host : originHeader;
2566
+ if (typeof originHeader === "string" && originHeader !== "null") {
2567
+ originUrl = new URL(originHeader);
2568
+ originDomain = originUrl.host;
2569
+ } else {
2570
+ originDomain = originHeader;
2571
+ }
2457
2572
  } catch {
2458
2573
  throw new Error(
2459
2574
  `\`origin\` header is not a valid URL. Aborting the action.`
2460
2575
  );
2461
2576
  }
2462
- let host = parseHostHeader(headers);
2463
- if (originDomain && (!host || originDomain !== host.value)) {
2577
+ let requestUrl = new URL(request.url);
2578
+ let originMatchesRequest = originUrl ? originUrl.origin === requestUrl.origin : originDomain === requestUrl.host;
2579
+ if (originDomain && !originMatchesRequest) {
2464
2580
  if (!isAllowedOrigin(originDomain, allowedActionOrigins)) {
2465
- if (host) {
2466
- throw new Error(
2467
- `${host.type} header does not match \`origin\` header from a forwarded action request. Aborting the action.`
2468
- );
2469
- } else {
2470
- throw new Error(
2471
- "`x-forwarded-host` or `host` headers are not provided. One of these is needed to compare the `origin` header from a forwarded action request. Aborting the action."
2472
- );
2473
- }
2581
+ throw new Error(
2582
+ "The `request.url` origin does not match `origin` header from a forwarded action request. Aborting the action."
2583
+ );
2474
2584
  }
2475
2585
  }
2476
2586
  }
@@ -2518,53 +2628,6 @@ function isAllowedOrigin(originDomain, allowedActionOrigins = []) {
2518
2628
  (allowedOrigin) => allowedOrigin && (allowedOrigin === originDomain || matchWildcardDomain(originDomain, allowedOrigin))
2519
2629
  );
2520
2630
  }
2521
- function parseHostHeader(headers) {
2522
- let forwardedHostHeader = headers.get("x-forwarded-host");
2523
- let forwardedHostValue = forwardedHostHeader?.split(",")[0]?.trim();
2524
- let hostHeader = headers.get("host");
2525
- return forwardedHostValue ? {
2526
- type: "x-forwarded-host",
2527
- value: forwardedHostValue
2528
- } : hostHeader ? {
2529
- type: "host",
2530
- value: hostHeader
2531
- } : void 0;
2532
- }
2533
-
2534
- // lib/errors.ts
2535
- var ERROR_DIGEST_BASE = "REACT_ROUTER_ERROR";
2536
- var ERROR_DIGEST_REDIRECT = "REDIRECT";
2537
- var ERROR_DIGEST_ROUTE_ERROR_RESPONSE = "ROUTE_ERROR_RESPONSE";
2538
- function createRedirectErrorDigest(response) {
2539
- return `${ERROR_DIGEST_BASE}:${ERROR_DIGEST_REDIRECT}:${JSON.stringify({
2540
- status: response.status,
2541
- statusText: response.statusText,
2542
- location: response.headers.get("Location"),
2543
- reloadDocument: response.headers.get("X-Remix-Reload-Document") === "true",
2544
- replace: response.headers.get("X-Remix-Replace") === "true"
2545
- })}`;
2546
- }
2547
- function createRouteErrorResponseDigest(response) {
2548
- let status = 500;
2549
- let statusText = "";
2550
- let data2;
2551
- if (isDataWithResponseInit(response)) {
2552
- status = response.init?.status ?? status;
2553
- statusText = response.init?.statusText ?? statusText;
2554
- data2 = response.data;
2555
- } else {
2556
- status = response.status;
2557
- statusText = response.statusText;
2558
- data2 = void 0;
2559
- }
2560
- return `${ERROR_DIGEST_BASE}:${ERROR_DIGEST_ROUTE_ERROR_RESPONSE}:${JSON.stringify(
2561
- {
2562
- status,
2563
- statusText,
2564
- data: data2
2565
- }
2566
- )}`;
2567
- }
2568
2631
 
2569
2632
  // lib/server-runtime/urls.ts
2570
2633
  function getNormalizedPath(request, basename, future) {
@@ -2636,7 +2699,7 @@ var replace2 = (...args) => {
2636
2699
  };
2637
2700
  var cachedResolvePromise = (
2638
2701
  // @ts-expect-error - on 18 types, requires 19.
2639
- React2.cache(async (resolve) => {
2702
+ React3.cache(async (resolve) => {
2640
2703
  return Promise.allSettled([resolve]).then((r) => r[0]);
2641
2704
  })
2642
2705
  );
@@ -2651,13 +2714,13 @@ var Await = async ({
2651
2714
  throw resolved.reason;
2652
2715
  }
2653
2716
  if (resolved.status === "rejected") {
2654
- return React2.createElement(UNSAFE_AwaitContextProvider, {
2655
- children: React2.createElement(React2.Fragment, null, errorElement),
2717
+ return React3.createElement(UNSAFE_AwaitContextProvider, {
2718
+ children: React3.createElement(React3.Fragment, null, errorElement),
2656
2719
  value: { _tracked: true, _error: resolved.reason }
2657
2720
  });
2658
2721
  }
2659
2722
  const toRender = typeof children === "function" ? children(resolved.value) : children;
2660
- return React2.createElement(UNSAFE_AwaitContextProvider, {
2723
+ return React3.createElement(UNSAFE_AwaitContextProvider, {
2661
2724
  children: toRender,
2662
2725
  value: { _tracked: true, _data: resolved.value }
2663
2726
  });
@@ -2746,6 +2809,13 @@ async function matchRSCServerRequest({
2746
2809
  return response;
2747
2810
  }
2748
2811
  async function generateManifestResponse(routes, basename, request, generateResponse, temporaryReferences, routeDiscovery) {
2812
+ let url = new URL(request.url);
2813
+ if (url.toString().length > URL_LIMIT) {
2814
+ return new Response(null, {
2815
+ statusText: "Bad Request",
2816
+ status: 400
2817
+ });
2818
+ }
2749
2819
  if (routeDiscovery?.mode === "initial") {
2750
2820
  let payload2 = {
2751
2821
  type: "manifest",
@@ -2763,7 +2833,6 @@ async function generateManifestResponse(routes, basename, request, generateRespo
2763
2833
  { temporaryReferences, onError: defaultOnError }
2764
2834
  );
2765
2835
  }
2766
- let url = new URL(request.url);
2767
2836
  let pathParam = url.searchParams.get("paths");
2768
2837
  let pathnames = pathParam ? pathParam.split(",").filter(Boolean) : [url.pathname.replace(/\.manifest$/, "")];
2769
2838
  let routeIds = /* @__PURE__ */ new Set();
@@ -2966,7 +3035,17 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
2966
3035
  let potentialCSRFAttackError;
2967
3036
  if (isMutationMethod(request.method)) {
2968
3037
  try {
2969
- throwIfPotentialCSRFAttack(request.headers, allowedActionOrigins);
3038
+ throwIfPotentialCSRFAttack(request, allowedActionOrigins);
3039
+ } catch (error) {
3040
+ onError?.(error);
3041
+ potentialCSRFAttackError = error;
3042
+ request = new Request(request.url, {
3043
+ method: "GET",
3044
+ headers: request.headers,
3045
+ signal: request.signal
3046
+ });
3047
+ }
3048
+ if (!potentialCSRFAttackError) {
2970
3049
  ctx.runningAction = true;
2971
3050
  let result2 = await processServerAction(
2972
3051
  request,
@@ -3006,15 +3085,11 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
3006
3085
  void 0
3007
3086
  );
3008
3087
  }
3009
- } catch (error) {
3010
- potentialCSRFAttackError = error;
3011
3088
  }
3012
3089
  }
3013
3090
  let staticContext = await query(
3014
3091
  request,
3015
- skipRevalidation || !!potentialCSRFAttackError ? {
3016
- filterMatchesToLoad: () => false
3017
- } : void 0
3092
+ skipRevalidation ? { filterMatchesToLoad: () => false } : void 0
3018
3093
  );
3019
3094
  if (isResponse(staticContext)) {
3020
3095
  return generateRedirectResponse(
@@ -3046,7 +3121,8 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
3046
3121
  temporaryReferences,
3047
3122
  skipRevalidation,
3048
3123
  ctx.redirect?.headers,
3049
- routeDiscovery
3124
+ routeDiscovery,
3125
+ staticHandler._matchCost
3050
3126
  );
3051
3127
  }
3052
3128
  })
@@ -3096,7 +3172,7 @@ function generateRedirectResponse(response, actionResult, basename, isDataReques
3096
3172
  { temporaryReferences, onError: defaultOnError }
3097
3173
  );
3098
3174
  }
3099
- async function generateStaticContextResponse(routes, basename, generateResponse, statusCode, routeIdsToLoad, isDataRequest, isSubmission, actionResult, formState, staticContext, temporaryReferences, skipRevalidation, sideEffectRedirectHeaders, routeDiscovery) {
3175
+ async function generateStaticContextResponse(routes, basename, generateResponse, statusCode, routeIdsToLoad, isDataRequest, isSubmission, actionResult, formState, staticContext, temporaryReferences, skipRevalidation, sideEffectRedirectHeaders, routeDiscovery, matchCost) {
3100
3176
  statusCode = staticContext.statusCode ?? statusCode;
3101
3177
  if (staticContext.errors) {
3102
3178
  staticContext.errors = Object.fromEntries(
@@ -3138,7 +3214,8 @@ async function generateStaticContextResponse(routes, basename, generateResponse,
3138
3214
  routeIdsToLoad,
3139
3215
  isDataRequest,
3140
3216
  staticContext,
3141
- routeDiscovery
3217
+ routeDiscovery,
3218
+ matchCost
3142
3219
  );
3143
3220
  let payload;
3144
3221
  if (actionResult) {
@@ -3165,7 +3242,7 @@ async function generateStaticContextResponse(routes, basename, generateResponse,
3165
3242
  { temporaryReferences, onError: defaultOnError }
3166
3243
  );
3167
3244
  }
3168
- async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToLoad, isDataRequest, staticContext, routeDiscovery) {
3245
+ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToLoad, isDataRequest, staticContext, routeDiscovery, matchCost) {
3169
3246
  let deepestRenderedRouteIdx = staticContext.matches.length - 1;
3170
3247
  let parentIds = {};
3171
3248
  staticContext.matches.forEach((m, i) => {
@@ -3189,18 +3266,27 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
3189
3266
  });
3190
3267
  })
3191
3268
  );
3192
- let patches = routeDiscovery?.mode === "initial" && !isDataRequest ? getAllRoutePatches(routes).then(
3193
- (patches2) => patches2.filter(
3194
- (patch) => !staticContext.matches.some((m) => m.route.id === patch.id)
3195
- )
3196
- ) : getAdditionalRoutePatches(
3197
- [staticContext.location.pathname],
3198
- routes,
3199
- basename,
3200
- staticContext.matches.map((m) => m.route.id)
3201
- );
3269
+ let pathname = staticContext.location.pathname;
3270
+ let useInitialRouteDiscovery = routeDiscovery?.mode === "initial" && !isDataRequest || shouldUseInitialRouteDiscovery(pathname, matchCost);
3271
+ let patches;
3272
+ if (useInitialRouteDiscovery) {
3273
+ patches = getAllRoutePatches(routes).then(
3274
+ (patches2) => patches2.filter(
3275
+ (patch) => !staticContext.matches.some((m) => m.route.id === patch.id)
3276
+ )
3277
+ );
3278
+ } else {
3279
+ patches = getAdditionalRoutePatches(
3280
+ // The full pathname is last and its matches are already in the payload.
3281
+ getPathsWithAncestors([pathname]).slice(0, -1),
3282
+ routes,
3283
+ basename,
3284
+ staticContext.matches.map((m) => m.route.id)
3285
+ );
3286
+ }
3202
3287
  return {
3203
3288
  ...baseRenderPayload,
3289
+ routeDiscovery: useInitialRouteDiscovery ? { mode: "initial" } : baseRenderPayload.routeDiscovery,
3204
3290
  matches: await matchesPromise,
3205
3291
  patches
3206
3292
  };
@@ -3214,7 +3300,7 @@ async function getRSCRouteMatch({
3214
3300
  }) {
3215
3301
  const route = match.route;
3216
3302
  await explodeLazyRoute(route);
3217
- const Layout = route.Layout || React2.Fragment;
3303
+ const Layout = route.Layout || React3.Fragment;
3218
3304
  const Component = route.Component;
3219
3305
  const ErrorBoundary = route.ErrorBoundary;
3220
3306
  const HydrateFallback = route.HydrateFallback;
@@ -3224,12 +3310,12 @@ async function getRSCRouteMatch({
3224
3310
  let element = void 0;
3225
3311
  let shouldLoadRoute = !routeIdsToLoad || routeIdsToLoad.includes(route.id);
3226
3312
  if (Component && shouldLoadRoute) {
3227
- element = !isBelowErrorBoundary ? React2.createElement(
3313
+ element = !isBelowErrorBoundary ? React3.createElement(
3228
3314
  Layout,
3229
3315
  null,
3230
- isClientReference(Component) ? React2.createElement(WithComponentProps, {
3231
- children: React2.createElement(Component)
3232
- }) : React2.createElement(Component, {
3316
+ isClientReference(Component) ? React3.createElement(WithComponentProps, {
3317
+ children: React3.createElement(Component)
3318
+ }) : React3.createElement(Component, {
3233
3319
  loaderData,
3234
3320
  actionData,
3235
3321
  params,
@@ -3237,30 +3323,30 @@ async function getRSCRouteMatch({
3237
3323
  (match2) => convertRouteMatchToUiMatch(match2, staticContext.loaderData)
3238
3324
  )
3239
3325
  })
3240
- ) : React2.createElement(Outlet);
3326
+ ) : React3.createElement(Outlet);
3241
3327
  }
3242
3328
  let error = void 0;
3243
3329
  if (ErrorBoundary && staticContext.errors) {
3244
3330
  error = staticContext.errors[route.id];
3245
3331
  }
3246
- const errorElement = ErrorBoundary ? React2.createElement(
3332
+ const errorElement = ErrorBoundary ? React3.createElement(
3247
3333
  Layout,
3248
3334
  null,
3249
- isClientReference(ErrorBoundary) ? React2.createElement(WithErrorBoundaryProps, {
3250
- children: React2.createElement(ErrorBoundary)
3251
- }) : React2.createElement(ErrorBoundary, {
3335
+ isClientReference(ErrorBoundary) ? React3.createElement(WithErrorBoundaryProps, {
3336
+ children: React3.createElement(ErrorBoundary)
3337
+ }) : React3.createElement(ErrorBoundary, {
3252
3338
  loaderData,
3253
3339
  actionData,
3254
3340
  params,
3255
3341
  error
3256
3342
  })
3257
3343
  ) : void 0;
3258
- const hydrateFallbackElement = HydrateFallback ? React2.createElement(
3344
+ const hydrateFallbackElement = HydrateFallback ? React3.createElement(
3259
3345
  Layout,
3260
3346
  null,
3261
- isClientReference(HydrateFallback) ? React2.createElement(WithHydrateFallbackProps, {
3262
- children: React2.createElement(HydrateFallback)
3263
- }) : React2.createElement(HydrateFallback, {
3347
+ isClientReference(HydrateFallback) ? React3.createElement(WithHydrateFallbackProps, {
3348
+ children: React3.createElement(HydrateFallback)
3349
+ }) : React3.createElement(HydrateFallback, {
3264
3350
  loaderData,
3265
3351
  actionData,
3266
3352
  params
@@ -3297,11 +3383,11 @@ async function getRSCRouteMatch({
3297
3383
  }
3298
3384
  async function getManifestRoute(route) {
3299
3385
  await explodeLazyRoute(route);
3300
- const Layout = route.Layout || React2.Fragment;
3301
- const errorElement = route.ErrorBoundary ? React2.createElement(
3386
+ const Layout = route.Layout || React3.Fragment;
3387
+ const errorElement = route.ErrorBoundary ? React3.createElement(
3302
3388
  Layout,
3303
3389
  null,
3304
- React2.createElement(route.ErrorBoundary)
3390
+ React3.createElement(route.ErrorBoundary)
3305
3391
  ) : void 0;
3306
3392
  return {
3307
3393
  clientAction: route.clientAction,
@@ -3359,27 +3445,18 @@ async function getAdditionalRoutePatches(pathnames, routes, basename, matchedRou
3359
3445
  let patchRouteMatches = /* @__PURE__ */ new Map();
3360
3446
  let matchedPaths = /* @__PURE__ */ new Set();
3361
3447
  for (const pathname of pathnames) {
3362
- let segments = pathname.split("/").filter(Boolean);
3363
- let paths = ["/"];
3364
- segments.pop();
3365
- while (segments.length > 0) {
3366
- paths.push(`/${segments.join("/")}`);
3367
- segments.pop();
3368
- }
3369
- paths.forEach((path) => {
3370
- if (matchedPaths.has(path)) {
3448
+ if (matchedPaths.has(pathname)) {
3449
+ continue;
3450
+ }
3451
+ matchedPaths.add(pathname);
3452
+ let matches = matchRoutes(routes, pathname, basename) || [];
3453
+ matches.forEach((m, i) => {
3454
+ if (patchRouteMatches.get(m.route.id)) {
3371
3455
  return;
3372
3456
  }
3373
- matchedPaths.add(path);
3374
- let matches = matchRoutes(routes, path, basename) || [];
3375
- matches.forEach((m, i) => {
3376
- if (patchRouteMatches.get(m.route.id)) {
3377
- return;
3378
- }
3379
- patchRouteMatches.set(m.route.id, {
3380
- ...m.route,
3381
- parentId: matches[i - 1]?.route.id
3382
- });
3457
+ patchRouteMatches.set(m.route.id, {
3458
+ ...m.route,
3459
+ parentId: matches[i - 1]?.route.id
3383
3460
  });
3384
3461
  });
3385
3462
  }
@@ -3491,15 +3568,6 @@ function byteStringToUint8Array(byteString) {
3491
3568
  return array;
3492
3569
  }
3493
3570
 
3494
- // lib/server-runtime/warnings.ts
3495
- var alreadyWarned = {};
3496
- function warnOnce(condition, message) {
3497
- if (!condition && !alreadyWarned[message]) {
3498
- alreadyWarned[message] = true;
3499
- console.warn(message);
3500
- }
3501
- }
3502
-
3503
3571
  // lib/server-runtime/cookies.ts
3504
3572
  var createCookie = (name, cookieOptions = {}) => {
3505
3573
  let { secrets = [], ...options } = {