react-router 7.9.4 → 7.9.6

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 (74) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/development/browser-BbBXFHbO.d.ts +310 -0
  3. package/dist/development/browser-C07r42Tt.d.mts +310 -0
  4. package/dist/development/{chunk-OIYGIGL5.mjs → chunk-4WY6JWTD.mjs} +458 -43
  5. package/dist/development/{chunk-DI2QHYMJ.js → chunk-AMVS5XVJ.js} +1314 -138
  6. package/dist/development/{chunk-WY5IRSCW.mjs → chunk-G3INQAYP.mjs} +197 -857
  7. package/dist/development/chunk-O4JVZSOY.js +1310 -0
  8. package/dist/development/chunk-PZWDWJAY.js +188 -0
  9. package/dist/development/dom-export.d.mts +103 -6
  10. package/dist/development/dom-export.d.ts +103 -4
  11. package/dist/development/dom-export.js +708 -20
  12. package/dist/development/dom-export.mjs +692 -11
  13. package/dist/{production/index-react-server-client-BbRcBjrA.d.ts → development/index-react-server-client-Da3kmxNd.d.ts} +195 -135
  14. package/dist/{production/index-react-server-client-BIz4AUNd.d.mts → development/index-react-server-client-rcoGPJhU.d.mts} +137 -78
  15. package/dist/development/index-react-server-client.d.mts +2 -3
  16. package/dist/development/index-react-server-client.d.ts +2 -2
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.d.mts +107 -3
  20. package/dist/development/index-react-server.d.ts +107 -3
  21. package/dist/development/index-react-server.js +259 -13
  22. package/dist/development/index-react-server.mjs +259 -13
  23. package/dist/development/index.d.mts +14 -320
  24. package/dist/development/index.d.ts +14 -362
  25. package/dist/development/index.js +146 -962
  26. package/dist/development/index.mjs +3 -9
  27. package/dist/development/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  28. package/dist/development/lib/types/internal.d.mts +2 -3
  29. package/dist/development/lib/types/internal.d.ts +2 -2
  30. package/dist/development/lib/types/internal.js +1 -1
  31. package/dist/development/lib/types/internal.mjs +1 -1
  32. package/dist/{production/register-C34pU-in.d.ts → development/register-BpU9rFBJ.d.ts} +1 -1
  33. package/dist/development/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  34. package/dist/{production/context-DSyS5mLj.d.mts → development/router-CAvh_Drx.d.mts} +1877 -1254
  35. package/dist/production/browser-BbBXFHbO.d.ts +310 -0
  36. package/dist/production/browser-C07r42Tt.d.mts +310 -0
  37. package/dist/production/{chunk-4E5LHRQP.js → chunk-EAIF67OW.js} +1314 -138
  38. package/dist/production/{chunk-FR6HSPLK.mjs → chunk-FDUMZGKM.mjs} +197 -857
  39. package/dist/production/{chunk-3TADTUL4.mjs → chunk-FUSXQSWG.mjs} +458 -43
  40. package/dist/production/chunk-G5A35OQU.js +188 -0
  41. package/dist/production/chunk-QN64DHI4.js +1310 -0
  42. package/dist/production/dom-export.d.mts +103 -6
  43. package/dist/production/dom-export.d.ts +103 -4
  44. package/dist/production/dom-export.js +708 -20
  45. package/dist/production/dom-export.mjs +692 -11
  46. package/dist/{development/index-react-server-client-BIz4AUNd.d.mts → production/index-react-server-client-Da3kmxNd.d.ts} +137 -78
  47. package/dist/{development/index-react-server-client-BbRcBjrA.d.ts → production/index-react-server-client-rcoGPJhU.d.mts} +195 -135
  48. package/dist/production/index-react-server-client.d.mts +2 -3
  49. package/dist/production/index-react-server-client.d.ts +2 -2
  50. package/dist/production/index-react-server-client.js +4 -4
  51. package/dist/production/index-react-server-client.mjs +2 -2
  52. package/dist/production/index-react-server.d.mts +107 -3
  53. package/dist/production/index-react-server.d.ts +107 -3
  54. package/dist/production/index-react-server.js +259 -13
  55. package/dist/production/index-react-server.mjs +259 -13
  56. package/dist/production/index.d.mts +14 -320
  57. package/dist/production/index.d.ts +14 -362
  58. package/dist/production/index.js +146 -962
  59. package/dist/production/index.mjs +3 -9
  60. package/dist/production/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  61. package/dist/production/lib/types/internal.d.mts +2 -3
  62. package/dist/production/lib/types/internal.d.ts +2 -2
  63. package/dist/production/lib/types/internal.js +1 -1
  64. package/dist/production/lib/types/internal.mjs +1 -1
  65. package/dist/{development/register-C34pU-in.d.ts → production/register-BpU9rFBJ.d.ts} +1 -1
  66. package/dist/production/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  67. package/dist/{development/context-DSyS5mLj.d.mts → production/router-CAvh_Drx.d.mts} +1877 -1254
  68. package/package.json +1 -1
  69. package/dist/development/browser-z32v5KVN.d.mts +0 -46
  70. package/dist/development/chunk-72XNTZCV.js +0 -2089
  71. package/dist/development/route-data-DZQOUSqV.d.mts +0 -473
  72. package/dist/production/browser-z32v5KVN.d.mts +0 -46
  73. package/dist/production/chunk-WNLQ53P5.js +0 -2089
  74. package/dist/production/route-data-DZQOUSqV.d.mts +0 -473
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
27
27
  var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
