react-router 7.7.1 → 7.8.0-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 (66) hide show
  1. package/CHANGELOG.md +81 -5
  2. package/dist/development/browser-z32v5KVN.d.mts +46 -0
  3. package/dist/{production/chunk-K3SBCRK4.mjs → development/chunk-HSC5IU24.mjs} +177 -134
  4. package/dist/development/{chunk-K7YFBME3.js → chunk-IW6UADHO.js} +250 -187
  5. package/dist/development/{chunk-C37GKA54.mjs → chunk-SC4OUYO4.mjs} +232 -169
  6. package/dist/development/{chunk-R73PQUJU.js → chunk-Z4NNCWGU.js} +130 -130
  7. package/dist/development/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
  8. package/dist/{production/route-data-CqEmXQub.d.mts → development/context-DZWGFcKX.d.mts} +312 -524
  9. package/dist/development/dom-export.d.mts +16 -12
  10. package/dist/development/dom-export.d.ts +13 -8
  11. package/dist/development/dom-export.js +3 -3
  12. package/dist/development/dom-export.mjs +3 -3
  13. package/dist/{production/index-react-server-client-KLg-U4nr.d.mts → development/index-react-server-client-BUK-oRcG.d.mts} +327 -200
  14. package/dist/development/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
  15. package/dist/development/index-react-server-client.d.mts +4 -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 +291 -70
  20. package/dist/development/index-react-server.d.ts +291 -70
  21. package/dist/development/index-react-server.js +174 -180
  22. package/dist/development/index-react-server.mjs +174 -180
  23. package/dist/development/index.d.mts +294 -86
  24. package/dist/development/index.d.ts +136 -105
  25. package/dist/development/index.js +258 -215
  26. package/dist/development/index.mjs +3 -3
  27. package/dist/development/lib/types/internal.d.mts +13 -2
  28. package/dist/development/lib/types/internal.d.ts +12 -2
  29. package/dist/development/lib/types/internal.js +1 -1
  30. package/dist/development/lib/types/internal.mjs +1 -1
  31. package/dist/development/route-data-UTmTa8an.d.mts +473 -0
  32. package/dist/{production/routeModules-BR2FO0ix.d.ts → development/routeModules-D5bppTB2.d.ts} +325 -67
  33. package/dist/production/browser-z32v5KVN.d.mts +46 -0
  34. package/dist/production/{chunk-4DGLNKXF.js → chunk-BCLZG6QW.js} +130 -130
  35. package/dist/{development/chunk-KIUJAIYX.mjs → production/chunk-KQ5567DT.mjs} +177 -134
  36. package/dist/production/{chunk-IZ57JD2V.mjs → chunk-X2NPJMV2.mjs} +232 -169
  37. package/dist/production/{chunk-7OQROU2D.js → chunk-YC2ENCM3.js} +250 -187
  38. package/dist/production/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
  39. package/dist/{development/route-data-CqEmXQub.d.mts → production/context-DZWGFcKX.d.mts} +312 -524
  40. package/dist/production/dom-export.d.mts +16 -12
  41. package/dist/production/dom-export.d.ts +13 -8
  42. package/dist/production/dom-export.js +3 -3
  43. package/dist/production/dom-export.mjs +3 -3
  44. package/dist/{development/index-react-server-client-KLg-U4nr.d.mts → production/index-react-server-client-BUK-oRcG.d.mts} +327 -200
  45. package/dist/production/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
  46. package/dist/production/index-react-server-client.d.mts +4 -3
  47. package/dist/production/index-react-server-client.d.ts +2 -2
  48. package/dist/production/index-react-server-client.js +4 -4
  49. package/dist/production/index-react-server-client.mjs +2 -2
  50. package/dist/production/index-react-server.d.mts +291 -70
  51. package/dist/production/index-react-server.d.ts +291 -70
  52. package/dist/production/index-react-server.js +174 -180
  53. package/dist/production/index-react-server.mjs +174 -180
  54. package/dist/production/index.d.mts +294 -86
  55. package/dist/production/index.d.ts +136 -105
  56. package/dist/production/index.js +258 -215
  57. package/dist/production/index.mjs +3 -3
  58. package/dist/production/lib/types/internal.d.mts +13 -2
  59. package/dist/production/lib/types/internal.d.ts +12 -2
  60. package/dist/production/lib/types/internal.js +1 -1
  61. package/dist/production/lib/types/internal.mjs +1 -1
  62. package/dist/production/route-data-UTmTa8an.d.mts +473 -0
  63. package/dist/{development/routeModules-BR2FO0ix.d.ts → production/routeModules-D5bppTB2.d.ts} +325 -67
  64. package/package.json +1 -1
  65. package/dist/development/browser-7LYX59NK.d.mts +0 -226
  66. package/dist/production/browser-7LYX59NK.d.mts +0 -226
@@ -1,5 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
2
- * react-router v7.7.1
2
+ * react-router v7.8.0-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -367,6 +367,10 @@ function unstable_createContext(defaultValue) {
367
367
  }
368
368
  var _map;
