react-router 0.0.0-experimental-3d7dcee → 0.0.0-experimental-426e5caec

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 (60) hide show
  1. package/CHANGELOG.md +39 -2
  2. package/dist/development/{chunk-WJ2QP6HN.mjs → chunk-5HELVQDL.mjs} +179 -249
  3. package/dist/development/{chunk-S2WJDCRE.js → chunk-KCPD675I.js} +173 -243
  4. package/dist/{production/chunk-NIW37A6Q.js → development/chunk-KPVSYEOF.js} +135 -135
  5. package/dist/development/{chunk-QMIAKNRH.mjs → chunk-ZOYSFAC5.mjs} +56 -102
  6. package/dist/{production/context-DnZM5brG.d.mts → development/context-EwD9faH7.d.mts} +34 -33
  7. package/dist/development/dom-export.d.mts +3 -3
  8. package/dist/development/dom-export.d.ts +2 -2
  9. package/dist/development/dom-export.js +7 -7
  10. package/dist/development/dom-export.mjs +7 -7
  11. package/dist/development/{index-react-server-client-zr5eNeut.d.ts → index-react-server-client-CjrUmqhw.d.ts} +12 -12
  12. package/dist/{production/index-react-server-client-9rHNv-U3.d.mts → development/index-react-server-client-DDdP8ud2.d.mts} +13 -13
  13. package/dist/development/index-react-server-client.d.mts +3 -3
  14. package/dist/development/index-react-server-client.d.ts +2 -2
  15. package/dist/development/index-react-server-client.js +4 -4
  16. package/dist/development/index-react-server-client.mjs +2 -2
  17. package/dist/development/index-react-server.d.mts +76 -38
  18. package/dist/development/index-react-server.d.ts +76 -38
  19. package/dist/development/index-react-server.js +116 -112
  20. package/dist/development/index-react-server.mjs +114 -111
  21. package/dist/development/index.d.mts +53 -15
  22. package/dist/development/index.d.ts +51 -13
  23. package/dist/development/index.js +138 -184
  24. package/dist/development/index.mjs +7 -7
  25. package/dist/development/lib/types/internal.d.mts +11 -8
  26. package/dist/development/lib/types/internal.d.ts +10 -7
  27. package/dist/development/lib/types/internal.js +1 -1
  28. package/dist/development/lib/types/internal.mjs +1 -1
  29. package/dist/development/{route-data-C24VEkoE.d.mts → route-data-CAnRKu1U.d.mts} +14 -14
  30. package/dist/development/{routeModules-FY5IBiA_.d.ts → routeModules-CQWjJ9NX.d.ts} +46 -45
  31. package/dist/production/{chunk-2BFZ6QQU.mjs → chunk-5W7O3ZZ2.mjs} +179 -249
  32. package/dist/production/{chunk-OFC37UQM.mjs → chunk-DZS627TW.mjs} +56 -102
  33. package/dist/production/{chunk-7CWVKQLP.js → chunk-NLCKEFES.js} +173 -243
  34. package/dist/{development/chunk-LSB26UC6.js → production/chunk-TC5SCO6O.js} +135 -135
  35. package/dist/{development/context-DnZM5brG.d.mts → production/context-EwD9faH7.d.mts} +34 -33
  36. package/dist/production/dom-export.d.mts +3 -3
  37. package/dist/production/dom-export.d.ts +2 -2
  38. package/dist/production/dom-export.js +7 -7
  39. package/dist/production/dom-export.mjs +7 -7
  40. package/dist/production/{index-react-server-client-zr5eNeut.d.ts → index-react-server-client-CjrUmqhw.d.ts} +12 -12
  41. package/dist/{development/index-react-server-client-9rHNv-U3.d.mts → production/index-react-server-client-DDdP8ud2.d.mts} +13 -13
  42. package/dist/production/index-react-server-client.d.mts +3 -3
  43. package/dist/production/index-react-server-client.d.ts +2 -2
  44. package/dist/production/index-react-server-client.js +4 -4
  45. package/dist/production/index-react-server-client.mjs +2 -2
  46. package/dist/production/index-react-server.d.mts +76 -38
  47. package/dist/production/index-react-server.d.ts +76 -38
  48. package/dist/production/index-react-server.js +116 -112
  49. package/dist/production/index-react-server.mjs +114 -111
  50. package/dist/production/index.d.mts +53 -15
  51. package/dist/production/index.d.ts +51 -13
  52. package/dist/production/index.js +138 -184
  53. package/dist/production/index.mjs +7 -7
  54. package/dist/production/lib/types/internal.d.mts +11 -8
  55. package/dist/production/lib/types/internal.d.ts +10 -7
  56. package/dist/production/lib/types/internal.js +1 -1
  57. package/dist/production/lib/types/internal.mjs +1 -1
  58. package/dist/production/{route-data-C24VEkoE.d.mts → route-data-CAnRKu1U.d.mts} +14 -14
  59. package/dist/production/{routeModules-FY5IBiA_.d.ts → routeModules-CQWjJ9NX.d.ts} +46 -45
  60. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-3d7dcee