28
28
 
29
29
  /**
30
- * react-router v7.9.4
30
+ * react-router v7.9.6
31
31
  *
32
32
  * Copyright (c) Remix Software Inc.
33
33
  *
@@ -107,6 +107,185 @@ function parsePath(path) {
107
107
  return parsedPath;
108
108
  }
109
109
 
110
+ // lib/router/instrumentation.ts
111
+ var UninstrumentedSymbol = Symbol("Uninstrumented");
112
+ function getRouteInstrumentationUpdates(fns, route) {
113
+ let aggregated = {
114
+ lazy: [],
115
+ "lazy.loader": [],
116
+ "lazy.action": [],
117
+ "lazy.middleware": [],
118
+ middleware: [],
119
+ loader: [],
120
+ action: []
121
+ };
122
+ fns.forEach(
123
+ (fn) => fn({
124
+ id: route.id,
125
+ index: route.index,
126
+ path: route.path,
127
+ instrument(i) {
128
+ let keys = Object.keys(aggregated);
129
+ for (let key of keys) {
130
+ if (i[key]) {
131
+ aggregated[key].push(i[key]);
132
+ }
133
+ }
134
+ }
135
+ })
136
+ );
137
+ let updates = {};
138
+ if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
139
+ let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
140
+ if (instrumented) {
141
+ updates.lazy = instrumented;
142
+ }
143
+ }
144
+ if (typeof route.lazy === "object") {
145
+ let lazyObject = route.lazy;
146
+ ["middleware", "loader", "action"].forEach((key) => {
147
+ let lazyFn = lazyObject[key];
148
+ let instrumentations = aggregated[`lazy.${key}`];
149
+ if (typeof lazyFn === "function" && instrumentations.length > 0) {
150
+ let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
151
+ if (instrumented) {
152
+ updates.lazy = Object.assign(updates.lazy || {}, {
153
+ [key]: instrumented
154
+ });
155
+ }
156
+ }
157
+ });
158
+ }
159
+ ["loader", "action"].forEach((key) => {
160
+ let handler = route[key];
161
+ if (typeof handler === "function" && aggregated[key].length > 0) {
162
+ let original = handler[UninstrumentedSymbol] ?? handler;
163
+ let instrumented = wrapImpl(
164
+ aggregated[key],
165
+ original,
166
+ (...args) => getHandlerInfo(args[0])
167
+ );
168
+ if (instrumented) {
169
+ instrumented[UninstrumentedSymbol] = original;
170
+ updates[key] = instrumented;
171
+ }
172
+ }
173
+ });
174
+ if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) {
175
+ updates.middleware = route.middleware.map((middleware) => {
176
+ let original = middleware[UninstrumentedSymbol] ?? middleware;
177
+ let instrumented = wrapImpl(
178
+ aggregated.middleware,
179
+ original,
180
+ (...args) => getHandlerInfo(args[0])
181
+ );
182
+ if (instrumented) {
183
+ instrumented[UninstrumentedSymbol] = original;
184
+ return instrumented;
185
+ }
186
+ return middleware;
187
+ });
188
+ }
189
+ return updates;
190
+ }
191
+ function wrapImpl(impls, handler, getInfo) {
192
+ if (impls.length === 0) {
193
+ return null;
194
+ }
195
+ return async (...args) => {
196
+ let result = await recurseRight(
197
+ impls,
198
+ getInfo(...args),
199
+ () => handler(...args),
200
+ impls.length - 1
201
+ );
202
+ if (result.type === "error") {
203
+ throw result.value;
204
+ }
205
+ return result.value;
206
+ };
207
+ }
208
+ async function recurseRight(impls, info, handler, index) {
209
+ let impl = impls[index];
210
+ let result;
211
+ if (!impl) {
212
+ try {
213
+ let value = await handler();
214
+ result = { type: "success", value };
215
+ } catch (e) {
216
+ result = { type: "error", value: e };
217
+ }
218
+ } else {
219
+ let handlerPromise = void 0;
220
+ let callHandler = async () => {
221
+ if (handlerPromise) {
222
+ console.error("You cannot call instrumented handlers more than once");
223
+ } else {
224
+ handlerPromise = recurseRight(impls, info, handler, index - 1);
225
+ }
226
+ result = await handlerPromise;
227
+ invariant(result, "Expected a result");
228
+ if (result.type === "error" && result.value instanceof Error) {
229
+ return { status: "error", error: result.value };
230
+ }
231
+ return { status: "success", error: void 0 };
232
+ };
233
+ try {
234
+ await impl(callHandler, info);
235
+ } catch (e) {
236
+ console.error("An instrumentation function threw an error:", e);
237
+ }
238
+ if (!handlerPromise) {
239
+ await callHandler();
240
+ }
241
+ await handlerPromise;
242
+ }
243
+ if (result) {
244
+ return result;
245
+ }
246
+ return {
247
+ type: "error",
248
+ value: new Error("No result assigned in instrumentation chain.")
249
+ };
250
+ }
251
+ function getHandlerInfo(args) {
252
+ let { request, context, params, unstable_pattern } = args;
253
+ return {
254
+ request: getReadonlyRequest(request),
255
+ params: { ...params },
256
+ unstable_pattern,
257
+ context: getReadonlyContext(context)
258
+ };
259
+ }
260
+ function getReadonlyRequest(request) {
261
+ return {
262
+ method: request.method,
263
+ url: request.url,
264
+ headers: {
265
+ get: (...args) => request.headers.get(...args)
266
+ }
267
+ };
268
+ }
269
+ function getReadonlyContext(context) {
270
+ if (isPlainObject(context)) {
271
+ let frozen = { ...context };
272
+ Object.freeze(frozen);
273
+ return frozen;
274
+ } else {
275
+ return {
276
+ get: (ctx) => context.get(ctx)
277
+ };
278
+ }
279
+ }
280
+ var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
281
+ function isPlainObject(thing) {
282
+ if (thing === null || typeof thing !== "object") {
283
+ return false;
284
+ }
285
+ const proto = Object.getPrototypeOf(thing);
286
+ return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
287
+ }
288
+
110
289
  // lib/router/utils.ts
111
290
  function createContext(defaultValue) {
112
291
  return { defaultValue };
@@ -200,19 +379,23 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
200
379
  if (isIndexRoute(route)) {
201
380
  let indexRoute = {
202
381
  ...route,
203
- ...mapRouteProperties(route),
204
382
  id
205
383
  };
206
- manifest[id] = indexRoute;
384
+ manifest[id] = mergeRouteUpdates(
385
+ indexRoute,
386
+ mapRouteProperties(indexRoute)
387
+ );
207
388
  return indexRoute;
208
389
  } else {
209
390
  let pathOrLayoutRoute = {
210
391
  ...route,
211
- ...mapRouteProperties(route),
212
392
  id,
213
393
  children: void 0
214
394
  };
215
- manifest[id] = pathOrLayoutRoute;
395
+ manifest[id] = mergeRouteUpdates(
396
+ pathOrLayoutRoute,
397
+ mapRouteProperties(pathOrLayoutRoute)
398
+ );
216
399
  if (route.children) {
217
400
  pathOrLayoutRoute.children = convertRoutesToDataRoutes(
218
401
  route.children,
@@ -226,6 +409,17 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
226
409
  }
227
410
  });
228
411
  }
412
+ function mergeRouteUpdates(route, updates) {
413
+ return Object.assign(route, {
414
+ ...updates,
415
+ ...typeof updates.lazy === "object" && updates.lazy != null ? {
416
+ lazy: {
417
+ ...route.lazy,
418
+ ...updates.lazy
419
+ }
420
+ } : {}
421
+ });
422
+ }
229
423
  function matchRoutes(routes, locationArg, basename = "/") {
230
424
  return matchRoutesImpl(routes, locationArg, basename, false);
231
425
  }
@@ -513,13 +707,36 @@ function prependBasename({
513
707
  }) {
514
708
  return pathname === "/" ? basename : joinPaths([basename, pathname]);
515
709
  }
710
+ var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
711
+ var isAbsoluteUrl = (url) => ABSOLUTE_URL_REGEX.test(url);
516
712
  function resolvePath(to, fromPathname = "/") {
517
713
  let {
518
714
  pathname: toPathname,
519
715
  search = "",
520
716
  hash = ""
521
717
  } = typeof to === "string" ? parsePath(to) : to;
522
- let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
718
+ let pathname;
719
+ if (toPathname) {
720
+ if (isAbsoluteUrl(toPathname)) {
721
+ pathname = toPathname;
722
+ } else {
723
+ if (toPathname.includes("//")) {
724
+ let oldPathname = toPathname;
725
+ toPathname = toPathname.replace(/\/\/+/g, "/");
726
+ warning(
727
+ false,
728
+ `Pathnames cannot have embedded double slashes - normalizing ${oldPathname} -> ${toPathname}`
729
+ );
730
+ }
731
+ if (toPathname.startsWith("/")) {
732
+ pathname = resolvePathname(toPathname.substring(1), "/");
733
+ } else {
734
+ pathname = resolvePathname(toPathname, fromPathname);
735
+ }
736
+ }
737
+ } else {
738
+ pathname = fromPathname;
739
+ }
523
740
  return {
524
741
  pathname,
525
742
  search: normalizeSearch(search),
@@ -652,6 +869,9 @@ var ErrorResponseImpl = class {
652
869
  function isRouteErrorResponse(error) {
653
870
  return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
654
871
  }
872
+ function getRoutePattern(paths) {
873
+ return paths.filter(Boolean).join("/").replace(/\/\/*/g, "/") || "/";
874
+ }
655
875
 