369
369
  var unstable_RouterContextProvider = class {
370
+ /**
371
+ * Create a new `unstable_RouterContextProvider` instance
372
+ * @param init An optional initial context map to populate the provider with
373
+ */
370
374
  constructor(init) {
371
375
  __privateAdd(this, _map, /* @__PURE__ */ new Map());
372
376
  if (init) {
@@ -375,6 +379,14 @@ var unstable_RouterContextProvider = class {
375
379
  }
376
380
  }
377
381
  }
382
+ /**
383
+ * Access a value from the context. If no value has been set for the context,
384
+ * it will return the context's `defaultValue` if provided, or throw an error
385
+ * if no `defaultValue` was set.
386
+ * @param context The context to get the value for
387
+ * @returns The value for the context, or the context's `defaultValue` if no
388
+ * value was set
389
+ */
378
390
  get(context) {
379
391
  if (__privateGet(this, _map).has(context)) {
380
392
  return __privateGet(this, _map).get(context);
@@ -384,6 +396,14 @@ var unstable_RouterContextProvider = class {
384
396
  }
385
397
  throw new Error("No value found for context");
386
398
  }
399
+ /**
400
+ * Set a value for the context. If the context already has a value set, this
401
+ * will overwrite it.
402
+ *
403
+ * @param context The context to set the value for
404
+ * @param value The value to set for the context
405
+ * @returns {void}
406
+ */
387
407
  set(context, value) {
388
408
  __privateGet(this, _map).set(context, value);
389
409
  }
@@ -489,6 +509,7 @@ function convertRouteMatchToUiMatch(match, loaderData) {
489
509
  pathname,
490
510
  params,
491
511
  data: loaderData[route.id],
512
+ loaderData: loaderData[route.id],
492
513
  handle: route.handle
493
514
  };
494
515
  }
@@ -1434,9 +1455,7 @@ function createRouter(init) {
1434
1455
  pendingNavigationController.signal,
1435
1456
  opts && opts.submission
1436
1457
  );
1437
- let scopedContext = new unstable_RouterContextProvider(
1438
- init.unstable_getContext ? await init.unstable_getContext() : void 0
1439
- );
1458
+ let scopedContext = init.unstable_getContext ? await init.unstable_getContext() : new unstable_RouterContextProvider();
1440
1459
  let pendingActionResult;
1441
1460
  if (opts && opts.pendingError) {
1442
1461
  pendingActionResult = [
@@ -1703,7 +1722,7 @@ function createRouter(init) {
1703
1722
  pendingActionResult
1704
1723
  );
1705
1724
  pendingNavigationLoadId = ++incrementingLoadId;
1706
- if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && revalidatingFetchers.length === 0) {
1725
+ if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && !dsMatches.some((m) => m.route.unstable_middleware) && revalidatingFetchers.length === 0) {
1707
1726
  let updatedFetchers2 = markFetchRedirectsDone();
1708
1727
  completeNavigation(
1709
1728
  location,
@@ -1857,9 +1876,7 @@ function createRouter(init) {
1857
1876
  setFetcherError(key, routeId, error, { flushSync });
1858
1877
  return;
1859
1878
  }
1860
- let scopedContext = new unstable_RouterContextProvider(
1861
- init.unstable_getContext ? await init.unstable_getContext() : void 0
1862
- );
1879
+ let scopedContext = init.unstable_getContext ? await init.unstable_getContext() : new unstable_RouterContextProvider();
1863
1880
  let preventScrollReset = (opts && opts.preventScrollReset) === true;
1864
1881
  if (submission && isMutationMethod(submission.formMethod)) {
1865
1882
  await handleFetcherAction(
@@ -2710,20 +2727,13 @@ function createStaticHandler(routes, opts) {
2710
2727
  skipLoaderErrorBubbling,
2711
2728
  skipRevalidation,
2712
2729
  dataStrategy,
2713
- unstable_stream: stream,
2714
- unstable_respond: respond
2730
+ unstable_generateMiddlewareResponse: generateMiddlewareResponse
2715
2731
  } = {}) {
2716
2732
  let url = new URL(request.url);
2717
2733
  let method = request.method;
2718
2734
  let location = createLocation("", createPath(url), null, "default");
2719
2735
  let matches = matchRoutes(dataRoutes, location, basename);
2720
2736
  requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
2721
- let respondOrStreamStaticContext = (ctx) => {
2722
- return stream ? stream(
2723
- requestContext,
2724
- () => Promise.resolve(ctx)
2725
- ) : respond ? respond(ctx) : ctx;
2726
- };
2727
2737
  if (!isValidMethod(method) && method !== "HEAD") {
2728
2738
  let error = getInternalRouterError(405, { method });
2729
2739
  let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
@@ -2740,7 +2750,7 @@ function createStaticHandler(routes, opts) {
2740
2750
  loaderHeaders: {},
2741
2751
  actionHeaders: {}
2742
2752
  };
2743
- return respondOrStreamStaticContext(staticContext);
2753
+ return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
2744
2754
  } else if (!matches) {
2745
2755
  let error = getInternalRouterError(404, { pathname: location.pathname });
2746
2756
  let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
@@ -2757,11 +2767,9 @@ function createStaticHandler(routes, opts) {
2757
2767
  loaderHeaders: {},
2758
2768
  actionHeaders: {}
2759
2769
  };
2760
- return respondOrStreamStaticContext(staticContext);
2770
+ return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
2761
2771
  }
2762
- if (stream || respond && matches.some(
2763
- (m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
2764
- )) {
2772
+ if (generateMiddlewareResponse) {
2765
2773
  invariant(
2766
2774
  requestContext instanceof unstable_RouterContextProvider,
2767
2775
  "When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
@@ -2773,7 +2781,7 @@ function createStaticHandler(routes, opts) {
2773
2781
  mapRouteProperties
2774
2782
  );
2775
2783
  let renderedStaticContext;
2776
- let response = await runMiddlewarePipeline(
2784
+ let response = await runServerMiddlewarePipeline(
2777
2785
  {
2778
2786
  request,
2779
2787
  matches,
@@ -2782,45 +2790,27 @@ function createStaticHandler(routes, opts) {
2782
2790
  // this to the proper type knowing it's not an `AppLoadContext`
2783
2791
  context: requestContext
2784
2792
  },
2785
- true,
2786
2793
  async () => {
2787
- if (stream) {
2788
- let res2 = await stream(
2789
- requestContext,
2790
- async (revalidationRequest) => {
2791
- let result3 = await queryImpl(
2792
- revalidationRequest,
2793
- location,
2794
- matches,
2795
- requestContext,
2796
- dataStrategy || null,
2797
- skipLoaderErrorBubbling === true,
2798
- null,
2799
- filterMatchesToLoad || null,
2800
- skipRevalidation === true
2801
- );
2802
- return isResponse(result3) ? result3 : { location, basename, ...result3 };
2794
+ let res = await generateMiddlewareResponse(
2795
+ async (revalidationRequest) => {
2796
+ let result2 = await queryImpl(
2797
+ revalidationRequest,
2798
+ location,
2799
+ matches,
2800
+ requestContext,
2801
+ dataStrategy || null,
2802
+ skipLoaderErrorBubbling === true,
2803
+ null,
2804
+ filterMatchesToLoad || null,
2805
+ skipRevalidation === true
2806
+ );
2807
+ if (isResponse(result2)) {
2808
+ return result2;
2803
2809
  }
2804
- );
2805
- return res2;
2806
- }
2807
- invariant(respond, "Expected respond to be defined");
2808
- let result2 = await queryImpl(
2809
- request,
2810
- location,
2811
- matches,
2812
- requestContext,
2813
- dataStrategy || null,
2814
- skipLoaderErrorBubbling === true,
2815
- null,
2816
- filterMatchesToLoad || null,
2817
- skipRevalidation === true
2810
+ renderedStaticContext = { location, basename, ...result2 };
2811
+ return renderedStaticContext;
2812
+ }
2818
2813
  );
2819
- if (isResponse(result2)) {
2820
- return result2;
2821
- }
2822
- renderedStaticContext = { location, basename, ...result2 };
2823
- let res = await respond(renderedStaticContext);
2824
2814
  return res;
2825
2815
  },
2826
2816
  async (error, routeId) => {
@@ -2837,7 +2827,9 @@ function createStaticHandler(routes, opts) {
2837
2827
  error,
2838
2828
  skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
2839
2829
  );
2840
- return respondOrStreamStaticContext(staticContext);
2830
+ return generateMiddlewareResponse(
2831
+ () => Promise.resolve(staticContext)
2832
+ );
2841
2833
  } else {
2842
2834
  let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
2843
2835
  matches,
@@ -2858,7 +2850,9 @@ function createStaticHandler(routes, opts) {
2858
2850
  actionHeaders: {},
2859
2851
  loaderHeaders: {}
2860
2852
  };
2861
- return respondOrStreamStaticContext(staticContext);
2853
+ return generateMiddlewareResponse(
2854
+ () => Promise.resolve(staticContext)
2855
+ );
2862
2856
  }
2863
2857
  }
2864
2858
  );
@@ -2891,7 +2885,7 @@ function createStaticHandler(routes, opts) {
2891
2885
  routeId,
2892
2886
  requestContext,
2893
2887
  dataStrategy,
2894
- unstable_respond: respond
2888
+ unstable_generateMiddlewareResponse: generateMiddlewareResponse
2895
2889
  } = {}) {
2896
2890
  let url = new URL(request.url);
2897
2891
  let method = request.method;
@@ -2912,15 +2906,13 @@ function createStaticHandler(routes, opts) {
2912
2906
  } else if (!match) {
2913
2907
  throw getInternalRouterError(404, { pathname: location.pathname });
2914
2908
  }
2915
- if (respond && matches.some(
2916
- (m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
2917
- )) {
2909
+ if (generateMiddlewareResponse) {
2918
2910
  invariant(
2919
2911
  requestContext instanceof unstable_RouterContextProvider,
2920
2912
  "When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
2921
2913
  );
2922
2914
  await loadLazyMiddlewareForMatches(matches, manifest, mapRouteProperties);
2923
- let response = await runMiddlewarePipeline(
2915
+ let response = await runServerMiddlewarePipeline(
2924
2916
  {
2925
2917
  request,
2926
2918
  matches,
@@ -2929,37 +2921,31 @@ function createStaticHandler(routes, opts) {
2929
2921
  // this to the proper type knowing it's not an `AppLoadContext`
2930
2922
  context: requestContext
2931
2923
  },
2932
- true,
2933
2924
  async () => {
2934
- let result2 = await queryImpl(
2935
- request,
2936
- location,
2937
- matches,
2938
- requestContext,
2939
- dataStrategy || null,
2940
- false,
2941
- match,
2942
- null,
2943
- false
2925
+ let res = await generateMiddlewareResponse(
2926
+ async (innerRequest) => {
2927
+ let result2 = await queryImpl(
2928
+ innerRequest,
2929
+ location,
2930
+ matches,
2931
+ requestContext,
2932
+ dataStrategy || null,
2933
+ false,
2934
+ match,
2935
+ null,
2936
+ false
2937
+ );
2938
+ let processed = handleQueryResult(result2);
2939
+ return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
2940
+ }
2944
2941
  );
2945
- if (isResponse(result2)) {
2946
- return respond(result2);
2947
- }
2948
- let error2 = result2.errors ? Object.values(result2.errors)[0] : void 0;
2949
- if (error2 !== void 0) {
2950
- throw error2;
2951
- }
2952
- let value = result2.actionData ? Object.values(result2.actionData)[0] : Object.values(result2.loaderData)[0];
2953
- return typeof value === "string" ? new Response(value) : Response.json(value);
2942
+ return res;
2954
2943
  },
2955
- (error2) => {
2956
- if (isResponse(error2)) {
2957
- return respond(error2);
2944
+ (error) => {
2945
+ if (isResponse(error)) {
2946
+ return Promise.resolve(error);
2958
2947
  }
2959
- return new Response(String(error2), {
2960
- status: 500,
2961
- statusText: "Unexpected Server Error"
2962
- });
2948
+ throw error;
2963
2949
  }
2964
2950
  );
2965
2951
  return response;
@@ -2975,20 +2961,23 @@ function createStaticHandler(routes, opts) {
2975
2961
  null,
2976
2962
  false
2977
2963
  );
2978
- if (isResponse(result)) {
2979
- return result;
2980
- }
2981
- let error = result.errors ? Object.values(result.errors)[0] : void 0;
2982
- if (error !== void 0) {
2983
- throw error;
2984
- }
2985
- if (result.actionData) {
2986
- return Object.values(result.actionData)[0];
2987
- }
2988
- if (result.loaderData) {
2989
- return Object.values(result.loaderData)[0];
2964
+ return handleQueryResult(result);
2965
+ function handleQueryResult(result2) {
2966
+ if (isResponse(result2)) {
2967
+ return result2;
2968
+ }
2969
+ let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
2970
+ if (error !== void 0) {
2971
+ throw error;
2972
+ }
2973
+ if (result2.actionData) {
2974
+ return Object.values(result2.actionData)[0];
2975
+ }
2976
+ if (result2.loaderData) {
2977
+ return Object.values(result2.loaderData)[0];
2978
+ }
2979
+ return void 0;
2990
2980
  }
2991
- return void 0;
2992
2981
  }
2993
2982
  async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
2994
2983
  invariant(
@@ -3928,45 +3917,35 @@ async function defaultDataStrategyWithMiddleware(args) {
3928
3917
  if (!args.matches.some((m) => m.route.unstable_middleware)) {
3929
3918
  return defaultDataStrategy(args);
3930
3919
  }
3931
- return runMiddlewarePipeline(
3920
+ return runClientMiddlewarePipeline(
3932
3921
  args,
3933
- false,
3934
3922
  () => defaultDataStrategy(args),
3935
3923
  (error, routeId) => ({ [routeId]: { type: "error", result: error } })
3936
3924
  );
3937
3925
  }
3938
- async function runMiddlewarePipeline(args, propagateResult, handler, errorHandler) {
3926
+ async function runServerMiddlewarePipeline(args, handler, errorHandler) {
3939
3927
  let { matches, request, params, context } = args;
3940
- let middlewareState = {
3941
- handlerResult: void 0
3942
- };
3943
- try {
3944
- let tuples = matches.flatMap(
3945
- (m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
3946
- );
3947
- let result = await callRouteMiddleware(
3948
- { request, params, context },
3949
- tuples,
3950
- propagateResult,
3951
- middlewareState,
3952
- handler
3953
- );
3954
- return propagateResult ? result : middlewareState.handlerResult;
3955
- } catch (e) {
3956
- if (!middlewareState.middlewareError) {
3957
- throw e;
3958
- }
3959
- let result = await errorHandler(
3960
- middlewareState.middlewareError.error,
3961
- middlewareState.middlewareError.routeId
3928
+ let tuples = matches.flatMap(
3929
+ (m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
3930
+ );
3931
+ let result = await callServerRouteMiddleware(
3932
+ { request, params, context },
3933
+ tuples,
3934
+ handler,
3935
+ errorHandler
3936
+ );
3937
+ if (isDataWithResponseInit(result)) {
3938
+ return new Response(
3939
+ typeof result.data === "string" ? result.data : JSON.stringify(result.data),
3940
+ { ...result.init }
3962
3941
  );
3963
- if (propagateResult || !middlewareState.handlerResult) {
3964
- return result;
3965
- }
3966
- return Object.assign(middlewareState.handlerResult, result);
3967
3942
  }
3943
+ if (isResponse(result)) {
3944
+ return result;
3945
+ }
3946
+ invariant(false, `Expected a Response to be returned from route middleware`);
3968
3947
  }
3969
- async function callRouteMiddleware(args, middlewares, propagateResult, middlewareState, handler, idx = 0) {
3948
+ async function callServerRouteMiddleware(args, middlewares, handler, errorHandler, idx = 0) {
3970
3949
  let { request } = args;
3971
3950
  if (request.signal.aborted) {
3972
3951
  if (request.signal.reason) {
@@ -3978,8 +3957,8 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
3978
3957
  }
3979
3958
  let tuple = middlewares[idx];
3980
3959
  if (!tuple) {
3981
- middlewareState.handlerResult = await handler();
3982
- return middlewareState.handlerResult;
3960
+ let result = await handler();
3961
+ return result;
3983
3962
  }
3984
3963
  let [routeId, middleware] = tuple;
3985
3964
  let nextCalled = false;
@@ -3989,17 +3968,19 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
3989
3968
  throw new Error("You may only call `next()` once per middleware");
3990
3969
  }
3991
3970
  nextCalled = true;
3992
- let result = await callRouteMiddleware(
3993
- args,
3994
- middlewares,
3995
- propagateResult,
3996
- middlewareState,
3997
- handler,
3998
- idx + 1
3999
- );
4000
- if (propagateResult) {
3971
+ try {
3972
+ let result = await callServerRouteMiddleware(
3973
+ args,
3974
+ middlewares,
3975
+ handler,
3976
+ errorHandler,
3977
+ idx + 1
3978
+ );
4001
3979
  nextResult = result;
4002
3980
  return nextResult;
3981
+ } catch (e) {
3982
+ nextResult = await errorHandler(e, routeId);
3983
+ return nextResult;
4003
3984
  }
4004
3985
  };
4005
3986
  try {
@@ -4012,21 +3993,92 @@ async function callRouteMiddleware(args, middlewares, propagateResult, middlewar
4012
3993
  next
4013
3994
  );
4014
3995
  if (nextCalled) {
4015
- if (result === void 0) {
4016
- return nextResult;
4017
- } else {
4018
- return result;
4019
- }
3996
+ return typeof result === "undefined" ? nextResult : result;
3997
+ } else if (isResponse(result) || isDataWithResponseInit(result)) {
3998
+ return result;
4020
3999
  } else {
4021
- return next();
4000
+ nextResult = await next();
4001
+ return nextResult;
4022
4002
  }
4023
4003
  } catch (error) {
4024
- if (!middlewareState.middlewareError) {
4025
- middlewareState.middlewareError = { routeId, error };
4026
- } else if (middlewareState.middlewareError.error !== error) {
4027
- middlewareState.middlewareError = { routeId, error };
4004
+ let response = await errorHandler(error, routeId);
4005
+ return response;
4006
+ }
4007
+ }
4008
+ async function runClientMiddlewarePipeline(args, handler, errorHandler) {
4009
+ let { matches, request, params, context } = args;
4010
+ let tuples = matches.flatMap(
4011
+ (m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
4012
+ );
4013
+ let handlerResult = {};
4014
+ await callClientRouteMiddleware(
4015
+ { request, params, context },
4016
+ tuples,
4017
+ handler,
4018
+ errorHandler,
4019
+ handlerResult
4020
+ );
4021
+ return handlerResult;
4022
+ }
4023
+ async function callClientRouteMiddleware(args, middlewares, handler, errorHandler, handlerResult = {}, idx = 0) {
4024
+ let { request } = args;
4025
+ if (request.signal.aborted) {
4026
+ if (request.signal.reason) {
4027
+ throw request.signal.reason;
4028
4028
  }
4029
- throw error;
4029
+ throw new Error(
4030
+ `Request aborted without an \`AbortSignal.reason\`: ${request.method} ${request.url}`
4031
+ );
4032
+ }
4033
+ let tuple = middlewares[idx];
4034
+ if (!tuple) {
4035
+ let result = await handler();
4036
+ Object.assign(handlerResult, result);
4037
+ return;
4038
+ }
4039
+ let [routeId, middleware] = tuple;
4040
+ let nextCalled = false;
4041
+ let next = async () => {
4042
+ if (nextCalled) {
4043
+ throw new Error("You may only call `next()` once per middleware");
4044
+ }
4045
+ nextCalled = true;
4046
+ try {
4047
+ let result = await callClientRouteMiddleware(
4048
+ args,
4049
+ middlewares,
4050
+ handler,
4051
+ errorHandler,
4052
+ handlerResult,
4053
+ idx + 1
4054
+ );
4055
+ Object.assign(handlerResult, result);
4056
+ } catch (e) {
4057
+ let result = await errorHandler(e, routeId);
4058
+ Object.assign(handlerResult, result);
4059
+ }
4060
+ };
4061
+ try {
4062
+ let result = await middleware(
4063
+ {
4064
+ request: args.request,
4065
+ params: args.params,
4066
+ context: args.context
4067
+ },
4068
+ next
4069
+ );
4070
+ if (typeof result !== "undefined") {
4071
+ console.warn(
4072
+ "client middlewares are not intended to return values, the value will be ignored",
4073
+ result
4074
+ );
4075
+ }
4076
+ if (!nextCalled) {
4077
+ await next();
4078
+ }
4079
+ } catch (error) {
4080
+ let result = await errorHandler(error, routeId);
4081
+ Object.assign(handlerResult, result);
4030
4082
  }
4031
4083
  }
4032
4084
  function getDataStrategyMatchLazyPromises(mapRouteProperties, manifest, request, match, lazyRoutePropertiesToSkip) {
@@ -4137,9 +4189,8 @@ async function callDataStrategyImpl(dataStrategyImpl, request, matches, fetcherK
4137
4189
  );
4138
4190
  } : (cb) => {
4139
4191
  let typedDataStrategyArgs = dataStrategyArgs;
4140
- return runMiddlewarePipeline(
4192
+ return runClientMiddlewarePipeline(
4141
4193
  typedDataStrategyArgs,
4142
- false,
4143
4194
  () => cb({
4144
4195
  ...typedDataStrategyArgs,
4145
4196
  fetcherKey,
@@ -4477,11 +4528,12 @@ function processLoaderData(state, matches, results, pendingActionResult, revalid
4477
4528
  );
4478
4529
  revalidatingFetchers.filter((f) => !f.matches || f.matches.some((m) => m.shouldLoad)).forEach((rf) => {
4479
4530
  let { key, match, controller } = rf;
4480
- let result = fetcherResults[key];
4481
- invariant(result, "Did not find corresponding fetcher result");
4482
4531
  if (controller && controller.signal.aborted) {
4483
4532
  return;
4484
- } else if (isErrorResult(result)) {
4533
+ }
4534
+ let result = fetcherResults[key];
4535
+ invariant(result, "Did not find corresponding fetcher result");
4536
+ if (isErrorResult(result)) {
4485
4537
  let boundaryMatch = findNearestBoundary(state.matches, _optionalChain([match, 'optionalAccess', _59 => _59.route, 'access', _60 => _60.id]));
4486
4538
  if (!(errors && errors[boundaryMatch.route.id])) {
4487
4539
  errors = {
@@ -5804,6 +5856,12 @@ async function bubbleMiddlewareErrors(singleFetchPromise, matches, routesParams,
5804
5856
  let routeResult = fetchedData.routes[match.route.id];
5805
5857
  if ("error" in routeResult) {
5806
5858
  middlewareError = routeResult.error;
5859
+ if (_optionalChain([results, 'access', _62 => _62[match.route.id], 'optionalAccess', _63 => _63.result]) == null) {
5860
+ results[match.route.id] = {
5861
+ type: "error",
5862
+ result: middlewareError
5863
+ };
5864
+ }
5807
5865
  break;
5808
5866
  }
5809
5867
  }
@@ -5911,7 +5969,7 @@ async function fetchAndDecodeViaTurboStream(args, basename, targetRoutes) {
5911
5969
  }
5912
5970
  } else {
5913
5971
  let typed = decoded.value;
5914
- let routeId = _optionalChain([targetRoutes, 'optionalAccess', _62 => _62[0]]);
5972
+ let routeId = _optionalChain([targetRoutes, 'optionalAccess', _64 => _64[0]]);
5915
5973
  invariant2(routeId, "No routeId found for single fetch call decoding");
5916
5974
  if ("redirect" in typed) {
5917
5975
  data2 = { redirect: typed };
@@ -6222,7 +6280,7 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
6222
6280
  if (locationArg) {
6223
6281
  let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
6224
6282
  invariant(
6225
- parentPathnameBase === "/" || _optionalChain([parsedLocationArg, 'access', _63 => _63.pathname, 'optionalAccess', _64 => _64.startsWith, 'call', _65 => _65(parentPathnameBase)]),
6283
+ parentPathnameBase === "/" || _optionalChain([parsedLocationArg, 'access', _65 => _65.pathname, 'optionalAccess', _66 => _66.startsWith, 'call', _67 => _67(parentPathnameBase)]),
6226
6284
  `When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${parentPathnameBase}" but pathname "${parsedLocationArg.pathname}" was given in the \`location\` prop.`
6227
6285
  );
6228
6286
  location = parsedLocationArg;
@@ -6370,10 +6428,10 @@ function _renderMatches(matches, parentMatches = [], dataRouterState = null, fut
6370
6428
  }
6371
6429
  }
6372
6430
  let renderedMatches = matches;
6373
- let errors = _optionalChain([dataRouterState, 'optionalAccess', _66 => _66.errors]);
6431
+ let errors = _optionalChain([dataRouterState, 'optionalAccess', _68 => _68.errors]);
6374
6432
  if (errors != null) {
6375
6433
  let errorIndex = renderedMatches.findIndex(
6376
- (m) => m.route.id && _optionalChain([errors, 'optionalAccess', _67 => _67[m.route.id]]) !== void 0
6434
+ (m) => m.route.id && _optionalChain([errors, 'optionalAccess', _69 => _69[m.route.id]]) !== void 0
6377
6435
  );
6378
6436
  invariant(
6379
6437
  errorIndex >= 0,
@@ -6550,15 +6608,15 @@ function useRouteError() {
6550
6608
  if (error !== void 0) {
6551
6609
  return error;
6552
6610
  }
6553
- return _optionalChain([state, 'access', _68 => _68.errors, 'optionalAccess', _69 => _69[routeId]]);
6611
+ return _optionalChain([state, 'access', _70 => _70.errors, 'optionalAccess', _71 => _71[routeId]]);
6554
6612
  }
6555
6613
  function useAsyncValue() {
6556
6614
  let value = React3.useContext(AwaitContext);
6557
- return _optionalChain([value, 'optionalAccess', _70 => _70._data]);
6615
+ return _optionalChain([value, 'optionalAccess', _72 => _72._data]);
6558
6616
  }
6559
6617
  function useAsyncError() {
6560
6618
  let value = React3.useContext(AwaitContext);
6561
- return _optionalChain([value, 'optionalAccess', _71 => _71._error]);
6619
+ return _optionalChain([value, 'optionalAccess', _73 => _73._error]);
6562
6620
  }
6563
6621
  var blockerId = 0;
6564
6622
  function useBlocker(shouldBlock) {
@@ -6670,7 +6728,7 @@ function getKeyedLinksForMatches(matches, routeModules, manifest) {
6670
6728
  let route = manifest.routes[match.route.id];
6671
6729
  return [
6672
6730
  route && route.css ? route.css.map((href) => ({ rel: "stylesheet", href })) : [],
6673
- _optionalChain([module, 'optionalAccess', _72 => _72.links, 'optionalCall', _73 => _73()]) || []
6731
+ _optionalChain([module, 'optionalAccess', _74 => _74.links, 'optionalCall', _75 => _75()]) || []
6674
6732
  ];
6675
6733
  }).flat(2);
6676
6734
  let preloads = getModuleLinkHrefs(matches, manifest);
@@ -6771,7 +6829,7 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
6771
6829
  // param change, /users/123 -> /users/456
6772
6830
  currentMatches[index].pathname !== match.pathname || // splat param changed, which is not present in match.path
6773
6831
  // e.g. /files/images/avatar.jpg -> files/finances.xls
6774
- _optionalChain([currentMatches, 'access', _74 => _74[index], 'access', _75 => _75.route, 'access', _76 => _76.path, 'optionalAccess', _77 => _77.endsWith, 'call', _78 => _78("*")]) && currentMatches[index].params["*"] !== match.params["*"]
6832
+ _optionalChain([currentMatches, 'access', _76 => _76[index], 'access', _77 => _77.route, 'access', _78 => _78.path, 'optionalAccess', _79 => _79.endsWith, 'call', _80 => _80("*")]) && currentMatches[index].params["*"] !== match.params["*"]
6775
6833
  );
6776
6834
  };
6777
6835
  if (mode === "assets") {
@@ -6794,7 +6852,7 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
6794
6852
  location.pathname + location.search + location.hash,
6795
6853
  window.origin
6796
6854
  ),
6797
- currentParams: _optionalChain([currentMatches, 'access', _79 => _79[0], 'optionalAccess', _80 => _80.params]) || {},
6855
+ currentParams: _optionalChain([currentMatches, 'access', _81 => _81[0], 'optionalAccess', _82 => _82.params]) || {},
6798
6856
  nextUrl: new URL(page, window.origin),
6799
6857
  nextParams: match.params,
6800
6858
  defaultShouldRevalidate: true
@@ -7066,10 +7124,10 @@ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSp
7066
7124
  )
7067
7125
  });
7068
7126
  let hasInitialData = initialState && initialState.loaderData && route.id in initialState.loaderData;
7069
- let initialData = hasInitialData ? _optionalChain([initialState, 'optionalAccess', _81 => _81.loaderData, 'optionalAccess', _82 => _82[route.id]]) : void 0;
7127
+ let initialData = hasInitialData ? _optionalChain([initialState, 'optionalAccess', _83 => _83.loaderData, 'optionalAccess', _84 => _84[route.id]]) : void 0;
7070
7128
  let hasInitialError = initialState && initialState.errors && route.id in initialState.errors;
7071
- let initialError = hasInitialError ? _optionalChain([initialState, 'optionalAccess', _83 => _83.errors, 'optionalAccess', _84 => _84[route.id]]) : void 0;
7072
- let isHydrationRequest = needsRevalidation == null && (_optionalChain([routeModule, 'access', _85 => _85.clientLoader, 'optionalAccess', _86 => _86.hydrate]) === true || !route.hasLoader);
7129
+ let initialError = hasInitialError ? _optionalChain([initialState, 'optionalAccess', _85 => _85.errors, 'optionalAccess', _86 => _86[route.id]]) : void 0;
7130
+ let isHydrationRequest = needsRevalidation == null && (_optionalChain([routeModule, 'access', _87 => _87.clientLoader, 'optionalAccess', _88 => _88.hydrate]) === true || !route.hasLoader);
7073
7131
  dataRoute.loader = async ({ request, params, context }, singleFetch) => {
7074
7132
  try {
7075
7133
  let result = await prefetchStylesAndCallHandler(async () => {
@@ -7366,7 +7424,7 @@ function getPatchRoutesOnNavigationFunction(manifest, routeModules, ssr, routeDi
7366
7424
  function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscovery, isSpaMode) {
7367
7425
  React6.useEffect(() => {
7368
7426
  if (!isFogOfWarEnabled(routeDiscovery, ssr) || // @ts-expect-error - TS doesn't know about this yet
7369
- _optionalChain([window, 'access', _87 => _87.navigator, 'optionalAccess', _88 => _88.connection, 'optionalAccess', _89 => _89.saveData]) === true) {
7427
+ _optionalChain([window, 'access', _89 => _89.navigator, 'optionalAccess', _90 => _90.connection, 'optionalAccess', _91 => _91.saveData]) === true) {
7370
7428
  return;
7371
7429
  }
7372
7430
  function registerElement(el) {
@@ -7428,12 +7486,14 @@ function getManifestPath(_manifestPath, basename) {
7428
7486
  }
7429
7487
  var MANIFEST_VERSION_STORAGE_KEY = "react-router-manifest-version";
7430
7488
  async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal) {
7489
+ const searchParams = new URLSearchParams();
7490
+ paths.sort().forEach((path) => searchParams.append("p", path));
7491
+ searchParams.set("version", manifest.version);
7431
7492
  let url = new URL(
7432
7493
  getManifestPath(manifestPath, basename),
7433
7494
  window.location.origin
7434
7495
  );
7435
- paths.sort().forEach((path) => url.searchParams.append("p", path));
7436
- url.searchParams.set("version", manifest.version);
7496
+ url.search = searchParams.toString();
7437
7497
  if (url.toString().length > URL_LIMIT) {
7438
7498
  nextPaths.clear();
7439
7499
  return;
@@ -7467,7 +7527,7 @@ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, ro
7467
7527
  sessionStorage.removeItem(MANIFEST_VERSION_STORAGE_KEY);
7468
7528
  serverPatches = await res.json();
7469
7529
  } catch (e) {
7470
- if (_optionalChain([signal, 'optionalAccess', _90 => _90.aborted])) return;
7530
+ if (_optionalChain([signal, 'optionalAccess', _92 => _92.aborted])) return;
7471
7531
  throw e;
7472
7532
  }
7473
7533
  let knownRoutes = new Set(Object.keys(manifest.routes));
@@ -7611,7 +7671,7 @@ function getActiveMatches(matches, errors, isSpaMode) {
7611
7671
  return matches;
7612
7672
  }
7613
7673
  var CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
7614
- function Links() {
7674
+ function Links({ nonce }) {
7615
7675
  let { isSpaMode, manifest, routeModules, criticalCss } = useFrameworkContext();
7616
7676
  let { errors, matches: routerMatches } = useDataRouterStateContext();
7617
7677
  let matches = getActiveMatches(routerMatches, errors, isSpaMode);
@@ -7630,10 +7690,11 @@ function Links() {
7630
7690
  {
7631
7691
  ...{ [CRITICAL_CSS_DATA_ATTRIBUTE]: "" },
7632
7692
  rel: "stylesheet",
7633
- href: criticalCss.href
7693
+ href: criticalCss.href,
7694
+ nonce
7634
7695
  }
7635
7696
  ) : null, keyedLinks.map(
7636
- ({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React7.createElement(PrefetchPageLinks, { key, ...link }) : /* @__PURE__ */ React7.createElement("link", { key, ...link })
7697
+ ({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React7.createElement(PrefetchPageLinks, { key, nonce, ...link }) : /* @__PURE__ */ React7.createElement("link", { key, nonce, ...link })
7637
7698
  ));
7638
7699
  }
7639
7700
  function PrefetchPageLinks({ page, ...linkProps }) {
@@ -7707,7 +7768,7 @@ function PrefetchPageLinksImpl({
7707
7768
  if (!manifestRoute || !manifestRoute.hasLoader) {
7708
7769
  return;
7709
7770
  }
7710
- if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && _optionalChain([routeModules, 'access', _91 => _91[m.route.id], 'optionalAccess', _92 => _92.shouldRevalidate])) {
7771
+ if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && _optionalChain([routeModules, 'access', _93 => _93[m.route.id], 'optionalAccess', _94 => _94.shouldRevalidate])) {
7711
7772
  foundOptOutRoute = true;
7712
7773
  } else if (manifestRoute.hasClientLoader) {
7713
7774
  foundOptOutRoute = true;
@@ -7744,7 +7805,7 @@ function PrefetchPageLinksImpl({
7744
7805
  return /* @__PURE__ */ React7.createElement(React7.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React7.createElement("link", { key: href, rel: "prefetch", as: "fetch", href, ...linkProps })), moduleHrefs.map((href) => /* @__PURE__ */ React7.createElement("link", { key: href, rel: "modulepreload", href, ...linkProps })), keyedPrefetchLinks.map(({ key, link }) => (
7745
7806
  // these don't spread `linkProps` because they are full link descriptors
7746
7807
  // already with their own props
7747
- /* @__PURE__ */ React7.createElement("link", { key, ...link })
7808
+ /* @__PURE__ */ React7.createElement("link", { key, nonce: linkProps.nonce, ...link })
7748
7809
  )));
7749
7810
  }
7750
7811
  function Meta() {
@@ -7773,6 +7834,7 @@ function Meta() {
7773
7834
  let match = {
7774
7835
  id: routeId,
7775
7836
  data: data2,
7837
+ loaderData: data2,
7776
7838
  meta: [],
7777
7839
  params: _match.params,
7778
7840
  pathname: _match.pathname,
@@ -7780,9 +7842,10 @@ function Meta() {
7780
7842
  error
7781
7843
  };
7782
7844
  matches[i] = match;
7783
- if (_optionalChain([routeModule, 'optionalAccess', _93 => _93.meta])) {
7845
+ if (_optionalChain([routeModule, 'optionalAccess', _95 => _95.meta])) {
7784
7846
  routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
7785
7847
  data: data2,
7848
+ loaderData: data2,
7786
7849
  params,
7787
7850
  location,
7788
7851
  matches,
@@ -7875,7 +7938,7 @@ function Scripts(scriptProps) {
7875
7938
  }
7876
7939
  let streamScript = "window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());";
7877
7940
  let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};${streamScript}` : " ";
7878
- let routeModulesScript = !isStatic ? " " : `${_optionalChain([manifest, 'access', _94 => _94.hmr, 'optionalAccess', _95 => _95.runtime]) ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
7941
+ let routeModulesScript = !isStatic ? " " : `${_optionalChain([manifest, 'access', _96 => _96.hmr, 'optionalAccess', _97 => _97.runtime]) ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
7879
7942
  ${matches.map((match, routeIndex) => {
7880
7943
  let routeVarName = `route${routeIndex}`;
7881
7944
  let manifestEntry = manifest.routes[match.route.id];
@@ -8105,7 +8168,7 @@ function BoundaryShell({
8105
8168
  children
8106
8169
  }) {
8107
8170
  let { routeModules } = useFrameworkContext();
8108
- if (_optionalChain([routeModules, 'access', _96 => _96.root, 'optionalAccess', _97 => _97.Layout]) && !isOutsideRemixApp) {
8171
+ if (_optionalChain([routeModules, 'access', _98 => _98.root, 'optionalAccess', _99 => _99.Layout]) && !isOutsideRemixApp) {
8109
8172
  return children;
8110
8173
  }
8111
8174
  return /* @__PURE__ */ React8.createElement("html", { lang: "en" }, /* @__PURE__ */ React8.createElement("head", null, /* @__PURE__ */ React8.createElement("meta", { charSet: "utf-8" }), /* @__PURE__ */ React8.createElement(