2
+ * react-router v0.0.0-experimental-426e5caec
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -362,13 +362,13 @@ function createBrowserURLImpl(to, isAbsolute = false) {
362
362
  }
363
363
 
364
364
  // lib/router/utils.ts
365
- function unstable_createContext(defaultValue) {
365
+ function createContext(defaultValue) {
366
366
  return { defaultValue };
367
367
  }
368
368
  var _map;
369
- var unstable_RouterContextProvider = class {
369
+ var RouterContextProvider = class {
370
370
  /**
371
- * Create a new `unstable_RouterContextProvider` instance
371
+ * Create a new `RouterContextProvider` instance
372
372
  * @param init An optional initial context map to populate the provider with
373
373
  */
374
374
  constructor(init) {
@@ -428,7 +428,7 @@ var unsupportedLazyRouteFunctionKeys = /* @__PURE__ */ new Set([
428
428
  "path",
429
429
  "id",
430
430
  "index",
431
- "unstable_middleware",
431
+ "middleware",
432
432
  "children"
433
433
  ]);
434
434
  function isUnsupportedLazyRouteFunctionKey(key) {
@@ -699,7 +699,7 @@ function generatePath(originalPath, params = {}) {
699
699
  const [, key, optional] = keyMatch;
700
700
  let param = params[key];
701
701
  invariant(optional === "?" || param != null, `Missing ":${key}" param`);
702
- return stringify2(param);
702
+ return encodeURIComponent(stringify2(param));
703
703
  }
704
704
  return segment.replace(/\?$/g, "");
705
705
  }).filter((segment) => !!segment);
@@ -1004,9 +1004,11 @@ function createRouter(init) {
1004
1004
  );
1005
1005
  let inFlightDataRoutes;
1006
1006
  let basename = init.basename || "/";
1007
+ if (!basename.startsWith("/")) {
1008
+ basename = `/${basename}`;
1009
+ }
1007
1010
  let dataStrategyImpl = init.dataStrategy || defaultDataStrategyWithMiddleware;
1008
1011
  let future = {
1009
- unstable_middleware: false,
1010
1012
  ...init.future
1011
1013
  };
1012
1014
  let unlistenHistory = null;
@@ -1464,7 +1466,7 @@ function createRouter(init) {
1464
1466
  pendingNavigationController.signal,
1465
1467
  opts && opts.submission
1466
1468
  );
1467
- let scopedContext = init.unstable_getContext ? await init.unstable_getContext() : new unstable_RouterContextProvider();
1469
+ let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
1468
1470
  let pendingActionResult;
1469
1471
  if (opts && opts.pendingError) {
1470
1472
  pendingActionResult = [
@@ -1553,6 +1555,19 @@ function createRouter(init) {
1553
1555
  if (discoverResult.type === "aborted") {
1554
1556
  return { shortCircuited: true };
1555
1557
  } else if (discoverResult.type === "error") {
1558
+ if (discoverResult.partialMatches.length === 0) {
1559
+ let { matches: matches2, route } = getShortCircuitMatches(dataRoutes);
1560
+ return {
1561
+ matches: matches2,
1562
+ pendingActionResult: [
1563
+ route.id,
1564
+ {
1565
+ type: "error" /* error */,
1566
+ error: discoverResult.error
1567
+ }
1568
+ ]
1569
+ };
1570
+ }
1556
1571
  let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
1557
1572
  return {
1558
1573
  matches: discoverResult.partialMatches,
@@ -1684,6 +1699,16 @@ function createRouter(init) {
1684
1699
  if (discoverResult.type === "aborted") {
1685
1700
  return { shortCircuited: true };
1686
1701
  } else if (discoverResult.type === "error") {
1702
+ if (discoverResult.partialMatches.length === 0) {
1703
+ let { matches: matches2, route } = getShortCircuitMatches(dataRoutes);
1704
+ return {
1705
+ matches: matches2,
1706
+ loaderData: {},
1707
+ errors: {
1708
+ [route.id]: discoverResult.error
1709
+ }
1710
+ };
1711
+ }
1687
1712
  let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
1688
1713
  return {
1689
1714
  matches: discoverResult.partialMatches,
@@ -1731,7 +1756,7 @@ function createRouter(init) {
1731
1756
  pendingActionResult
1732
1757
  );
1733
1758
  pendingNavigationLoadId = ++incrementingLoadId;
1734
- if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.unstable_middleware) && revalidatingFetchers.length === 0) {
1759
+ if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.middleware) && revalidatingFetchers.length === 0) {
1735
1760
  let updatedFetchers2 = markFetchRedirectsDone();
1736
1761
  completeNavigation(
1737
1762
  location,
@@ -1885,7 +1910,7 @@ function createRouter(init) {
1885
1910
  setFetcherError(key, routeId, error, { flushSync });
1886
1911
  return;
1887
1912
  }
1888
- let scopedContext = init.unstable_getContext ? await init.unstable_getContext() : new unstable_RouterContextProvider();
1913
+ let scopedContext = init.getContext ? await init.getContext() : new RouterContextProvider();
1889
1914
  let preventScrollReset = (opts && opts.preventScrollReset) === true;
1890
1915
  if (submission && isMutationMethod(submission.formMethod)) {
1891
1916
  await handleFetcherAction(
@@ -2736,13 +2761,13 @@ function createStaticHandler(routes, opts) {
2736
2761
  skipLoaderErrorBubbling,
2737
2762
  skipRevalidation,
2738
2763
  dataStrategy,
2739
- unstable_generateMiddlewareResponse: generateMiddlewareResponse
2764
+ generateMiddlewareResponse
2740
2765
  } = {}) {
2741
2766
  let url = new URL(request.url);
2742
2767
  let method = request.method;
2743
2768
  let location = createLocation("", createPath(url), null, "default");
2744
2769
  let matches = matchRoutes(dataRoutes, location, basename);
2745
- requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
2770
+ requestContext = requestContext != null ? requestContext : new RouterContextProvider();
2746
2771
  if (!isValidMethod(method) && method !== "HEAD") {
2747
2772
  let error = getInternalRouterError(405, { method });
2748
2773
  let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
@@ -2780,8 +2805,8 @@ function createStaticHandler(routes, opts) {
2780
2805
  }
2781
2806
  if (generateMiddlewareResponse) {
2782
2807
  invariant(
2783
- requestContext instanceof unstable_RouterContextProvider,
2784
- "When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
2808
+ requestContext instanceof RouterContextProvider,
2809
+ "When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
2785
2810
  );
2786
2811
  try {
2787
2812
  await loadLazyMiddlewareForMatches(
@@ -2801,7 +2826,7 @@ function createStaticHandler(routes, opts) {
2801
2826
  },
2802
2827
  async () => {
2803
2828
  let res = await generateMiddlewareResponse(
2804
- async (revalidationRequest) => {
2829
+ async (revalidationRequest, opts2 = {}) => {
2805
2830
  let result2 = await queryImpl(
2806
2831
  revalidationRequest,
2807
2832
  location,
@@ -2810,7 +2835,7 @@ function createStaticHandler(routes, opts) {
2810
2835
  dataStrategy || null,
2811
2836
  skipLoaderErrorBubbling === true,
2812
2837
  null,
2813
- filterMatchesToLoad || null,
2838
+ "filterMatchesToLoad" in opts2 ? opts2.filterMatchesToLoad ?? null : null,
2814
2839
  skipRevalidation === true
2815
2840
  );
2816
2841
  if (isResponse(result2)) {
@@ -2823,9 +2848,23 @@ function createStaticHandler(routes, opts) {
2823
2848
  return res;
2824
2849
  },
2825
2850
  async (error, routeId) => {
2826
- if (isResponse(error)) {
2851
+ if (isRedirectResponse(error)) {
2827
2852
  return error;
2828
2853
  }
2854
+ if (isResponse(error)) {
2855
+ try {
2856
+ error = new ErrorResponseImpl(
2857
+ error.status,
2858
+ error.statusText,
2859
+ await parseResponseBody(error)
2860
+ );
2861
+ } catch (e) {
2862
+ error = e;
2863
+ }
2864
+ }
2865
+ if (isDataWithResponseInit(error)) {
2866
+ error = dataWithResponseInitToErrorResponse(error);
2867
+ }
2829
2868
  if (renderedStaticContext) {
2830
2869
  if (routeId in renderedStaticContext.loaderData) {
2831
2870
  renderedStaticContext.loaderData[routeId] = void 0;
@@ -2894,13 +2933,13 @@ function createStaticHandler(routes, opts) {
2894
2933
  routeId,
2895
2934
  requestContext,
2896
2935
  dataStrategy,
2897
- unstable_generateMiddlewareResponse: generateMiddlewareResponse
2936
+ generateMiddlewareResponse
2898
2937
  } = {}) {
2899
2938
  let url = new URL(request.url);
2900
2939
  let method = request.method;
2901
2940
  let location = createLocation("", createPath(url), null, "default");
2902
2941
  let matches = matchRoutes(dataRoutes, location, basename);
2903
- requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
2942
+ requestContext = requestContext != null ? requestContext : new RouterContextProvider();
2904
2943
  if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
2905
2944
  throw getInternalRouterError(405, { method });
2906
2945
  } else if (!matches) {
@@ -2917,8 +2956,8 @@ function createStaticHandler(routes, opts) {
2917
2956
  }
2918
2957
  if (generateMiddlewareResponse) {
2919
2958
  invariant(
2920
- requestContext instanceof unstable_RouterContextProvider,
2921
- "When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
2959
+ requestContext instanceof RouterContextProvider,
2960
+ "When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `RouterContextProvider`"
2922
2961
  );
2923
2962
  await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties2);
2924
2963
  let response = await runServerMiddlewarePipeline(
@@ -2951,8 +2990,8 @@ function createStaticHandler(routes, opts) {
2951
2990
  return res;
2952
2991
  },
2953
2992
  (error) => {
2954
- if (isRouteErrorResponse(error)) {
2955
- return Promise.resolve(errorResponseToResponse(error));
2993
+ if (isDataWithResponseInit(error)) {
2994
+ return Promise.resolve(dataWithResponseInitToResponse(error));
2956
2995
  }
2957
2996
  if (isResponse(error)) {
2958
2997
  return Promise.resolve(error);
@@ -3281,8 +3320,12 @@ function createStaticHandler(routes, opts) {
3281
3320
  basename
3282
3321
  );
3283
3322
  }
3284
- if (isResponse(result.result) && isRouteRequest) {
3285
- throw result;
3323
+ if (isRouteRequest) {
3324
+ if (isResponse(result.result)) {
3325
+ throw result;
3326
+ } else if (isDataWithResponseInit(result.result)) {
3327
+ throw dataWithResponseInitToResponse(result.result);
3328
+ }
3286
3329
  }
3287
3330
  dataResults[match.route.id] = await convertDataStrategyResultToDataResult(result);
3288
3331
  })
@@ -3904,11 +3947,11 @@ function isNonNullable(value) {
3904
3947
  }
3905
3948
  function loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties2) {
3906
3949
  let promises = matches.map(({ route }) => {
3907
- if (typeof route.lazy !== "object" || !route.lazy.unstable_middleware) {
3950
+ if (typeof route.lazy !== "object" || !route.lazy.middleware) {
3908
3951
  return void 0;
3909
3952
  }
3910
3953
  return loadLazyRouteProperty({
3911
- key: "unstable_middleware",
3954
+ key: "middleware",
3912
3955
  route,
3913
3956
  manifest,
3914
3957
  mapRouteProperties: mapRouteProperties2
@@ -3926,214 +3969,124 @@ async function defaultDataStrategy(args) {
3926
3969
  return keyedResults;
3927
3970
  }
3928
3971
  async function defaultDataStrategyWithMiddleware(args) {
3929
- if (!args.matches.some((m) => m.route.unstable_middleware)) {
3972
+ if (!args.matches.some((m) => m.route.middleware)) {
3930
3973
  return defaultDataStrategy(args);
3931
3974
  }
3932
- let didCallHandler = false;
3933
- return runClientMiddlewarePipeline(
3975
+ return runClientMiddlewarePipeline(args, () => defaultDataStrategy(args));
3976
+ }
3977
+ function runServerMiddlewarePipeline(args, handler, errorHandler) {
3978
+ return runMiddlewarePipeline(
3934
3979
  args,
3935
- () => {
3936
- didCallHandler = true;
3937
- return defaultDataStrategy(args);
3938
- },
3939
- (error, routeId) => clientMiddlewareErrorHandler(
3940
- error,
3941
- routeId,
3942
- args.matches,
3943
- didCallHandler
3944
- )
3980
+ handler,
3981
+ processResult,
3982
+ isResponse,
3983
+ errorHandler
3945
3984
  );
3946
- }
3947
- function clientMiddlewareErrorHandler(error, routeId, matches, didCallHandler) {
3948
- if (didCallHandler) {
3949
- return {
3950
- [routeId]: { type: "error", result: error }
3951
- };
3952
- } else {
3953
- let maxBoundaryIdx = Math.min(
3954
- // Throwing route
3955
- matches.findIndex((m) => m.route.id === routeId) || 0,
3956
- // or the shallowest route that needs to load data
3957
- matches.findIndex((m) => m.unstable_shouldCallHandler()) || 0
3958
- );
3959
- let boundaryRouteId = findNearestBoundary(
3960
- matches,
3961
- matches[maxBoundaryIdx].route.id
3962
- ).route.id;
3963
- return {
3964
- [boundaryRouteId]: { type: "error", result: error }
3965
- };
3985
+ function processResult(result) {
3986
+ return isDataWithResponseInit(result) ? dataWithResponseInitToResponse(result) : result;
3966
3987
  }
3967
3988
  }
3968
- async function runServerMiddlewarePipeline(args, handler, errorHandler) {
3969
- let { matches, request, params, context } = args;
3970
- let tuples = matches.flatMap(
3971
- (m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
3972
- );
3973
- let result = await callServerRouteMiddleware(
3974
- { request, params, context },
3975
- tuples,
3989
+ function runClientMiddlewarePipeline(args, handler) {
3990
+ return runMiddlewarePipeline(
3991
+ args,
3976
3992
  handler,
3993
+ (r) => r,
3994
+ // No post-processing needed on the client
3995
+ isDataStrategyResults,
3977
3996
  errorHandler
3978
3997
  );
3979
- if (isResponse(result)) {
3980
- return result;
3981
- }
3982
- invariant(false, `Expected a Response to be returned from route middleware`);
3983
- }
3984
- async function callServerRouteMiddleware(args, middlewares, handler, errorHandler, idx = 0) {
3985
- let { request } = args;
3986
- if (request.signal.aborted) {
3987
- if (request.signal.reason) {
3988
- throw request.signal.reason;
3989
- }
3990
- throw new Error(
3991
- `Request aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
3992
- );
3993
- }
3994
- let tuple = middlewares[idx];
3995
- if (!tuple) {
3996
- let result = await handler();
3997
- return result;
3998
- }
3999
- let [routeId, middleware] = tuple;
4000
- let nextCalled = false;
4001
- let nextResult = void 0;
4002
- let next = async () => {
4003
- if (nextCalled) {
4004
- throw new Error("You may only call `next()` once per middleware");
4005
- }
4006
- nextCalled = true;
4007
- try {
4008
- let result = await callServerRouteMiddleware(
4009
- args,
4010
- middlewares,
4011
- handler,
4012
- errorHandler,
4013
- idx + 1
4014
- );
4015
- if (isDataWithResponseInit(result)) {
4016
- result = dataWithResponseInitToResponse(result);
4017
- }
4018
- nextResult = result;
4019
- return nextResult;
4020
- } catch (e) {
4021
- nextResult = await errorHandler(
4022
- // Convert thrown data() values to ErrorResponses
4023
- isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
4024
- routeId
3998
+ function errorHandler(error, routeId, nextResult) {
3999
+ if (nextResult) {
4000
+ return Promise.resolve(
4001
+ Object.assign(nextResult.value, {
4002
+ [routeId]: { type: "error", result: error }
4003
+ })
4025
4004
  );
4026
- return nextResult;
4027
- }
4028
- };
4029
- try {
4030
- let result = await middleware(
4031
- {
4032
- request: args.request,
4033
- params: args.params,
4034
- context: args.context
4035
- },
4036
- next
4037
- );
4038
- if (isDataWithResponseInit(result)) {
4039
- result = dataWithResponseInitToResponse(result);
4040
- }
4041
- if (nextCalled) {
4042
- return typeof result === "undefined" ? nextResult : result;
4043
- } else if (isResponse(result)) {
4044
- return result;
4045
4005
  } else {
4046
- nextResult = await next();
4047
- return nextResult;
4006
+ let { matches } = args;
4007
+ let maxBoundaryIdx = Math.min(
4008
+ // Throwing route
4009
+ matches.findIndex((m) => m.route.id === routeId) || 0,
4010
+ // or the shallowest route that needs to load data
4011
+ matches.findIndex((m) => m.unstable_shouldCallHandler()) || 0
4012
+ );
4013
+ let boundaryRouteId = findNearestBoundary(
4014
+ matches,
4015
+ matches[maxBoundaryIdx].route.id
4016
+ ).route.id;
4017
+ return Promise.resolve({
4018
+ [boundaryRouteId]: { type: "error", result: error }
4019
+ });
4048
4020
  }
4049
- } catch (e) {
4050
- let response = await errorHandler(
4051
- // Convert thrown data() values to ErrorResponses
4052
- isDataWithResponseInit(e) ? dataWithResponseInitToErrorResponse(e) : e,
4053
- routeId
4054
- );
4055
- return response;
4056
4021
  }
4057
4022
  }
4058
- async function runClientMiddlewarePipeline(args, handler, errorHandler) {
4023
+ async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
4059
4024
  let { matches, request, params, context } = args;
4060
4025
  let tuples = matches.flatMap(
4061
- (m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
4026
+ (m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
4062
4027
  );
4063
- let handlerResult = {};
4064
- await callClientRouteMiddleware(
4028
+ let result = await callRouteMiddleware(
4065
4029
  { request, params, context },
4066
4030
  tuples,
4067
4031
  handler,
4068
- errorHandler,
4069
- handlerResult
4032
+ processResult,
4033
+ isResult,
4034
+ errorHandler
4070
4035
  );
4071
- return handlerResult;
4036
+ return result;
4072
4037
  }
4073
- async function callClientRouteMiddleware(args, middlewares, handler, errorHandler, handlerResult = {}, idx = 0) {
4038
+ async function callRouteMiddleware(args, middlewares, handler, processResult, isResult, errorHandler, idx = 0) {
4074
4039
  let { request } = args;
4075
4040
  if (request.signal.aborted) {
4076
- if (request.signal.reason) {
4077
- throw request.signal.reason;
4078
- }
4079
- throw new Error(
4080
- `Request aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
4081
- );
4041
+ throw request.signal.reason ?? new Error(`Request aborted: ${request.method} ${request.url}`);
4082
4042
  }
4083
4043
  let tuple = middlewares[idx];
4084
4044
  if (!tuple) {
4085
4045
  let result = await handler();
4086
- Object.assign(handlerResult, result);
4087
- return;
4046
+ return result;
4088
4047
  }
4089
4048
  let [routeId, middleware] = tuple;
4090
- let nextCalled = false;
4049
+ let nextResult;
4091
4050
  let next = async () => {
4092
- if (nextCalled) {
4051
+ if (nextResult) {
4093
4052
  throw new Error("You may only call `next()` once per middleware");
4094
4053
  }
4095
- nextCalled = true;
4096
4054
  try {
4097
- let result = await callClientRouteMiddleware(
4055
+ let result = await callRouteMiddleware(
4098
4056
  args,
4099
4057
  middlewares,
4100
4058
  handler,
4059
+ processResult,
4060
+ isResult,
4101
4061
  errorHandler,
4102
- handlerResult,
4103
4062
  idx + 1
4104
4063
  );
4105
- Object.assign(handlerResult, result);
4106
- } catch (e) {
4107
- let result = await errorHandler(e, routeId);
4108
- Object.assign(handlerResult, result);
4064
+ nextResult = { value: result };
4065
+ return nextResult.value;
4066
+ } catch (error) {
4067
+ nextResult = { value: await errorHandler(error, routeId, nextResult) };
4068
+ return nextResult.value;
4109
4069
  }
4110
4070
  };
4111
4071
  try {
4112
- let result = await middleware(
4113
- {
4114
- request: args.request,
4115
- params: args.params,
4116
- context: args.context
4117
- },
4118
- next
4119
- );
4120
- if (typeof result !== "undefined") {
4121
- console.warn(
4122
- "client middlewares are not intended to return values, the value will be ignored",
4123
- result
4124
- );
4125
- }
4126
- if (!nextCalled) {
4127
- await next();
4072
+ let value = await middleware(args, next);
4073
+ let result = value != null ? processResult(value) : void 0;
4074
+ if (isResult(result)) {
4075
+ return result;
4076
+ } else if (nextResult) {
4077
+ return result ?? nextResult.value;
4078
+ } else {
4079
+ nextResult = { value: await next() };
4080
+ return nextResult.value;
4128
4081
  }
4129
4082
  } catch (error) {
4130
- let result = await errorHandler(error, routeId);
4131
- Object.assign(handlerResult, result);
4083
+ let response = await errorHandler(error, routeId, nextResult);
4084
+ return response;
4132
4085
  }
4133
4086
  }
4134
4087
  function getDataStrategyMatchLazyPromises(mapRouteProperties2, manifest, request, match, lazyRoutePropertiesToSkip) {
4135
4088
  let lazyMiddlewarePromise = loadLazyRouteProperty({
4136
- key: "unstable_middleware",
4089
+ key: "middleware",
4137
4090
  route: match.route,
4138
4091
  manifest,
4139
4092
  mapRouteProperties: mapRouteProperties2
@@ -4233,39 +4186,28 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
4233
4186
  context: scopedContext,
4234
4187
  matches
4235
4188
  };
4236
- let unstable_runClientMiddleware = isStaticHandler ? () => {
4189
+ let runClientMiddleware = isStaticHandler ? () => {
4237
4190
  throw new Error(
4238
- "You cannot call `unstable_runClientMiddleware()` from a static handler `dataStrategy`. Middleware is run outside of `dataStrategy` during SSR in order to bubble up the Response. You can enable middleware via the `respond` API in `query`/`queryRoute`"
4191
+ "You cannot call `runClientMiddleware()` from a static handler `dataStrategy`. Middleware is run outside of `dataStrategy` during SSR in order to bubble up the Response. You can enable middleware via the `respond` API in `query`/`queryRoute`"
4239
4192
  );
4240
4193
  } : (cb) => {
4241
4194
  let typedDataStrategyArgs = dataStrategyArgs;
4242
- let didCallHandler = false;
4243
- return runClientMiddlewarePipeline(
4244
- typedDataStrategyArgs,
4245
- () => {
4246
- didCallHandler = true;
4247
- return cb({
4248
- ...typedDataStrategyArgs,
4249
- fetcherKey,
4250
- unstable_runClientMiddleware: () => {
4251
- throw new Error(
4252
- "Cannot call `unstable_runClientMiddleware()` from within an `unstable_runClientMiddleware` handler"
4253
- );
4254
- }
4255
- });
4256
- },
4257
- (error, routeId) => clientMiddlewareErrorHandler(
4258
- error,
4259
- routeId,
4260
- matches,
4261
- didCallHandler
4262
- )
4263
- );
4195
+ return runClientMiddlewarePipeline(typedDataStrategyArgs, () => {
4196
+ return cb({
4197
+ ...typedDataStrategyArgs,
4198
+ fetcherKey,
4199
+ runClientMiddleware: () => {
4200
+ throw new Error(
4201
+ "Cannot call `runClientMiddleware()` from within an `runClientMiddleware` handler"
4202
+ );
4203
+ }
4204
+ });
4205
+ });
4264
4206
  };
4265
4207
  let results = await dataStrategyImpl({
4266
4208
  ...dataStrategyArgs,
4267
4209
  fetcherKey,
4268
- unstable_runClientMiddleware
4210
+ runClientMiddleware
4269
4211
  });
4270
4212
  try {
4271
4213
  await Promise.all(
@@ -4377,21 +4319,19 @@ async function callLoaderOrAction({
4377
4319
  }
4378
4320
  return result;
4379
4321
  }
4322
+ async function parseResponseBody(response) {
4323
+ let contentType = response.headers.get("Content-Type");
4324
+ if (contentType && /\bapplication\/json\b/.test(contentType)) {
4325
+ return response.body == null ? null : response.json();
4326
+ }
4327
+ return response.text();
4328
+ }
4380
4329
  async function convertDataStrategyResultToDataResult(dataStrategyResult) {
4381
4330
  let { result, type } = dataStrategyResult;
4382
4331
  if (isResponse(result)) {
4383
4332
  let data2;
4384
4333
  try {
4385
- let contentType = result.headers.get("Content-Type");
4386
- if (contentType && /\bapplication\/json\b/.test(contentType)) {
4387
- if (result.body == null) {
4388
- data2 = null;
4389
- } else {
4390
- data2 = await result.json();
4391
- }
4392
- } else {
4393
- data2 = await result.text();
4394
- }
4334
+ data2 = await parseResponseBody(result);
4395
4335
  } catch (e) {
4396
4336
  return { type: "error" /* error */, error: e };
4397
4337
  }
@@ -4721,10 +4661,7 @@ function isHashChangeOnly(a, b) {
4721
4661
  return false;
4722
4662
  }
4723
4663
  function dataWithResponseInitToResponse(data2) {
4724
- return new Response(
4725
- typeof data2.data === "string" ? data2.data : JSON.stringify(data2.data),
4726
- data2.init || void 0
4727
- );
4664
+ return Response.json(data2.data, data2.init ?? void 0);
4728
4665
  }
4729
4666
  function dataWithResponseInitToErrorResponse(data2) {
4730
4667
  return new ErrorResponseImpl(
@@ -4733,13 +4670,9 @@ function dataWithResponseInitToErrorResponse(data2) {
4733
4670
  data2.data
4734
4671
  );
4735
4672
  }
4736
- function errorResponseToResponse(error) {
4737
- return new Response(
4738
- typeof error.data === "string" ? error.data : JSON.stringify(error.data),
4739
- {
4740
- status: error.status,
4741
- statusText: error.statusText
4742
- }
4673
+ function isDataStrategyResults(result) {
4674
+ return result != null && typeof result === "object" && Object.entries(result).every(
4675
+ ([key, value]) => typeof key === "string" && isDataStrategyResult(value)
4743
4676
  );
4744
4677
  }
4745
4678
  function isDataStrategyResult(result) {
@@ -5660,7 +5593,7 @@ var hydrationRouteProperties = [
5660
5593
  function createMemoryRouter(routes, opts) {
5661
5594
  return createRouter({
5662
5595
  basename: opts?.basename,
5663
- unstable_getContext: opts?.unstable_getContext,
5596
+ getContext: opts?.getContext,
5664
5597
  future: opts?.future,
5665
5598
  history: createMemoryHistory({
5666
5599
  initialEntries: opts?.initialEntries,
@@ -7164,7 +7097,7 @@ function getTurboStreamSingleFetchDataStrategy(getRouter, manifest, routeModules
7164
7097
  ssr,
7165
7098
  basename
7166
7099
  );
7167
- return async (args) => args.unstable_runClientMiddleware(dataStrategy);
7100
+ return async (args) => args.runClientMiddleware(dataStrategy);
7168
7101
  }
7169
7102
  function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode, ssr, basename, shouldAllowOptOut = () => true) {
7170
7103
  return async (args) => {
@@ -7960,7 +7893,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
7960
7893
  Object.assign(dataRoute, {
7961
7894
  ...dataRoute,
7962
7895
  ...getRouteComponents(route, routeModule, isSpaMode),
7963
- unstable_middleware: routeModule.unstable_clientMiddleware,
7896
+ middleware: routeModule.clientMiddleware,
7964
7897
  handle: routeModule.handle,
7965
7898
  shouldRevalidate: getShouldRevalidateFunction(
7966
7899
  dataRoute.path,
@@ -8102,17 +8035,14 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
8102
8035
  }
8103
8036
  });
8104
8037
  } : void 0,
8105
- unstable_middleware: route.hasClientMiddleware ? async () => {
8106
- let { unstable_clientMiddleware } = route.clientMiddlewareModule ? await import(
8038
+ middleware: route.hasClientMiddleware ? async () => {
8039
+ let { clientMiddleware } = route.clientMiddlewareModule ? await import(
8107
8040
  /* @vite-ignore */
8108
8041
  /* webpackIgnore: true */
8109
8042
  route.clientMiddlewareModule
8110
8043
  ) : await getLazyRoute();
8111
- invariant2(
8112
- unstable_clientMiddleware,
8113
- "No `unstable_clientMiddleware` export found"
8114
- );
8115
- return unstable_clientMiddleware;
8044
+ invariant2(clientMiddleware, "No `clientMiddleware` export found");
8045
+ return clientMiddleware;
8116
8046
  } : void 0,
8117
8047
  shouldRevalidate: async () => {
8118
8048
  let lazyRoute = await getLazyRoute();
@@ -8193,7 +8123,7 @@ async function loadRouteModuleWithBlockingLinks(route, routeModules) {
8193
8123
  return {
8194
8124
  Component: getRouteModuleComponent(routeModule),
8195
8125
  ErrorBoundary: routeModule.ErrorBoundary,
8196
- unstable_clientMiddleware: routeModule.unstable_clientMiddleware,
8126
+ clientMiddleware: routeModule.clientMiddleware,
8197
8127
  clientAction: routeModule.clientAction,
8198
8128
  clientLoader: routeModule.clientLoader,
8199
8129
  handle: routeModule.handle,
@@ -9036,14 +8966,14 @@ var isBrowser = typeof window !== "undefined" && typeof window.document !== "und
9036
8966
  try {
9037
8967
  if (isBrowser) {
9038
8968
  window.__reactRouterVersion = // @ts-expect-error
9039
- "0.0.0-experimental-3d7dcee";
8969
+ "0.0.0-experimental-426e5caec";
9040
8970
  }
9041
8971
  } catch (e) {
9042
8972
  }
9043
8973
  function createBrowserRouter(routes, opts) {
9044
8974
  return createRouter({
9045
8975
  basename: opts?.basename,
9046
- unstable_getContext: opts?.unstable_getContext,
8976
+ getContext: opts?.getContext,
9047
8977
  future: opts?.future,
9048
8978
  history: createBrowserHistory({ window: opts?.window }),
9049
8979
  hydrationData: opts?.hydrationData || parseHydrationData(),
@@ -9058,7 +8988,7 @@ function createBrowserRouter(routes, opts) {
9058
8988
  function createHashRouter(routes, opts) {
9059
8989
  return createRouter({
9060
8990
  basename: opts?.basename,
9061
- unstable_getContext: opts?.unstable_getContext,
8991
+ getContext: opts?.getContext,
9062
8992
  future: opts?.future,
9063
8993
  history: createHashHistory({ window: opts?.window }),
9064
8994
  hydrationData: opts?.hydrationData || parseHydrationData(),
@@ -10027,7 +9957,7 @@ function createStaticRouter(routes, context, opts = {}) {
10027
9957
  },
10028
9958
  get future() {
10029
9959
  return {
10030
- unstable_middleware: false,
9960
+ v8_middleware: false,
10031
9961
  ...opts?.future
10032
9962
  };
10033
9963
  },
@@ -10133,8 +10063,8 @@ export {
10133
10063
  invariant,
10134
10064
  createPath,
10135
10065
  parsePath,
10136
- unstable_createContext,
10137
- unstable_RouterContextProvider,
10066
+ createContext,
10067
+ RouterContextProvider,
10138
10068
  convertRoutesToDataRoutes,
10139
10069
  matchRoutes,
10140
10070
  generatePath,