656
876
  // lib/router/router.ts
657
877
  var validMutationMethodsArr = [
@@ -669,8 +889,6 @@ var validRequestMethodsArr = [
669
889
  ];
670
890
  var validRequestMethods = new Set(validRequestMethodsArr);
671
891
  var redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
672
- var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
673
- var isAbsoluteUrl = (url) => ABSOLUTE_URL_REGEX.test(url);
674
892
  var defaultMapRouteProperties = (route) => ({
675
893
  hasErrorBoundary: Boolean(route.hasErrorBoundary)
676
894
  });
@@ -682,7 +900,20 @@ function createStaticHandler(routes, opts) {
682
900
  );
683
901
  let manifest = {};
684
902
  let basename = (opts ? opts.basename : null) || "/";
685
- let mapRouteProperties = opts?.mapRouteProperties || defaultMapRouteProperties;
903
+ let _mapRouteProperties = opts?.mapRouteProperties || defaultMapRouteProperties;
904
+ let mapRouteProperties = _mapRouteProperties;
905
+ if (opts?.unstable_instrumentations) {
906
+ let instrumentations = opts.unstable_instrumentations;
907
+ mapRouteProperties = (route) => {
908
+ return {
909
+ ..._mapRouteProperties(route),
910
+ ...getRouteInstrumentationUpdates(
911
+ instrumentations.map((i) => i.route).filter(Boolean),
912
+ route
913
+ )
914
+ };
915
+ };
916
+ }
686
917
  let dataRoutes = convertRoutesToDataRoutes(
687
918
  routes,
688
919
  mapRouteProperties,
@@ -752,6 +983,7 @@ function createStaticHandler(routes, opts) {
752
983
  let response = await runServerMiddlewarePipeline(
753
984
  {
754
985
  request,
986
+ unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
755
987
  matches,
756
988
  params: matches[0].params,
757
989
  // If we're calling middleware then it must be enabled so we can cast
@@ -897,6 +1129,7 @@ function createStaticHandler(routes, opts) {
897
1129
  let response = await runServerMiddlewarePipeline(
898
1130
  {
899
1131
  request,
1132
+ unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
900
1133
  matches,
901
1134
  params: matches[0].params,
902
1135
  // If we're calling middleware then it must be enabled so we can cast
@@ -1172,12 +1405,14 @@ function createStaticHandler(routes, opts) {
1172
1405
  // Up to but not including the boundary
1173
1406
  matches.findIndex((m) => m.route.id === pendingActionResult[0]) - 1
1174
1407
  ) : void 0;
1408
+ let pattern = getRoutePattern(matches.map((m) => m.route.path));
1175
1409
  dsMatches = matches.map((match, index) => {
1176
1410
  if (maxIdx != null && index > maxIdx) {
1177
1411
  return getDataStrategyMatch(
1178
1412
  mapRouteProperties,
1179
1413
  manifest,
1180
1414
  request,
1415
+ pattern,
1181
1416
  match,
1182
1417
  [],
1183
1418
  requestContext,
@@ -1188,6 +1423,7 @@ function createStaticHandler(routes, opts) {
1188
1423
  mapRouteProperties,
1189
1424
  manifest,
1190
1425
  request,
1426
+ pattern,
1191
1427
  match,
1192
1428
  [],
1193
1429
  requestContext,
@@ -1526,12 +1762,17 @@ function runServerMiddlewarePipeline(args, handler, errorHandler) {
1526
1762
  }
1527
1763
  }
1528
1764
  async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
1529
- let { matches, request, params, context } = args;
1765
+ let { matches, request, params, context, unstable_pattern } = args;
1530
1766
  let tuples = matches.flatMap(
1531
1767
  (m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
1532
1768
  );
1533
1769
  let result = await callRouteMiddleware(
1534
- { request, params, context },
1770
+ {
1771
+ request,
1772
+ params,
1773
+ context,
1774
+ unstable_pattern
1775
+ },
1535
1776
  tuples,
1536
1777
  handler,
1537
1778
  processResult,
@@ -1609,7 +1850,7 @@ function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request,
1609
1850
  handler: lazyRoutePromises.lazyHandlerPromise
1610
1851
  };
1611
1852
  }
1612
- function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
1853
+ function getDataStrategyMatch(mapRouteProperties, manifest, request, unstable_pattern, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
1613
1854
  let isUsingNewApi = false;
1614
1855
  let _lazyPromises = getDataStrategyMatchLazyPromises(
1615
1856
  mapRouteProperties,
@@ -1640,9 +1881,10 @@ function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazy
1640
1881
  let { lazy, loader, middleware } = match.route;
1641
1882
  let callHandler = isUsingNewApi || shouldLoad || handlerOverride && !isMutationMethod(request.method) && (lazy || loader);
1642
1883
  let isMiddlewareOnlyRoute = middleware && middleware.length > 0 && !loader && !lazy;
1643
- if (callHandler && !isMiddlewareOnlyRoute) {
1884
+ if (callHandler && (isMutationMethod(request.method) || !isMiddlewareOnlyRoute)) {
1644
1885
  return callLoaderOrAction({
1645
1886
  request,
1887
+ unstable_pattern,
1646
1888
  match,
1647
1889
  lazyHandlerPromise: _lazyPromises?.handler,
1648
1890
  lazyRoutePromise: _lazyPromises?.route,
@@ -1676,6 +1918,7 @@ function getTargetedDataStrategyMatches(mapRouteProperties, manifest, request, m
1676
1918
  mapRouteProperties,
1677
1919
  manifest,
1678
1920
  request,
1921
+ getRoutePattern(matches.map((m) => m.route.path)),
1679
1922
  match,
1680
1923
  lazyRoutePropertiesToSkip,
1681
1924
  scopedContext,
@@ -1690,6 +1933,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
1690
1933
  }
1691
1934
  let dataStrategyArgs = {
1692
1935
  request,
1936
+ unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
1693
1937
  params: matches[0].params,
1694
1938
  context: scopedContext,
1695
1939
  matches
@@ -1717,6 +1961,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
1717
1961
  }
1718
1962
  async function callLoaderOrAction({
1719
1963
  request,
1964
+ unstable_pattern,
1720
1965
  match,
1721
1966
  lazyHandlerPromise,
1722
1967
  lazyRoutePromise,
@@ -1743,6 +1988,7 @@ async function callLoaderOrAction({
1743
1988
  return handler(
1744
1989
  {
1745
1990
  request,
1991
+ unstable_pattern,
1746
1992
  params: match.params,
1747
1993
  context: scopedContext
1748
1994
  },