react-router 7.9.4-pre.0 → 7.9.5-pre.0

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 +35 -1
  2. package/dist/development/browser-DM83uryY.d.ts +310 -0
  3. package/dist/development/browser-DfMfSvsC.d.mts +310 -0
  4. package/dist/development/{chunk-I2PHXWY4.mjs → chunk-76L3QNAV.mjs} +365 -22
  5. package/dist/development/{chunk-5IRCOFJ2.mjs → chunk-B6QYCHJF.mjs} +197 -857
  6. package/dist/development/chunk-FXLUBU25.js +1310 -0
  7. package/dist/development/chunk-KXZSW2DO.js +188 -0
  8. package/dist/development/{chunk-V7H6ON6M.js → chunk-TSYPWE43.js} +1226 -122
  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-BIz4AUNd.d.mts → development/index-react-server-client-B0vnxMMk.d.mts} +137 -78
  14. package/dist/development/{index-react-server-client-BIz4AUNd.d.mts → index-react-server-client-BSxMvS7Z.d.ts} +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 +235 -10
  22. package/dist/development/index-react-server.mjs +235 -10
  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-iAqbU5Q4.d.ts} +173 -24
  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/development/{register-CI4bTprK.d.mts → register-_G476ptB.d.mts} +1 -1
  33. package/dist/{production/register-C34pU-in.d.ts → development/register-c-dooqKE.d.ts} +1 -1
  34. package/dist/development/{context-DSyS5mLj.d.mts → router-DIAPGK5f.d.mts} +1873 -1254
  35. package/dist/production/browser-DM83uryY.d.ts +310 -0
  36. package/dist/production/browser-DfMfSvsC.d.mts +310 -0
  37. package/dist/production/{chunk-TK5RYV7M.mjs → chunk-4JX2RDWY.mjs} +197 -857
  38. package/dist/production/chunk-4SZHQXEM.js +188 -0
  39. package/dist/production/{chunk-VDTQF36D.mjs → chunk-7EXEUENX.mjs} +365 -22
  40. package/dist/production/{chunk-QIDCISSR.js → chunk-ARKB3I5K.js} +1226 -122
  41. package/dist/production/chunk-OB3KSCCZ.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/production/{index-react-server-client-BbRcBjrA.d.ts → index-react-server-client-B0vnxMMk.d.mts} +195 -135
  47. package/dist/{development/index-react-server-client-BbRcBjrA.d.ts → production/index-react-server-client-BSxMvS7Z.d.ts} +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 +235 -10
  55. package/dist/production/index-react-server.mjs +235 -10
  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-iAqbU5Q4.d.ts} +173 -24
  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/production/{register-CI4bTprK.d.mts → register-_G476ptB.d.mts} +1 -1
  66. package/dist/{development/register-C34pU-in.d.ts → production/register-c-dooqKE.d.ts} +1 -1
  67. package/dist/production/{context-DSyS5mLj.d.mts → router-DIAPGK5f.d.mts} +1873 -1254
  68. package/package.json +1 -1
  69. package/dist/development/browser-z32v5KVN.d.mts +0 -46
  70. package/dist/development/chunk-JPM6TDKY.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-A4C524Z4.js +0 -2089
  74. package/dist/production/route-data-DZQOUSqV.d.mts +0 -473
