react-router 0.0.0-experimental-479e73b7b → 0.0.0-experimental-2a01b6fd8

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 (149) hide show
  1. package/dist/development/dom-export.js +1 -1
  2. package/dist/development/index-react-server-client.js +1 -1
  3. package/dist/development/index-react-server.d.ts +31 -21
  4. package/dist/development/index-react-server.js +254 -20
  5. package/dist/development/index.d.ts +2 -2
  6. package/dist/development/index.js +3 -3
  7. package/dist/development/lib/actions.js +1 -1
  8. package/dist/development/lib/components.js +9 -42
  9. package/dist/development/lib/context.d.ts +3 -8
  10. package/dist/development/lib/context.js +2 -8
  11. package/dist/development/lib/dom/dom.js +2 -2
  12. package/dist/development/lib/dom/lib.js +9 -9
  13. package/dist/development/lib/dom/server.d.ts +6 -1
  14. package/dist/development/lib/dom/server.js +16 -32
  15. package/dist/development/lib/dom/ssr/components.js +9 -18
  16. package/dist/development/lib/dom/ssr/data.js +1 -1
  17. package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
  18. package/dist/development/lib/dom/ssr/fallback.js +1 -1
  19. package/dist/development/lib/dom/ssr/fog-of-war.js +3 -3
  20. package/dist/development/lib/dom/ssr/hydration.d.ts +3 -1
  21. package/dist/development/lib/dom/ssr/hydration.js +6 -4
  22. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  23. package/dist/development/lib/dom/ssr/links.js +1 -1
  24. package/dist/development/lib/dom/ssr/markup.js +1 -1
  25. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  26. package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
  27. package/dist/development/lib/dom/ssr/routes.js +1 -1
  28. package/dist/development/lib/dom/ssr/server.js +2 -2
  29. package/dist/development/lib/dom/ssr/single-fetch.js +5 -5
  30. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  31. package/dist/development/lib/dom-export/hydrated-router.js +2 -1
  32. package/dist/development/lib/errors.js +1 -1
  33. package/dist/development/lib/hooks.js +34 -38
  34. package/dist/development/lib/href.js +1 -1
  35. package/dist/development/lib/router/history.js +2 -2
  36. package/dist/development/lib/router/instrumentation.js +1 -1
  37. package/dist/development/lib/router/matcher-route-pattern.js +213 -0
  38. package/dist/development/lib/router/matcher.d.ts +2 -0
  39. package/dist/development/lib/router/matcher.js +30 -0
  40. package/dist/development/lib/router/router.d.ts +6 -3
  41. package/dist/development/lib/router/router.js +51 -58
  42. package/dist/development/lib/router/url.js +1 -1
  43. package/dist/development/lib/router/utils.d.ts +8 -1
  44. package/dist/development/lib/router/utils.js +6 -4
  45. package/dist/development/lib/rsc/browser.js +2 -1
  46. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  47. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  48. package/dist/development/lib/rsc/html-stream/server.js +2 -2
  49. package/dist/development/lib/rsc/route-modules.js +1 -1
  50. package/dist/development/lib/rsc/server.ssr.js +2 -2
  51. package/dist/development/lib/server-runtime/cookies.js +2 -2
  52. package/dist/development/lib/server-runtime/crypto.js +2 -2
  53. package/dist/development/lib/server-runtime/data.js +1 -1
  54. package/dist/development/lib/server-runtime/dev.js +2 -2
  55. package/dist/development/lib/server-runtime/entry.js +1 -1
  56. package/dist/development/lib/server-runtime/errors.js +1 -1
  57. package/dist/development/lib/server-runtime/headers.js +1 -1
  58. package/dist/development/lib/server-runtime/invariant.js +1 -1
  59. package/dist/development/lib/server-runtime/mode.js +1 -1
  60. package/dist/development/lib/server-runtime/routeMatching.js +3 -4
  61. package/dist/development/lib/server-runtime/routes.js +1 -1
  62. package/dist/development/lib/server-runtime/server.js +9 -7
  63. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  64. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  65. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  66. package/dist/development/lib/server-runtime/sessions.js +1 -1
  67. package/dist/development/lib/server-runtime/single-fetch.js +2 -2
  68. package/dist/development/lib/server-runtime/urls.js +1 -1
  69. package/dist/development/lib/server-runtime/warnings.js +1 -1
  70. package/dist/development/lib/types/internal.js +1 -1
  71. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  72. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +4 -4
  73. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  74. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  75. package/dist/production/dom-export.js +1 -1
  76. package/dist/production/index-react-server-client.js +1 -1
  77. package/dist/production/index-react-server.d.ts +31 -21
  78. package/dist/production/index-react-server.js +254 -20
  79. package/dist/production/index.d.ts +2 -2
  80. package/dist/production/index.js +3 -3
  81. package/dist/production/lib/actions.js +1 -1
  82. package/dist/production/lib/components.js +9 -42
  83. package/dist/production/lib/context.d.ts +3 -8
  84. package/dist/production/lib/context.js +2 -8
  85. package/dist/production/lib/dom/dom.js +2 -2
  86. package/dist/production/lib/dom/lib.js +9 -9
  87. package/dist/production/lib/dom/server.d.ts +6 -1
  88. package/dist/production/lib/dom/server.js +16 -32
  89. package/dist/production/lib/dom/ssr/components.js +9 -18
  90. package/dist/production/lib/dom/ssr/data.js +1 -1
  91. package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
  92. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  93. package/dist/production/lib/dom/ssr/fog-of-war.js +3 -3
  94. package/dist/production/lib/dom/ssr/hydration.d.ts +3 -1
  95. package/dist/production/lib/dom/ssr/hydration.js +6 -4
  96. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  97. package/dist/production/lib/dom/ssr/links.js +1 -1
  98. package/dist/production/lib/dom/ssr/markup.js +1 -1
  99. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  100. package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
  101. package/dist/production/lib/dom/ssr/routes.js +1 -1
  102. package/dist/production/lib/dom/ssr/server.js +2 -2
  103. package/dist/production/lib/dom/ssr/single-fetch.js +5 -5
  104. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  105. package/dist/production/lib/dom-export/hydrated-router.js +2 -1
  106. package/dist/production/lib/errors.js +1 -1
  107. package/dist/production/lib/hooks.js +34 -38
  108. package/dist/production/lib/href.js +1 -1
  109. package/dist/production/lib/router/history.js +2 -2
  110. package/dist/production/lib/router/instrumentation.js +1 -1
  111. package/dist/production/lib/router/matcher-route-pattern.js +213 -0
  112. package/dist/production/lib/router/matcher.d.ts +2 -0
  113. package/dist/production/lib/router/matcher.js +30 -0
  114. package/dist/production/lib/router/router.d.ts +6 -3
  115. package/dist/production/lib/router/router.js +51 -58
  116. package/dist/production/lib/router/url.js +1 -1
  117. package/dist/production/lib/router/utils.d.ts +8 -1
  118. package/dist/production/lib/router/utils.js +6 -4
  119. package/dist/production/lib/rsc/browser.js +2 -1
  120. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  121. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  122. package/dist/production/lib/rsc/html-stream/server.js +2 -2
  123. package/dist/production/lib/rsc/route-modules.js +1 -1
  124. package/dist/production/lib/rsc/server.ssr.js +2 -2
  125. package/dist/production/lib/server-runtime/cookies.js +2 -2
  126. package/dist/production/lib/server-runtime/crypto.js +2 -2
  127. package/dist/production/lib/server-runtime/data.js +1 -1
  128. package/dist/production/lib/server-runtime/dev.js +2 -2
  129. package/dist/production/lib/server-runtime/entry.js +1 -1
  130. package/dist/production/lib/server-runtime/errors.js +1 -1
  131. package/dist/production/lib/server-runtime/headers.js +1 -1
  132. package/dist/production/lib/server-runtime/invariant.js +1 -1
  133. package/dist/production/lib/server-runtime/mode.js +1 -1
  134. package/dist/production/lib/server-runtime/routeMatching.js +3 -4
  135. package/dist/production/lib/server-runtime/routes.js +1 -1
  136. package/dist/production/lib/server-runtime/server.js +9 -7
  137. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  138. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  139. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  140. package/dist/production/lib/server-runtime/sessions.js +1 -1
  141. package/dist/production/lib/server-runtime/single-fetch.js +2 -2
  142. package/dist/production/lib/server-runtime/urls.js +1 -1
  143. package/dist/production/lib/server-runtime/warnings.js +1 -1
  144. package/dist/production/lib/types/internal.js +1 -1
  145. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  146. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +4 -4
  147. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  148. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  149. package/package.json +2 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-479e73b7b
