react-router 0.0.0-experimental-2a6c7bc → 0.0.0-experimental-e89ad3012

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 (61) hide show
  1. package/dist/development/{chunk-VEWXUMGM.mjs → chunk-3O4L5GVQ.mjs} +90 -125
  2. package/dist/development/{chunk-JRLTRGBE.js → chunk-JJHCVRDZ.js} +89 -124
  3. package/dist/development/{chunk-GSZ4XTPZ.js → chunk-ROJMZUUV.js} +130 -130
  4. package/dist/{production/chunk-ATNMTWNA.mjs → development/chunk-XKV32KFX.mjs} +157 -141
  5. package/dist/development/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
  6. package/dist/development/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
  7. package/dist/development/dom-export.d.mts +3 -3
  8. package/dist/development/dom-export.d.ts +1 -1
  9. package/dist/development/dom-export.js +3 -3
  10. package/dist/development/dom-export.mjs +3 -3
  11. package/dist/{production/index-react-server-client-DIZWnqdE.d.ts → development/index-react-server-client-D-lyvxf_.d.ts} +25 -26
  12. package/dist/{production/index-react-server-client-BuCmY0hu.d.mts → development/index-react-server-client-pe1TAKAq.d.mts} +12 -13
  13. package/dist/development/index-react-server-client.d.mts +4 -4
  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 +193 -14
  18. package/dist/development/index-react-server.d.ts +193 -14
  19. package/dist/development/index-react-server.js +115 -147
  20. package/dist/development/index-react-server.mjs +115 -147
  21. package/dist/development/index.d.mts +8 -8
  22. package/dist/development/index.d.ts +4 -4
  23. package/dist/development/index.js +240 -224
  24. package/dist/development/index.mjs +3 -3
  25. package/dist/development/lib/types/internal.d.mts +2 -2
  26. package/dist/development/lib/types/internal.d.ts +1 -1
  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-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
  30. package/dist/development/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
  31. package/dist/{development/chunk-M2KD4YIT.mjs → production/chunk-J6PLTU3O.mjs} +157 -141
  32. package/dist/production/{chunk-3UOGQQWX.js → chunk-NFNPXIQE.js} +89 -124
  33. package/dist/production/{chunk-P2JVUBYL.mjs → chunk-QI3NR5VQ.mjs} +90 -125
  34. package/dist/production/{chunk-ZIOZTUIH.js → chunk-X3M2F3OK.js} +130 -130
  35. package/dist/production/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
  36. package/dist/production/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
  37. package/dist/production/dom-export.d.mts +3 -3
  38. package/dist/production/dom-export.d.ts +1 -1
  39. package/dist/production/dom-export.js +3 -3
  40. package/dist/production/dom-export.mjs +3 -3
  41. package/dist/{development/index-react-server-client-DIZWnqdE.d.ts → production/index-react-server-client-D-lyvxf_.d.ts} +25 -26
  42. package/dist/{development/index-react-server-client-BuCmY0hu.d.mts → production/index-react-server-client-pe1TAKAq.d.mts} +12 -13
  43. package/dist/production/index-react-server-client.d.mts +4 -4
  44. package/dist/production/index-react-server-client.d.ts +2 -2
  45. package/dist/production/index-react-server-client.js +4 -4
  46. package/dist/production/index-react-server-client.mjs +2 -2
  47. package/dist/production/index-react-server.d.mts +193 -14
  48. package/dist/production/index-react-server.d.ts +193 -14
  49. package/dist/production/index-react-server.js +115 -147
  50. package/dist/production/index-react-server.mjs +115 -147
  51. package/dist/production/index.d.mts +8 -8
  52. package/dist/production/index.d.ts +4 -4
  53. package/dist/production/index.js +240 -224
  54. package/dist/production/index.mjs +3 -3
  55. package/dist/production/lib/types/internal.d.mts +2 -2
  56. package/dist/production/lib/types/internal.d.ts +1 -1
  57. package/dist/production/lib/types/internal.js +1 -1
  58. package/dist/production/lib/types/internal.mjs +1 -1
  59. package/dist/production/{route-data-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
  60. package/dist/production/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
  61. package/package.json +1 -1
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
27
27
  var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
28
28
 
29
29
  /**
30
- * react-router v0.0.0-experimental-2a6c7bc
30
+ * react-router v0.0.0-experimental-e89ad3012
31
31
  *
32
32
  * Copyright (c) Remix Software Inc.
33
33
  *
@@ -113,6 +113,10 @@ function unstable_createContext(defaultValue) {
113
113
  }
114
114
  var _map;
115
115
  var unstable_RouterContextProvider = class {
116
+ /**
117
+ * Create a new `unstable_RouterContextProvider` instance
118
+ * @param init An optional initial context map to populate the provider with
119
+ */
116
120
  constructor(init) {
117
121
  __privateAdd(this, _map, /* @__PURE__ */ new Map());
118
122
  if (init) {
@@ -121,6 +125,14 @@ var unstable_RouterContextProvider = class {
121
125
  }
122
126
  }
123
127
  }
128
+ /**
129
+ * Access a value from the context. If no value has been set for the
130
+ * context, it will return the context's `defaultValue` if provided, or throw an
131
+ * error if no `defaultValue` was set.
132
+ * @param context The context to get the value for
133
+ * @returns The value for the context, or the contexts `defaultValue` if no
134
+ * value was set
135
+ */
124
136
  get(context) {
125
137
  if (__privateGet(this, _map).has(context)) {
126
138
  return __privateGet(this, _map).get(context);
@@ -130,6 +142,14 @@ var unstable_RouterContextProvider = class {
130
142
  }
131
143
  throw new Error("No value found for context");
132
144
  }
145
+ /**
146
+ * Set a value for the context. If the context already has a value set,
147
+ * this will overwrite it.
148
+ *
149
+ * @param context The context to set the value for
150
+ * @param value The value to set for the context
151
+ * @returns {void}
152
+ */
133
153
  set(context, value) {
134
154
  __privateGet(this, _map).set(context, value);
135
155
  }
@@ -666,20 +686,13 @@ function createStaticHandler(routes, opts) {
666
686
  skipLoaderErrorBubbling,
667
687
  skipRevalidation,
668
688
  dataStrategy,
669
- unstable_stream: stream,
670
- unstable_respond: respond
689
+ unstable_generateMiddlewareResponse: generateMiddlewareResponse
671
690
  } = {}) {
672
691
  let url = new URL(request.url);
673
692
  let method = request.method;
674
693
  let location = createLocation("", createPath(url), null, "default");
675
694
  let matches = matchRoutes(dataRoutes, location, basename);
676
695
  requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
677
- let shortCircuitResult = (ctx) => {
678
- return stream ? stream(
679
- requestContext,
680
- () => Promise.resolve(ctx)
681
- ) : respond ? respond(ctx) : ctx;
682
- };
683
696
  if (!isValidMethod(method) && method !== "HEAD") {
684
697
  let error = getInternalRouterError(405, { method });
685
698
  let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
@@ -696,7 +709,7 @@ function createStaticHandler(routes, opts) {
696
709
  loaderHeaders: {},
697
710
  actionHeaders: {}
698
711
  };
699
- return shortCircuitResult(staticContext);
712
+ return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
700
713
  } else if (!matches) {
701
714
  let error = getInternalRouterError(404, { pathname: location.pathname });
702
715
  let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
@@ -713,11 +726,9 @@ function createStaticHandler(routes, opts) {
713
726
  loaderHeaders: {},
714
727
  actionHeaders: {}
715
728
  };
716
- return shortCircuitResult(staticContext);
729
+ return generateMiddlewareResponse ? generateMiddlewareResponse(() => Promise.resolve(staticContext)) : staticContext;
717
730
  }
718
- if (stream || respond && matches.some(
719
- (m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
720
- )) {
731
+ if (generateMiddlewareResponse) {
721
732
  invariant(
722
733
  requestContext instanceof unstable_RouterContextProvider,
723
734
  "When using middleware in `staticHandler.query()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
@@ -740,43 +751,26 @@ function createStaticHandler(routes, opts) {
740
751
  },
741
752
  true,
742
753
  async () => {
743
- if (stream) {
744
- let res2 = await stream(
745
- requestContext,
746
- async (revalidationRequest) => {
747
- let result3 = await queryImpl(
748
- revalidationRequest,
749
- location,
750
- matches,
751
- requestContext,
752
- dataStrategy || null,
753
- skipLoaderErrorBubbling === true,
754
- null,
755
- filterMatchesToLoad || null,
756
- skipRevalidation === true
757
- );
758
- return isResponse(result3) ? result3 : { location, basename, ...result3 };
754
+ let res = await generateMiddlewareResponse(
755
+ async (revalidationRequest) => {
756
+ let result2 = await queryImpl(
757
+ revalidationRequest,
758
+ location,
759
+ matches,
760
+ requestContext,
761
+ dataStrategy || null,
762
+ skipLoaderErrorBubbling === true,
763
+ null,
764
+ filterMatchesToLoad || null,
765
+ skipRevalidation === true
766
+ );
767
+ if (isResponse(result2)) {
768
+ return result2;
759
769
  }
760
- );
761
- return res2;
762
- }
763
- invariant(respond, "Expected respond to be defined");
764
- let result2 = await queryImpl(
765
- request,
766
- location,
767
- matches,
768
- requestContext,
769
- dataStrategy || null,
770
- skipLoaderErrorBubbling === true,
771
- null,
772
- filterMatchesToLoad || null,
773
- skipRevalidation === true
770
+ renderedStaticContext = { location, basename, ...result2 };
771
+ return renderedStaticContext;
772
+ }
774
773
  );
775
- if (isResponse(result2)) {
776
- return result2;
777
- }
778
- renderedStaticContext = { location, basename, ...result2 };
779
- let res = await respond(renderedStaticContext);
780
774
  return res;
781
775
  },
782
776
  async (error, routeId) => {
@@ -793,7 +787,9 @@ function createStaticHandler(routes, opts) {
793
787
  error,
794
788
  skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
795
789
  );
796
- return stream ? stream(requestContext, () => Promise.resolve(staticContext)) : respond(staticContext);
790
+ return generateMiddlewareResponse(
791
+ () => Promise.resolve(staticContext)
792
+ );
797
793
  } else {
798
794
  let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
799
795
  matches,
@@ -814,7 +810,9 @@ function createStaticHandler(routes, opts) {
814
810
  actionHeaders: {},
815
811
  loaderHeaders: {}
816
812
  };
817
- return stream ? stream(requestContext, () => Promise.resolve(staticContext)) : respond(staticContext);
813
+ return generateMiddlewareResponse(
814
+ () => Promise.resolve(staticContext)
815
+ );
818
816
  }
819
817
  }
820
818
  );
@@ -847,8 +845,7 @@ function createStaticHandler(routes, opts) {
847
845
  routeId,
848
846
  requestContext,
849
847
  dataStrategy,
850
- unstable_respond: respond,
851
- unstable_stream: stream
848
+ unstable_generateMiddlewareResponse: generateMiddlewareResponse
852
849
  } = {}) {
853
850
  let url = new URL(request.url);
854
851
  let method = request.method;
@@ -869,9 +866,7 @@ function createStaticHandler(routes, opts) {
869
866
  } else if (!match) {
870
867
  throw getInternalRouterError(404, { pathname: location.pathname });
871
868
  }
872
- if (stream || respond && matches.some(
873
- (m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
874
- )) {
869
+ if (generateMiddlewareResponse) {
875
870
  invariant(
876
871
  requestContext instanceof unstable_RouterContextProvider,
877
872
  "When using middleware in `staticHandler.queryRoute()`, any provided `requestContext` must be an instance of `unstable_RouterContextProvider`"
@@ -888,63 +883,30 @@ function createStaticHandler(routes, opts) {
888
883
  },
889
884
  true,
890
885
  async () => {
891
- if (stream) {
892
- let res = await stream(
893
- requestContext,
894
- async (revalidationRequest) => {
895
- let result3 = await queryImpl(
896
- revalidationRequest,
897
- location,
898
- matches,
899
- requestContext,
900
- dataStrategy || null,
901
- false,
902
- match,
903
- null,
904
- false
905
- );
906
- if (isResponse(result3)) {
907
- return result3;
908
- }
909
- let error3 = result3.errors ? Object.values(result3.errors)[0] : void 0;
910
- if (error3 !== void 0) {
911
- throw error3;
912
- }
913
- let value2 = result3.actionData ? Object.values(result3.actionData)[0] : Object.values(result3.loaderData)[0];
914
- return typeof value2 === "string" ? new Response(value2) : Response.json(value2);
915
- }
916
- );
917
- return res;
918
- }
919
- invariant(respond, "Expected respond to be defined");
920
- let result2 = await queryImpl(
921
- request,
922
- location,
923
- matches,
924
- requestContext,
925
- dataStrategy || null,
926
- false,
927
- match,
928
- null,
929
- false
930
- );
931
- if (isResponse(result2)) {
932
- return respond(result2);
933
- }
934
- let error2 = result2.errors ? Object.values(result2.errors)[0] : void 0;
935
- if (error2 !== void 0) {
936
- throw error2;
937
- }
938
- let value = result2.actionData ? Object.values(result2.actionData)[0] : Object.values(result2.loaderData)[0];
939
- return respond(
940
- typeof value === "string" ? new Response(value) : Response.json(value)
886
+ let res = await generateMiddlewareResponse(
887
+ async (innerRequest) => {
888
+ let result2 = await queryImpl(
889
+ innerRequest,
890
+ location,
891
+ matches,
892
+ requestContext,
893
+ dataStrategy || null,
894
+ false,
895
+ match,
896
+ null,
897
+ false
898
+ );
899
+ let processed = handleQueryResult(result2);
900
+ return isResponse(processed) ? processed : typeof processed === "string" ? new Response(processed) : Response.json(processed);
901
+ }
941
902
  );
903
+ return res;
942
904
  },
943
- (error2) => {
944
- if (isResponse(error2)) {
945
- return respond ? respond(error2) : error2;
905
+ (error) => {
906
+ if (isResponse(error)) {
907
+ return error;
946
908
  }
947
- throw error2;
909
+ throw error;
948
910
  }
949
911
  );
950
912
  return response;
@@ -960,20 +922,23 @@ function createStaticHandler(routes, opts) {
960
922
  null,
961
923
  false
962
924
  );
963
- if (isResponse(result)) {
964
- return result;
965
- }
966
- let error = result.errors ? Object.values(result.errors)[0] : void 0;
967
- if (error !== void 0) {
968
- throw error;
969
- }
970
- if (result.actionData) {
971
- return Object.values(result.actionData)[0];
972
- }
973
- if (result.loaderData) {
974
- return Object.values(result.loaderData)[0];
925
+ return handleQueryResult(result);
926
+ function handleQueryResult(result2) {
927
+ if (isResponse(result2)) {
928
+ return result2;
929
+ }
930
+ let error = result2.errors ? Object.values(result2.errors)[0] : void 0;
931
+ if (error !== void 0) {
932
+ throw error;
933
+ }
934
+ if (result2.actionData) {
935
+ return Object.values(result2.actionData)[0];
936
+ }
937
+ if (result2.loaderData) {
938
+ return Object.values(result2.loaderData)[0];
939
+ }
940
+ return void 0;
975
941
  }
976
- return void 0;
977
942
  }
978
943
  async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
979
944
  invariant(
@@ -2399,7 +2364,6 @@ async function processServerAction(request, basename, decodeReply, loadServerAct
2399
2364
  }
2400
2365
  }
2401
2366
  async function generateResourceResponse(request, routes, basename, routeId, requestContext, onError) {
2402
- let result;
2403
2367
  try {
2404
2368
  const staticHandler = createStaticHandler(routes, {
2405
2369
  basename
@@ -2407,41 +2371,45 @@ async function generateResourceResponse(request, routes, basename, routeId, requ
2407
2371
  let response = await staticHandler.queryRoute(request, {
2408
2372
  routeId,
2409
2373
  requestContext,
2410
- unstable_respond: (ctx) => ctx
2411
- });
2412
- if (isResponse(response)) {
2413
- result = response;
2414
- } else {
2415
- if (typeof response === "string") {
2416
- result = new Response(response);
2417
- } else {
2418
- result = Response.json(response);
2374
+ async unstable_generateMiddlewareResponse(queryRoute) {
2375
+ try {
2376
+ let response2 = await queryRoute(request);
2377
+ return generateResourceResponse2(response2);
2378
+ } catch (error) {
2379
+ return generateErrorResponse(error);
2380
+ }
2419
2381
  }
2420
- }
2382
+ });
2383
+ return response;
2421
2384
  } catch (error) {
2385
+ return generateErrorResponse(error);
2386
+ }
2387
+ function generateErrorResponse(error) {
2388
+ let response;
2422
2389
  if (isResponse(error)) {
2423
- result = error;
2390
+ response = error;
2424
2391
  } else if (isRouteErrorResponse(error)) {
2425
2392
  onError?.(error);
2426
2393
  const errorMessage = typeof error.data === "string" ? error.data : error.statusText;
2427
- result = new Response(errorMessage, {
2394
+ response = new Response(errorMessage, {
2428
2395
  status: error.status,
2429
2396
  statusText: error.statusText
2430
2397
  });
2431
2398
  } else {
2432
2399
  onError?.(error);
2433
- result = new Response("Internal Server Error", {
2434
- status: 500
2435
- });
2400
+ response = new Response("Internal Server Error", { status: 500 });
2436
2401
  }
2402
+ return generateResourceResponse2(response);
2403
+ }
2404
+ function generateResourceResponse2(response) {
2405
+ const headers = new Headers(response.headers);
2406
+ headers.set("React-Router-Resource", "true");
2407
+ return new Response(response.body, {
2408
+ status: response.status,
2409
+ statusText: response.statusText,
2410
+ headers
2411
+ });
2437
2412
  }
2438
- const headers = new Headers(result.headers);
2439
- headers.set("React-Router-Resource", "true");
2440
- return new Response(result.body, {
2441
- status: result.status,
2442
- statusText: result.statusText,
2443
- headers
2444
- });
2445
2413
  }
2446
2414
  async function generateRenderResponse(request, routes, basename, isDataRequest, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, generateResponse, temporaryReferences) {
2447
2415
  let statusCode = 200;
@@ -2463,7 +2431,7 @@ async function generateRenderResponse(request, routes, basename, isDataRequest,
2463
2431
  skipLoaderErrorBubbling: isDataRequest,
2464
2432
  skipRevalidation: isSubmission,
2465
2433
  ...routeIdsToLoad ? { filterMatchesToLoad: (m) => routeIdsToLoad.includes(m.route.id) } : null,
2466
- async unstable_stream(_, query) {
2434
+ async unstable_generateMiddlewareResponse(query) {
2467
2435
  let formState;
2468
2436
  if (request.method === "POST") {
2469
2437
  let result2 = await processServerAction(