@@ -6,7 +6,7 @@ export { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLi
6
6
  import { serialize, parse } from 'cookie';
7
7
 
8
8
  /**
9
- * react-router v7.9.4-pre.0
9
+ * react-router v7.9.5-pre.0
10
10
  *
11
11
  * Copyright (c) Remix Software Inc.
12
12
  *
@@ -86,6 +86,185 @@ function parsePath(path) {
86
86
  return parsedPath;
87
87
  }
88
88
 
89
+ // lib/router/instrumentation.ts
90
+ var UninstrumentedSymbol = Symbol("Uninstrumented");
91
+ function getRouteInstrumentationUpdates(fns, route) {
92
+ let aggregated = {
93
+ lazy: [],
94
+ "lazy.loader": [],
95
+ "lazy.action": [],
96
+ "lazy.middleware": [],
97
+ middleware: [],
98
+ loader: [],
99
+ action: []
100
+ };
101
+ fns.forEach(
102
+ (fn) => fn({
103
+ id: route.id,
104
+ index: route.index,
105
+ path: route.path,
106
+ instrument(i) {
107
+ let keys = Object.keys(aggregated);
108
+ for (let key of keys) {
109
+ if (i[key]) {
110
+ aggregated[key].push(i[key]);
111
+ }
112
+ }
113
+ }
114
+ })
115
+ );
116
+ let updates = {};
117
+ if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
118
+ let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
119
+ if (instrumented) {
120
+ updates.lazy = instrumented;
121
+ }
122
+ }
123
+ if (typeof route.lazy === "object") {
124
+ let lazyObject = route.lazy;
125
+ ["middleware", "loader", "action"].forEach((key) => {
126
+ let lazyFn = lazyObject[key];
127
+ let instrumentations = aggregated[`lazy.${key}`];
128
+ if (typeof lazyFn === "function" && instrumentations.length > 0) {
129
+ let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
130
+ if (instrumented) {
131
+ updates.lazy = Object.assign(updates.lazy || {}, {
132
+ [key]: instrumented
133
+ });
134
+ }
135
+ }
136
+ });
137
+ }
138
+ ["loader", "action"].forEach((key) => {
139
+ let handler = route[key];
140
+ if (typeof handler === "function" && aggregated[key].length > 0) {
141
+ let original = handler[UninstrumentedSymbol] ?? handler;
142
+ let instrumented = wrapImpl(
143
+ aggregated[key],
144
+ original,
145
+ (...args) => getHandlerInfo(args[0])
146
+ );
147
+ if (instrumented) {
148
+ instrumented[UninstrumentedSymbol] = original;
149
+ updates[key] = instrumented;
150
+ }
151
+ }
152
+ });
153
+ if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) {
154
+ updates.middleware = route.middleware.map((middleware) => {
155
+ let original = middleware[UninstrumentedSymbol] ?? middleware;
156
+ let instrumented = wrapImpl(
157
+ aggregated.middleware,
158
+ original,
159
+ (...args) => getHandlerInfo(args[0])
160
+ );
161
+ if (instrumented) {
162
+ instrumented[UninstrumentedSymbol] = original;
163
+ return instrumented;
164
+ }
165
+ return middleware;
166
+ });
167
+ }
168
+ return updates;
169
+ }
170
+ function wrapImpl(impls, handler, getInfo) {
171
+ if (impls.length === 0) {
172
+ return null;
173
+ }
174
+ return async (...args) => {
175
+ let result = await recurseRight(
176
+ impls,
177
+ getInfo(...args),
178
+ () => handler(...args),
179
+ impls.length - 1
180
+ );
181
+ if (result.type === "error") {
182
+ throw result.value;
183
+ }
184
+ return result.value;
185
+ };
186
+ }
187
+ async function recurseRight(impls, info, handler, index) {
188
+ let impl = impls[index];
189
+ let result;
190
+ if (!impl) {
191
+ try {
192
+ let value = await handler();
193
+ result = { type: "success", value };
194
+ } catch (e) {
195
+ result = { type: "error", value: e };
196
+ }
197
+ } else {
198
+ let handlerPromise = void 0;
199
+ let callHandler = async () => {
200
+ if (handlerPromise) {
201
+ console.error("You cannot call instrumented handlers more than once");
202
+ } else {
203
+ handlerPromise = recurseRight(impls, info, handler, index - 1);
204
+ }
205
+ result = await handlerPromise;
206
+ invariant(result, "Expected a result");
207
+ if (result.type === "error" && result.value instanceof Error) {
208
+ return { status: "error", error: result.value };
209
+ }
210
+ return { status: "success", error: void 0 };
211
+ };
212
+ try {
213
+ await impl(callHandler, info);
214
+ } catch (e) {
215
+ console.error("An instrumentation function threw an error:", e);
216
+ }
217
+ if (!handlerPromise) {
218
+ await callHandler();
219
+ }
220
+ await handlerPromise;
221
+ }
222
+ if (result) {
223
+ return result;
224
+ }
225
+ return {
226
+ type: "error",
227
+ value: new Error("No result assigned in instrumentation chain.")
228
+ };
229
+ }
230
+ function getHandlerInfo(args) {
231
+ let { request, context, params, unstable_pattern } = args;
232
+ return {
233
+ request: getReadonlyRequest(request),
234
+ params: { ...params },
235
+ unstable_pattern,
236
+ context: getReadonlyContext(context)
237
+ };
238
+ }
239
+ function getReadonlyRequest(request) {
240
+ return {
241
+ method: request.method,
242
+ url: request.url,
243
+ headers: {
244
+ get: (...args) => request.headers.get(...args)
245
+ }
246
+ };
247
+ }
248
+ function getReadonlyContext(context) {
249
+ if (isPlainObject(context)) {
250
+ let frozen = { ...context };
251
+ Object.freeze(frozen);
252
+ return frozen;
253
+ } else {
254
+ return {
255
+ get: (ctx) => context.get(ctx)
256
+ };
257
+ }
258
+ }
259
+ var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
260
+ function isPlainObject(thing) {
261
+ if (thing === null || typeof thing !== "object") {
262
+ return false;
263
+ }
264
+ const proto = Object.getPrototypeOf(thing);
265
+ return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
266
+ }
267
+
89
268
  // lib/router/utils.ts
90
269
  function createContext(defaultValue) {
91
270
  return { defaultValue };
@@ -179,19 +358,23 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
179
358
  if (isIndexRoute(route)) {
180
359
  let indexRoute = {
181
360
  ...route,
182
- ...mapRouteProperties(route),
183
361
  id
184
362
  };
185
- manifest[id] = indexRoute;
363
+ manifest[id] = mergeRouteUpdates(
364
+ indexRoute,
365
+ mapRouteProperties(indexRoute)
366
+ );
186
367
  return indexRoute;
187
368
  } else {
188
369
  let pathOrLayoutRoute = {
189
370
  ...route,
190
- ...mapRouteProperties(route),
191
371
  id,
192
372
  children: void 0
193
373
  };
194
- manifest[id] = pathOrLayoutRoute;
374
+ manifest[id] = mergeRouteUpdates(
375
+ pathOrLayoutRoute,
376
+ mapRouteProperties(pathOrLayoutRoute)
377
+ );
195
378
  if (route.children) {
196
379
  pathOrLayoutRoute.children = convertRoutesToDataRoutes(
197
380
  route.children,
@@ -205,6 +388,17 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath = [],
205
388
  }
206
389
  });
207
390
  }
391
+ function mergeRouteUpdates(route, updates) {
392
+ return Object.assign(route, {
393
+ ...updates,
394
+ ...typeof updates.lazy === "object" && updates.lazy != null ? {
395
+ lazy: {
396
+ ...route.lazy,
397
+ ...updates.lazy
398
+ }
399
+ } : {}
400
+ });
401
+ }
208
402
  function matchRoutes(routes, locationArg, basename = "/") {
209
403
  return matchRoutesImpl(routes, locationArg, basename, false);
210
404
  }
@@ -631,6 +825,9 @@ var ErrorResponseImpl = class {
631
825
  function isRouteErrorResponse(error) {
632
826
  return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
633
827
  }
828
+ function getRoutePattern(paths) {
829
+ return paths.filter(Boolean).join("/").replace(/\/\/*/g, "/") || "/";
830
+ }
634
831
 