2
+ * react-router v0.0.0-experimental-2a01b6fd8
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-479e73b7b
2
+ * react-router v0.0.0-experimental-2a01b6fd8
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -50,7 +50,7 @@ interface Path {
50
50
  * An entry in a history stack. A location contains information about the
51
51
  * URL path, as well as possibly some arbitrary state and a key.
52
52
  */
53
- interface Location<State = any> extends Path {
53
+ interface Location$1<State = any> extends Path {
54
54
  /**
55
55
  * A value of arbitrary data associated with this location.
56
56
  */
@@ -79,7 +79,7 @@ interface Update {
79
79
  /**
80
80
  * The new location.
81
81
  */
82
- location: Location;
82
+ location: Location$1;
83
83
  /**
84
84
  * The delta between this location and the former location in the history stack
85
85
  */
@@ -113,7 +113,7 @@ interface History {
113
113
  /**
114
114
  * The current location. This value is mutable.
115
115
  */
116
- readonly location: Location;
116
+ readonly location: Location$1;
117
117
  /**
118
118
  * Returns a valid href for the given `to` value that may be used as
119
119
  * the value of an <a href> attribute.
@@ -488,6 +488,9 @@ interface ShouldRevalidateFunctionArgs {
488
488
  interface ShouldRevalidateFunction {
489
489
  (args: ShouldRevalidateFunctionArgs): boolean;
490
490
  }
491
+ interface UnstableValidateParamsFunction {
492
+ (params: Params): boolean;
493
+ }
491
494
  interface DataStrategyMatch extends RouteMatch<string, DataRouteObject> {
492
495
  /**
493
496
  * @private
@@ -597,7 +600,7 @@ interface MapRoutePropertiesFunction {
597
600
  * onto the route. Either they're meaningful to the router, or they'll get
598
601
  * ignored.
599
602
  */
600
- type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
603
+ type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children" | "unstable_validateParams";
601
604
  /**
602
605
  * Keys we cannot change from within a lazy() function. We spread all other keys
603
606
  * onto the route. Either they're meaningful to the router, or they'll get
@@ -655,6 +658,10 @@ type BaseRouteObject = {
655
658
  * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
656
659
  */
657
660
  shouldRevalidate?: ShouldRevalidateFunction;
661
+ /**
662
+ * Validate route params after a route-pattern match.
663
+ */
664
+ unstable_validateParams?: UnstableValidateParamsFunction;
658
665
  /**
659
666
  * The route handle.
660
667
  */
@@ -791,7 +798,7 @@ interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {}
791
798
  * Defaults to `/`.
792
799
  * @returns An array of matched routes, or `null` if no matches were found.
793
800
  */
794
- declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
801
+ declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location$1> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
795
802
  interface UIMatch<Data = unknown, Handle = unknown> {
796
803
  id: string;
797
804
  pathname: string;
@@ -1143,9 +1150,10 @@ interface Router$1 {
1143
1150
  * @private
1144
1151
  * PRIVATE - DO NOT USE
1145
1152
  *
1146
- * Return the route branches for this router instance
1153
+ * Match routes against a location using the router's configured route
1154
+ * matching implementation.
1147
1155
  */
1148
- get branches(): RouteBranch<DataRouteObject>[] | undefined;
1156
+ match(locationArg: Partial<Location$1> | string): DataRouteMatch[] | null;
1149
1157
  /**
1150
1158
  * @private
1151
1159
  * PRIVATE - DO NOT USE
@@ -1230,7 +1238,7 @@ interface Router$1 {
1230
1238
  * Utility function to create an href for the given location
1231
1239
  * @param location
1232
1240
  */
1233
- createHref(location: Location | URL): string;
1241
+ createHref(location: Location$1 | URL): string;
1234
1242
  /**
1235
1243
  * @private
1236
1244
  * PRIVATE - DO NOT USE
@@ -1338,7 +1346,7 @@ interface RouterState {
1338
1346
  /**
1339
1347
  * The current location reflected by the router
1340
1348
  */
1341
- location: Location;
1349
+ location: Location$1;
1342
1350
  /**
1343
1351
  * The current set of route matches
1344
1352
  */
@@ -1399,7 +1407,9 @@ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "e
1399
1407
  /**
1400
1408
  * Future flags to toggle new feature behavior
1401
1409
  */
1402
- interface FutureConfig {}
1410
+ interface FutureConfig {
1411
+ unstable_routePatternMatching?: boolean;
1412
+ }
1403
1413
  /**
1404
1414
  * Initialization options for createRouter
1405
1415
  */
@@ -1495,8 +1505,8 @@ interface StaticHandler {
1495
1505
  }): Promise<any>;
1496
1506
  }
1497
1507
  type ViewTransitionOpts = {
1498
- currentLocation: Location;
1499
- nextLocation: Location;
1508
+ currentLocation: Location$1;
1509
+ nextLocation: Location$1;
1500
1510
  };
1501
1511
  /**
1502
1512
  * Subscriber function signature for changes to router state
@@ -1514,7 +1524,7 @@ interface RouterSubscriber {
1514
1524
  * for a given location
1515
1525
  */
1516
1526
  interface GetScrollRestorationKeyFunction {
1517
- (location: Location, matches: UIMatch[]): string | null;
1527
+ (location: Location$1, matches: UIMatch[]): string | null;
1518
1528
  }
1519
1529
  /**
1520
1530
  * Function signature for determining the current scroll position
@@ -1596,7 +1606,7 @@ type NavigationStates = {
1596
1606
  };
1597
1607
  Loading: {
1598
1608
  state: "loading";
1599
- location: Location;
1609
+ location: Location$1;
1600
1610
  matches: DataRouteMatch[];
1601
1611
  historyAction: Action;
1602
1612
  formMethod: Submission["formMethod"] | undefined;
@@ -1608,7 +1618,7 @@ type NavigationStates = {
1608
1618
  };
1609
1619
  Submitting: {
1610
1620
  state: "submitting";
1611
- location: Location;
1621
+ location: Location$1;
1612
1622
  matches: DataRouteMatch[];
1613
1623
  historyAction: Action;
1614
1624
  formMethod: Submission["formMethod"];
@@ -1698,7 +1708,7 @@ interface BlockerBlocked {
1698
1708
  state: "blocked";
1699
1709
  reset: () => void;
1700
1710
  proceed: () => void;
1701
- location: Location;
1711
+ location: Location$1;
1702
1712
  }
1703
1713
  interface BlockerUnblocked {
1704
1714
  state: "unblocked";
@@ -1710,12 +1720,12 @@ interface BlockerProceeding {
1710
1720
  state: "proceeding";
1711
1721
  reset: undefined;
1712
1722
  proceed: undefined;
1713
- location: Location;
1723
+ location: Location$1;
1714
1724
  }
1715
1725
  type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1716
1726
  type BlockerFunction = (args: {
1717
- currentLocation: Location;
1718
- nextLocation: Location;
1727
+ currentLocation: Location$1;
1728
+ nextLocation: Location$1;
1719
1729
  historyAction: Action;
1720
1730
  }) => boolean;
1721
1731
  interface CreateStaticHandlerOptions {
@@ -2000,7 +2010,7 @@ type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoad
2000
2010
  interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
2001
2011
  loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
2002
2012
  params: Params;
2003
- location: Location;
2013
+ location: Location$1;
2004
2014
  matches: MetaMatches<MatchLoaders>;
2005
2015
  error?: unknown;
2006
2016
  }
@@ -2321,7 +2331,7 @@ type RSCRenderPayload = {
2321
2331
  clientVersion?: string;
2322
2332
  errors: Record<string, any> | null;
2323
2333
  loaderData: Record<string, any>;
2324
- location: Location;
2334
+ location: Location$1;
2325
2335
  routeDiscovery: RouteDiscovery;
2326
2336
  matches: RSCRouteMatch[];
2327
2337
  patches?: Promise<RSCRouteManifest[]>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-479e73b7b
2
+ * react-router v0.0.0-experimental-2a01b6fd8
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { AsyncLocalStorage } from "node:async_hooks";
12
12
  import * as React from "react";
13
+ import { createMultiMatcher } from "@remix-run/route-pattern/match";
13
14
  import { parse, serialize, splitSetCookieString } from "cookie-es";
14
15
  import { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Outlet as Outlet$1, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, UNSAFE_AwaitContextProvider, UNSAFE_WithComponentProps, UNSAFE_WithErrorBoundaryProps, UNSAFE_WithHydrateFallbackProps, unstable_HistoryRouter } from "react-router/internal/react-server-client";
15
16
  //#region lib/router/url.ts
@@ -24,7 +25,7 @@ function warning(cond, message) {
24
25
  if (typeof console !== "undefined") console.warn(message);
25
26
  try {
26
27
  throw new Error(message);
27
- } catch (e) {}
28
+ } catch {}
28
29
  }
29
30
  }
30
31
  function createKey$1() {
@@ -207,7 +208,8 @@ const unsupportedLazyRouteObjectKeys = new Set([
207
208
  "path",
208
209
  "id",
209
210
  "index",
210
- "children"
211
+ "children",
212
+ "unstable_validateParams"
211
213
  ]);
212
214
  function isUnsupportedLazyRouteObjectKey(key) {
213
215
  return unsupportedLazyRouteObjectKeys.has(key);
@@ -219,7 +221,8 @@ const unsupportedLazyRouteFunctionKeys = new Set([
219
221
  "id",
220
222
  "index",
221
223
  "middleware",
222
- "children"
224
+ "children",
225
+ "unstable_validateParams"
223
226
  ]);
224
227
  function isUnsupportedLazyRouteFunctionKey(key) {
225
228
  return unsupportedLazyRouteFunctionKeys.has(key);
@@ -335,11 +338,11 @@ function convertRouteMatchToUiMatch(match, loaderData) {
335
338
  };
336
339
  }
337
340
  function flattenAndRankRoutes(routes) {
338
- let branches = flattenRoutes(routes);
341
+ let branches = flattenRoutes$1(routes);
339
342
  rankRouteBranches(branches);
340
343
  return branches;
341
344
  }
342
- function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
345
+ function flattenRoutes$1(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
343
346
  let flattenRoute = (route, index, hasParentOptionalSegments = _hasParentOptionalSegments, relativePath) => {
344
347
  let meta = {
345
348
  relativePath: relativePath === void 0 ? route.path || "" : relativePath,
@@ -356,7 +359,7 @@ function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "",
356
359
  let routesMeta = parentsMeta.concat(meta);
357
360
  if (route.children && route.children.length > 0) {
358
361
  invariant$1(route.index !== true, `Index routes must not have child routes. Please remove all child routes from route path "${path}".`);
359
- flattenRoutes(route.children, branches, routesMeta, path, hasParentOptionalSegments);
362
+ flattenRoutes$1(route.children, branches, routesMeta, path, hasParentOptionalSegments);
360
363
  }
361
364
  if (route.path == null && !route.index) return;
362
365
  branches.push({
@@ -1036,6 +1039,223 @@ function getReadonlyContext(context) {
1036
1039
  return { get: (ctx) => context.get(ctx) };
1037
1040
  }
1038
1041
  //#endregion
1042
+ //#region lib/router/matcher-route-pattern.ts
1043
+ var RoutePatternDataRouteMatcher = class {
1044
+ #state;
1045
+ #basename;
1046
+ constructor(basename) {
1047
+ this.#basename = basename;
1048
+ }
1049
+ update(routes) {
1050
+ let branches = flattenRoutes(routes);
1051
+ let matcher = createMultiMatcher();
1052
+ let partialMatcher = createMultiMatcher();
1053
+ for (let branch of branches) {
1054
+ let routePattern = convertReactRouterPathToRoutePattern(branch.path);
1055
+ validateRoutePatternSplat(branch.path, routePattern);
1056
+ routePattern = addOptionalTrailingSlash(routePattern);
1057
+ matcher.add(routePattern, branch);
1058
+ if (!branch.routesMeta[branch.routesMeta.length - 1].route.index) partialMatcher.add(routePattern === "/" ? `/*__rr_partial` : `${routePattern}(/*__rr_partial)`, branch);
1059
+ }
1060
+ this.#state = {
1061
+ branches,
1062
+ matcher,
1063
+ partialMatcher
1064
+ };
1065
+ return branches;
1066
+ }
1067
+ match(locationArg, allowPartial = false) {
1068
+ let pathname = stripBasename((typeof locationArg === "string" ? parsePath(locationArg) : locationArg).pathname || "/", this.#basename);
1069
+ if (pathname == null) return null;
1070
+ let decoded = decodePath(pathname);
1071
+ let url = new URL(decoded, "http://reactrouter.local");
1072
+ invariant$1(this.#state, "Route pattern routes must be initialized before matching.");
1073
+ let matches = this.#state.matcher.matchAll(url);
1074
+ if (allowPartial) matches.push(...this.#state.partialMatcher.matchAll(url));
1075
+ for (let match of prioritizeValidatedMatches(matches)) {
1076
+ let routeMatches = convertRoutePatternMatchToRouteMatches(match, pathname, allowPartial);
1077
+ if (routeMatches && validateRouteMatchParams(routeMatches)) return routeMatches;
1078
+ }
1079
+ return null;
1080
+ }
1081
+ };
1082
+ function validateRoutePatternSplat(routePath, routePattern) {
1083
+ invariant$1(getRoutePatternSplatIndexes(routePattern).length <= 1 && isTerminalRoutePatternSplat(routePattern), `Route path "${routePath}" is not supported with \`future.unstable_routePatternMatching\` because React Router only supports a single splat at the end of a route path.`);
1084
+ }
1085
+ function getRoutePatternSplatIndexes(routePattern) {
1086
+ let splatIndexes = [];
1087
+ for (let i = 0; i < routePattern.length; i++) {
1088
+ let char = routePattern[i];
1089
+ if (char === "\\") {
1090
+ i++;
1091
+ continue;
1092
+ }
1093
+ if (char === "*") splatIndexes.push(i);
1094
+ }
1095
+ return splatIndexes;
1096
+ }
1097
+ function isTerminalRoutePatternSplat(routePattern) {
1098
+ for (let i = 0; i < routePattern.length; i++) {
1099
+ let char = routePattern[i];
1100
+ if (char === "\\") {
1101
+ i++;
1102
+ continue;
1103
+ }
1104
+ if (char !== "*") continue;
1105
+ let suffix = routePattern.slice(i + 1);
1106
+ return /^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(suffix) || suffix === "";
1107
+ }
1108
+ return true;
1109
+ }
1110
+ function addOptionalTrailingSlash(routePattern) {
1111
+ return routePattern === "/" ? routePattern : `${routePattern.replace(/\/+$/, "")}(/)`;
1112
+ }
1113
+ function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "") {
1114
+ routes.forEach((route, index) => {
1115
+ invariant$1(route.caseSensitive !== true, "`caseSensitive` routes are not supported with `future.unstable_routePatternMatching`.");
1116
+ let meta = {
1117
+ relativePath: route.path || "",
1118
+ caseSensitive: false,
1119
+ childrenIndex: index,
1120
+ route
1121
+ };
1122
+ if (meta.relativePath.startsWith("/")) {
1123
+ invariant$1(meta.relativePath.startsWith(parentPath), `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.`);
1124
+ meta.relativePath = meta.relativePath.slice(parentPath.length);
1125
+ }
1126
+ let routesMeta = parentsMeta.concat(meta);
1127
+ let path = meta.relativePath ? joinPaths([parentPath, meta.relativePath]) : parentPath;
1128
+ if (route.children && route.children.length > 0) {
1129
+ invariant$1(route.index !== true, `Index routes must not have child routes. Please remove all child routes from route path "${path}".`);
1130
+ flattenRoutes(route.children, branches, routesMeta, path);
1131
+ if (route.children?.some((child) => child.index)) return;
1132
+ }
1133
+ if (route.path != null || route.index) branches.push({
1134
+ path,
1135
+ score: 0,
1136
+ routesMeta
1137
+ });
1138
+ });
1139
+ return branches;
1140
+ }
1141
+ function convertReactRouterPathToRoutePattern(path) {
1142
+ warning(path === "*" || !path.endsWith("*") || path.endsWith("/*"), `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(/\*$/, "/*")}".`);
1143
+ if (path.endsWith("*") && path !== "*" && !path.endsWith("/*")) path = path.replace(/\*$/, "/*");
1144
+ path = path.replace(/^\/*/, "/");
1145
+ if (path === "") return "/";
1146
+ let segments = path.split("/");
1147
+ let pattern = segments.shift() || "";
1148
+ for (let i = 0; i < segments.length;) {
1149
+ let optionalRun = [];
1150
+ while (i < segments.length && isOptionalRouteSegment(segments[i])) {
1151
+ optionalRun.push(convertRouteSegment(segments[i].slice(0, -1)));
1152
+ i++;
1153
+ }
1154
+ if (optionalRun.length > 0) {
1155
+ let nested = optionalRun.reduceRight((child, segment) => `/${segment}${child ? `(${child})` : ""}`, "");
1156
+ pattern += `(${nested})`;
1157
+ continue;
1158
+ }
1159
+ pattern += `/${convertRouteSegment(segments[i])}`;
1160
+ i++;
1161
+ }
1162
+ return pattern || "/";
1163
+ }
1164
+ function isOptionalRouteSegment(segment) {
1165
+ return segment.endsWith("?");
1166
+ }
1167
+ function convertRouteSegment(segment) {
1168
+ if (segment === "*") return "*__rr_splat";
1169
+ let paramMatch = segment.match(/^:([\w-]+)(\?)?(.*)$/);
1170
+ if (paramMatch) {
1171
+ let [, paramName, optional, suffix] = paramMatch;
1172
+ let converted = `:${paramName}${escapeRoutePatternLiteral(suffix)}`;
1173
+ return optional ? `(:${paramName})${escapeRoutePatternLiteral(suffix)}` : converted;
1174
+ }
1175
+ return escapeRoutePatternLiteral(segment);
1176
+ }
1177
+ function escapeRoutePatternLiteral(value) {
1178
+ return value.replace(/[\\():*]/g, "\\$&");
1179
+ }
1180
+ function validateRouteMatchParams(matches) {
1181
+ return matches.every(({ route, params }) => {
1182
+ try {
1183
+ return typeof route.unstable_validateParams !== "function" || route.unstable_validateParams(params) === true;
1184
+ } catch (e) {
1185
+ warning(false, `Route "${route.id || route.path}" failed param validation with the following error:\n` + (e instanceof Error ? e.message : String(e)));
1186
+ }
1187
+ });
1188
+ }
1189
+ function prioritizeValidatedMatches(matches) {
1190
+ let validatedMatches = [];
1191
+ let unvalidatedMatches = [];
1192
+ for (let match of matches) if (match.data.routesMeta.some((meta) => typeof meta.route.unstable_validateParams === "function")) validatedMatches.push(match);
1193
+ else unvalidatedMatches.push(match);
1194
+ return validatedMatches.concat(unvalidatedMatches);
1195
+ }
1196
+ function convertRoutePatternMatchToRouteMatches(match, pathname, allowPartial) {
1197
+ let pathSegments = pathname.replace(/^\//, "").split("/").filter(Boolean);
1198
+ let splatParamName = match.paramsMeta.pathname.find((meta) => meta.type === "*")?.name;
1199
+ let matchedParams = Object.entries(match.params).reduce((params, [key, value]) => {
1200
+ if (key === "__rr_partial" || value === void 0) return params;
1201
+ params[key === "__rr_splat" || key === splatParamName ? "*" : key] = value;
1202
+ return params;
1203
+ }, {});
1204
+ let consumedSegments = 0;
1205
+ let matches = [];
1206
+ for (let i = 0; i < match.data.routesMeta.length; i++) {
1207
+ let meta = match.data.routesMeta[i];
1208
+ let splatBaseSegments = null;
1209
+ let routeSegments = meta.relativePath.replace(/^\//, "").split("/").filter(Boolean);
1210
+ for (let segment of routeSegments) {
1211
+ if (segment === "*") {
1212
+ splatBaseSegments = consumedSegments;
1213
+ consumedSegments = pathSegments.length;
1214
+ break;
1215
+ }
1216
+ if (segment.endsWith("?")) {
1217
+ let routeSegment = segment.slice(0, -1);
1218
+ if (routeSegment.startsWith(":")) {
1219
+ if (matchedParams[routeSegment.slice(1)] !== void 0) consumedSegments++;
1220
+ } else if (pathSegments[consumedSegments] === routeSegment) consumedSegments++;
1221
+ continue;
1222
+ }
1223
+ consumedSegments++;
1224
+ }
1225
+ let routePathname = getRoutePatternMatchPathname(pathSegments, consumedSegments);
1226
+ let pathnameBase = splatBaseSegments == null ? routePathname : getRoutePatternMatchPathname(pathSegments, splatBaseSegments);
1227
+ matches.push({
1228
+ params: matchedParams,
1229
+ pathname: routePathname,
1230
+ pathnameBase,
1231
+ route: meta.route
1232
+ });
1233
+ }
1234
+ if (!allowPartial && pathSegments.length > consumedSegments && !match.data.routesMeta[match.data.routesMeta.length - 1].route.index) return null;
1235
+ return matches;
1236
+ }
1237
+ function getRoutePatternMatchPathname(pathSegments, consumedSegments) {
1238
+ return consumedSegments === 0 ? "/" : `/${pathSegments.slice(0, consumedSegments).join("/")}`;
1239
+ }
1240
+ //#endregion
1241
+ //#region lib/router/matcher.ts
1242
+ var V6RegExMatcher = class {
1243
+ #routes = [];
1244
+ #branches = [];
1245
+ #basename;
1246
+ constructor(basename) {
1247
+ this.#basename = basename;
1248
+ }
1249
+ update(routes) {
1250
+ this.#routes = routes;
1251
+ this.#branches = flattenAndRankRoutes(routes);
1252
+ return this.#branches;
1253
+ }
1254
+ match(locationArg, allowPartial = false) {
1255
+ return matchRoutesImpl(this.#routes, locationArg, this.#basename, allowPartial, this.#branches);
1256
+ }
1257
+ };
1258
+ //#endregion
1039
1259
  //#region lib/router/router.ts
1040
1260
  const validMutationMethodsArr = [
1041
1261
  "POST",
@@ -1054,6 +1274,9 @@ const redirectStatusCodes = new Set([
1054
1274
  308
1055
1275
  ]);
1056
1276
  const ResetLoaderDataSymbol = Symbol("ResetLoaderData");
1277
+ function createDataRouteMatcher(future, basename) {
1278
+ return future.unstable_routePatternMatching ? new RoutePatternDataRouteMatcher(basename) : new V6RegExMatcher(basename);
1279
+ }
1057
1280
  /**
1058
1281
  * Create a static handler to perform server-side data loading
1059
1282
  *
@@ -1090,7 +1313,7 @@ function createStaticHandler(routes, opts) {
1090
1313
  let basename = (opts ? opts.basename : null) || "/";
1091
1314
  let _mapRouteProperties = opts?.mapRouteProperties;
1092
1315
  let mapRouteProperties = _mapRouteProperties ? _mapRouteProperties : () => ({});
1093
- ({ ...opts?.future });
1316
+ let dataRouteMatcher = createDataRouteMatcher({ ...opts?.future }, basename);
1094
1317
  if (opts?.instrumentations) {
1095
1318
  let instrumentations = opts.instrumentations;
1096
1319
  mapRouteProperties = (route) => {
@@ -1101,7 +1324,7 @@ function createStaticHandler(routes, opts) {
1101
1324
  };
1102
1325
  }
1103
1326
  let dataRoutes = convertRoutesToDataRoutes(routes, mapRouteProperties, void 0, manifest);
1104
- let routeBranches = flattenAndRankRoutes(dataRoutes);
1327
+ let routeBranches = dataRouteMatcher.update(dataRoutes);
1105
1328
  /**
1106
1329
  * The query() method is intended for document requests, in which we want to
1107
1330
  * call an optional action and potentially multiple loaders for all nested
@@ -1132,7 +1355,7 @@ function createStaticHandler(routes, opts) {
1132
1355
  let normalizePathImpl = normalizePath || defaultNormalizePath;
1133
1356
  let method = request.method;
1134
1357
  let location = createLocation("", normalizePathImpl(request), null, "default");
1135
- let matches = matchRoutesImpl(dataRoutes, location, basename, false, routeBranches);
1358
+ let matches = dataRouteMatcher.match(location);
1136
1359
  requestContext = requestContext != null ? requestContext : new RouterContextProvider();
1137
1360
  if (!isValidMethod(method) && method !== "HEAD") {
1138
1361
  let error = getInternalRouterError(405, { method });
@@ -1260,7 +1483,7 @@ function createStaticHandler(routes, opts) {
1260
1483
  let normalizePathImpl = normalizePath || defaultNormalizePath;
1261
1484
  let method = request.method;
1262
1485
  let location = createLocation("", normalizePathImpl(request), null, "default");
1263
- let matches = matchRoutesImpl(dataRoutes, location, basename, false, routeBranches);
1486
+ let matches = dataRouteMatcher.match(location);
1264
1487
  requestContext = requestContext != null ? requestContext : new RouterContextProvider();
1265
1488
  if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") throw getInternalRouterError(405, { method });
1266
1489
  else if (!matches) throw getInternalRouterError(404, { pathname: location.pathname });
@@ -1816,7 +2039,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, path, matches, fe
1816
2039
  });
1817
2040
  try {
1818
2041
  await Promise.all(matches.flatMap((m) => [m._lazyPromises?.handler, m._lazyPromises?.route]));
1819
- } catch (e) {}
2042
+ } catch {}
1820
2043
  return results;
1821
2044
  }
1822
2045
  async function callLoaderOrAction({ request, path, pattern, match, lazyHandlerPromise, lazyRoutePromise, handlerOverride, scopedContext }) {
@@ -2321,6 +2544,11 @@ const Await = (async ({ children, resolve, errorElement }) => {
2321
2544
  }
2322
2545
  });
2323
2546
  });
2547
+ function createRSCDataRouteMatcher(routes, basename) {
2548
+ let dataRouteMatcher = createDataRouteMatcher({}, basename ?? "/");
2549
+ dataRouteMatcher.update(routes);
2550
+ return dataRouteMatcher;
2551
+ }
2324
2552
  /**
2325
2553
  * Matches the given routes to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
2326
2554
  * and returns an [RSC](https://react.dev/reference/rsc/server-components)
@@ -2415,7 +2643,7 @@ async function matchRSCServerRequest({ allowedActionOrigins, createTemporaryRefe
2415
2643
  const requestUrl = new URL(request.url);
2416
2644
  if (isManifestRequest(requestUrl)) return await generateManifestResponse(routes, basename, request, generateResponse, temporaryReferences, routeDiscovery, clientVersion);
2417
2645
  let isDataRequest = isReactServerRequest(requestUrl);
2418
- let matches = matchRoutes(routes, url.pathname, basename);
2646
+ let matches = createRSCDataRouteMatcher(routes, basename).match(url.pathname);
2419
2647
  if (matches) await Promise.all(matches.map((m) => explodeLazyRoute(m.route)));
2420
2648
  const leafMatch = matches?.[matches.length - 1];
2421
2649
  if (!isDataRequest && leafMatch && !leafMatch.route.Component && !leafMatch.route.ErrorBoundary) return generateResourceResponse(routerRequest, routes, basename, leafMatch.route.id, requestContext, onError);
@@ -2452,9 +2680,10 @@ async function generateManifestResponse(routes, basename, request, generateRespo
2452
2680
  }
2453
2681
  let pathParam = url.searchParams.get("paths");
2454
2682
  let pathnames = pathParam ? pathParam.split(",").filter(Boolean) : [url.pathname.replace(/\.manifest$/, "")];
2683
+ let dataRouteMatcher = createRSCDataRouteMatcher(routes, basename);
2455
2684
  let routeIds = /* @__PURE__ */ new Set();
2456
2685
  let matchedRoutes = pathnames.flatMap((pathname) => {
2457
- let pathnameMatches = matchRoutes(routes, pathname, basename);
2686
+ let pathnameMatches = dataRouteMatcher.match(pathname);
2458
2687
  return pathnameMatches?.map((m, i) => ({
2459
2688
  ...m.route,
2460
2689
  parentId: pathnameMatches[i - 1]?.route.id
@@ -2468,7 +2697,7 @@ async function generateManifestResponse(routes, basename, request, generateRespo
2468
2697
  });
2469
2698
  let payload = {
2470
2699
  type: "manifest",
2471
- patches: Promise.all([...matchedRoutes.map((route) => getManifestRoute(route)), getAdditionalRoutePatches(pathnames, routes, basename, Array.from(routeIds))]).then((r) => r.flat(1))
2700
+ patches: Promise.all([...matchedRoutes.map((route) => getManifestRoute(route)), getAdditionalRoutePatches(pathnames, dataRouteMatcher, Array.from(routeIds))]).then((r) => r.flat(1))
2472
2701
  };
2473
2702
  return generateResponse({
2474
2703
  statusCode: 200,
@@ -2729,7 +2958,12 @@ async function getRenderPayload(baseRenderPayload, routes, basename, routeIdsToL
2729
2958
  parentId
2730
2959
  });
2731
2960
  }));
2732
- let patches = routeDiscovery?.mode === "initial" && !isDataRequest ? getAllRoutePatches(routes, basename).then((patches) => patches.filter((patch) => !staticContext.matches.some((m) => m.route.id === patch.id))) : getAdditionalRoutePatches(getPathsWithAncestors([staticContext.location.pathname]), routes, basename, staticContext.matches.map((m) => m.route.id));
2961
+ let patches;
2962
+ if (routeDiscovery?.mode === "initial" && !isDataRequest) patches = getAllRoutePatches(routes, basename).then((patches) => patches.filter((patch) => !staticContext.matches.some((m) => m.route.id === patch.id)));
2963
+ else {
2964
+ let dataRouteMatcher = createRSCDataRouteMatcher(routes, basename);
2965
+ patches = getAdditionalRoutePatches(getPathsWithAncestors([staticContext.location.pathname]), dataRouteMatcher, staticContext.matches.map((m) => m.route.id));
2966
+ }
2733
2967
  return {
2734
2968
  ...baseRenderPayload,
2735
2969
  matches: await matchesPromise,
@@ -2833,13 +3067,13 @@ async function getAllRoutePatches(routes, basename) {
2833
3067
  for (let route of routes) await traverse(route, void 0);
2834
3068
  return patches.filter((p) => !!p.parentId);
2835
3069
  }
2836
- async function getAdditionalRoutePatches(pathnames, routes, basename, matchedRouteIds) {
3070
+ async function getAdditionalRoutePatches(pathnames, dataRouteMatcher, matchedRouteIds) {
2837
3071
  let patchRouteMatches = /* @__PURE__ */ new Map();
2838
3072
  let matchedPaths = /* @__PURE__ */ new Set();
2839
3073
  for (const pathname of pathnames) {
2840
3074
  if (matchedPaths.has(pathname)) continue;
2841
3075
  matchedPaths.add(pathname);
2842
- let matches = matchRoutes(routes, pathname, basename) || [];
3076
+ let matches = dataRouteMatcher.match(pathname) || [];
2843
3077
  matches.forEach((m, i) => {
2844
3078
  if (patchRouteMatches.get(m.route.id)) return;
2845
3079
  patchRouteMatches.set(m.route.id, {
@@ -2948,7 +3182,7 @@ const unsign = async (cookie, secret) => {
2948
3182
  try {
2949
3183
  let signature = byteStringToUint8Array(atob(hash));
2950
3184
  return await crypto.subtle.verify("HMAC", key, signature, data) ? value : false;
2951
- } catch (e) {
3185
+ } catch {
2952
3186
  return false;
2953
3187
  }
2954
3188
  };
@@ -3046,7 +3280,7 @@ function encodeData(value) {
3046
3280
  function decodeData(value) {
3047
3281
  try {
3048
3282
  return JSON.parse(decodeURIComponent(myEscape(atob(value))));
3049
- } catch (e) {
3283
+ } catch {
3050
3284
  return {};
3051
3285
  }
3052
3286
  }