635
832
  // lib/router/router.ts
636
833
  var validMutationMethodsArr = [
@@ -661,7 +858,20 @@ function createStaticHandler(routes, opts) {
661
858
  );
662
859
  let manifest = {};
663
860
  let basename = (opts ? opts.basename : null) || "/";
664
- let mapRouteProperties = opts?.mapRouteProperties || defaultMapRouteProperties;
861
+ let _mapRouteProperties = opts?.mapRouteProperties || defaultMapRouteProperties;
862
+ let mapRouteProperties = _mapRouteProperties;
863
+ if (opts?.unstable_instrumentations) {
864
+ let instrumentations = opts.unstable_instrumentations;
865
+ mapRouteProperties = (route) => {
866
+ return {
867
+ ..._mapRouteProperties(route),
868
+ ...getRouteInstrumentationUpdates(
869
+ instrumentations.map((i) => i.route).filter(Boolean),
870
+ route
871
+ )
872
+ };
873
+ };
874
+ }
665
875
  let dataRoutes = convertRoutesToDataRoutes(
666
876
  routes,
667
877
  mapRouteProperties,
@@ -731,6 +941,7 @@ function createStaticHandler(routes, opts) {
731
941
  let response = await runServerMiddlewarePipeline(
732
942
  {
733
943
  request,
944
+ unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
734
945
  matches,
735
946
  params: matches[0].params,
736
947
  // If we're calling middleware then it must be enabled so we can cast
@@ -876,6 +1087,7 @@ function createStaticHandler(routes, opts) {
876
1087
  let response = await runServerMiddlewarePipeline(
877
1088
  {
878
1089
  request,
1090
+ unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
879
1091
  matches,
880
1092
  params: matches[0].params,
881
1093
  // If we're calling middleware then it must be enabled so we can cast
@@ -1151,12 +1363,14 @@ function createStaticHandler(routes, opts) {
1151
1363
  // Up to but not including the boundary
1152
1364
  matches.findIndex((m) => m.route.id === pendingActionResult[0]) - 1
1153
1365
  ) : void 0;
1366
+ let pattern = getRoutePattern(matches.map((m) => m.route.path));
1154
1367
  dsMatches = matches.map((match, index) => {
1155
1368
  if (maxIdx != null && index > maxIdx) {
1156
1369
  return getDataStrategyMatch(
1157
1370
  mapRouteProperties,
1158
1371
  manifest,
1159
1372
  request,
1373
+ pattern,
1160
1374
  match,
1161
1375
  [],
1162
1376
  requestContext,
@@ -1167,6 +1381,7 @@ function createStaticHandler(routes, opts) {
1167
1381
  mapRouteProperties,
1168
1382
  manifest,
1169
1383
  request,
1384
+ pattern,
1170
1385
  match,
1171
1386
  [],
1172
1387
  requestContext,
@@ -1505,12 +1720,17 @@ function runServerMiddlewarePipeline(args, handler, errorHandler) {
1505
1720
  }
1506
1721
  }
1507
1722
  async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
1508
- let { matches, request, params, context } = args;
1723
+ let { matches, request, params, context, unstable_pattern } = args;
1509
1724
  let tuples = matches.flatMap(
1510
1725
  (m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
1511
1726
  );
1512
1727
  let result = await callRouteMiddleware(
1513
- { request, params, context },
1728
+ {
1729
+ request,
1730
+ params,
1731
+ context,
1732
+ unstable_pattern
1733
+ },
1514
1734
  tuples,
1515
1735
  handler,
1516
1736
  processResult,
@@ -1588,7 +1808,7 @@ function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request,
1588
1808
  handler: lazyRoutePromises.lazyHandlerPromise
1589
1809
  };
1590
1810
  }
1591
- function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
1811
+ function getDataStrategyMatch(mapRouteProperties, manifest, request, unstable_pattern, match, lazyRoutePropertiesToSkip, scopedContext, shouldLoad, unstable_shouldRevalidateArgs = null) {
1592
1812
  let isUsingNewApi = false;
1593
1813
  let _lazyPromises = getDataStrategyMatchLazyPromises(
1594
1814
  mapRouteProperties,
@@ -1619,9 +1839,10 @@ function getDataStrategyMatch(mapRouteProperties, manifest, request, match, lazy
1619
1839
  let { lazy, loader, middleware } = match.route;
1620
1840
  let callHandler = isUsingNewApi || shouldLoad || handlerOverride && !isMutationMethod(request.method) && (lazy || loader);
1621
1841
  let isMiddlewareOnlyRoute = middleware && middleware.length > 0 && !loader && !lazy;
1622
- if (callHandler && !isMiddlewareOnlyRoute) {
1842
+ if (callHandler && (isMutationMethod(request.method) || !isMiddlewareOnlyRoute)) {
1623
1843
  return callLoaderOrAction({
1624
1844
  request,
1845
+ unstable_pattern,
1625
1846
  match,
1626
1847
  lazyHandlerPromise: _lazyPromises?.handler,
1627
1848
  lazyRoutePromise: _lazyPromises?.route,
@@ -1655,6 +1876,7 @@ function getTargetedDataStrategyMatches(mapRouteProperties, manifest, request, m
1655
1876
  mapRouteProperties,
1656
1877
  manifest,
1657
1878
  request,
1879
+ getRoutePattern(matches.map((m) => m.route.path)),
1658
1880
  match,
1659
1881
  lazyRoutePropertiesToSkip,
1660
1882
  scopedContext,
@@ -1669,6 +1891,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
1669
1891
  }
1670
1892
  let dataStrategyArgs = {
1671
1893
  request,
1894
+ unstable_pattern: getRoutePattern(matches.map((m) => m.route.path)),
1672
1895
  params: matches[0].params,
1673
1896
  context: scopedContext,
1674
1897
  matches
@@ -1696,6 +1919,7 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
1696
1919
  }
1697
1920
  async function callLoaderOrAction({
1698
1921
  request,
1922
+ unstable_pattern,
1699
1923
  match,
1700
1924
  lazyHandlerPromise,
1701
1925
  lazyRoutePromise,
@@ -1722,6 +1946,7 @@ async function callLoaderOrAction({
1722
1946
  return handler(
1723
1947
  {
1724
1948
  request,
1949
+ unstable_pattern,
1725
1950
  params: match.params,
1726
1951
  context: scopedContext
1727
1952
  },