react-router 0.0.0-experimental-a65d6f5 → 0.0.0-experimental-e0b6ce9

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-CWSJ6RYI.mjs → chunk-4FI4BC6Y.mjs} +2 -2
  2. package/dist/development/{chunk-47MIYFLC.mjs → chunk-F6CT5MEB.mjs} +173 -169
  3. package/dist/development/{chunk-QOFB7XZ5.js → chunk-INO4IHBF.js} +172 -168
  4. package/dist/{production/chunk-4SPSFXAZ.js → development/chunk-ITZFCV4J.js} +134 -134
  5. package/dist/development/dom-export.d.mts +1 -1
  6. package/dist/development/dom-export.d.ts +1 -1
  7. package/dist/development/dom-export.js +3 -3
  8. package/dist/development/dom-export.mjs +3 -3
  9. package/dist/{production/index-react-server-client-lf74v6ET.d.mts → development/index-react-server-client-CYIi6gi0.d.mts} +2 -2
  10. package/dist/development/{index-react-server-client-Iw2PMej2.d.ts → index-react-server-client-ChBGplLn.d.ts} +2 -2
  11. package/dist/development/index-react-server-client.d.mts +3 -3
  12. package/dist/development/index-react-server-client.d.ts +3 -3
  13. package/dist/development/index-react-server-client.js +4 -4
  14. package/dist/development/index-react-server-client.mjs +2 -2
  15. package/dist/development/index-react-server.d.mts +23 -39
  16. package/dist/development/index-react-server.d.ts +23 -39
  17. package/dist/development/index-react-server.js +101 -95
  18. package/dist/development/index-react-server.mjs +101 -95
  19. package/dist/development/index.d.mts +6 -6
  20. package/dist/development/index.d.ts +6 -6
  21. package/dist/development/index.js +98 -98
  22. package/dist/development/index.mjs +3 -3
  23. package/dist/development/{instrumentation-BWRz1MRU.d.ts → instrumentation-BGrNA7uj.d.ts} +23 -39
  24. package/dist/development/lib/types/internal.d.mts +2 -2
  25. package/dist/development/lib/types/internal.d.ts +2 -2
  26. package/dist/development/lib/types/internal.js +1 -1
  27. package/dist/development/lib/types/internal.mjs +1 -1
  28. package/dist/development/{routeModules--SgCTStn.d.mts → routeModules-Cy4Xsfoi.d.mts} +1 -1
  29. package/dist/{production/routeModules-rxNxBmdR.d.ts → development/routeModules-DqotkItD.d.ts} +1 -1
  30. package/dist/development/{router-DQIRhYoj.d.mts → router-DWv6Clt-.d.mts} +23 -39
  31. package/dist/production/{chunk-UAAA7FTX.mjs → chunk-52MYED7O.mjs} +2 -2
  32. package/dist/{development/chunk-ZLVXSGFL.js → production/chunk-DASXXYNZ.js} +134 -134
  33. package/dist/production/{chunk-ZOHTOBOT.js → chunk-K7VXYOZD.js} +172 -168
  34. package/dist/production/{chunk-MMAHTIVZ.mjs → chunk-LKSLGWXX.mjs} +173 -169
  35. package/dist/production/dom-export.d.mts +1 -1
  36. package/dist/production/dom-export.d.ts +1 -1
  37. package/dist/production/dom-export.js +3 -3
  38. package/dist/production/dom-export.mjs +3 -3
  39. package/dist/{development/index-react-server-client-lf74v6ET.d.mts → production/index-react-server-client-CYIi6gi0.d.mts} +2 -2
  40. package/dist/production/{index-react-server-client-Iw2PMej2.d.ts → index-react-server-client-ChBGplLn.d.ts} +2 -2
  41. package/dist/production/index-react-server-client.d.mts +3 -3
  42. package/dist/production/index-react-server-client.d.ts +3 -3
  43. package/dist/production/index-react-server-client.js +4 -4
  44. package/dist/production/index-react-server-client.mjs +2 -2
  45. package/dist/production/index-react-server.d.mts +23 -39
  46. package/dist/production/index-react-server.d.ts +23 -39
  47. package/dist/production/index-react-server.js +101 -95
  48. package/dist/production/index-react-server.mjs +101 -95
  49. package/dist/production/index.d.mts +6 -6
  50. package/dist/production/index.d.ts +6 -6
  51. package/dist/production/index.js +98 -98
  52. package/dist/production/index.mjs +3 -3
  53. package/dist/production/{instrumentation-BWRz1MRU.d.ts → instrumentation-BGrNA7uj.d.ts} +23 -39
  54. package/dist/production/lib/types/internal.d.mts +2 -2
  55. package/dist/production/lib/types/internal.d.ts +2 -2
  56. package/dist/production/lib/types/internal.js +1 -1
  57. package/dist/production/lib/types/internal.mjs +1 -1
  58. package/dist/production/{routeModules--SgCTStn.d.mts → routeModules-Cy4Xsfoi.d.mts} +1 -1
  59. package/dist/{development/routeModules-rxNxBmdR.d.ts → production/routeModules-DqotkItD.d.ts} +1 -1
  60. package/dist/production/{router-DQIRhYoj.d.mts → router-DWv6Clt-.d.mts} +23 -39
  61. package/package.json +1 -1
@@ -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 v0.0.0-experimental-a65d6f5
2
+ * react-router v0.0.0-experimental-e0b6ce9
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -956,182 +956,130 @@ function getRoutePattern(paths) {
956
956
 
957
957
  // lib/router/instrumentation.ts
958
958
  var UninstrumentedSymbol = Symbol("Uninstrumented");
959
- function getInstrumentedImplementation(impls, handler, getInfo = () => void 0) {
960
- if (impls.length === 0) {
961
- return null;
962
- }
963
- return async (...args) => {
964
- let value;
965
- let info = getInfo(...args);
966
- await recurseRight(
967
- impls,
968
- info,
969
- async () => {
970
- value = await handler(...args);
971
- },
972
- impls.length - 1
973
- );
974
- return value;
959
+ function getRouteInstrumentationUpdates(fns, route) {
960
+ let aggregated = {
961
+ lazy: [],
962
+ "lazy.loader": [],
963
+ "lazy.action": [],
964
+ "lazy.middleware": [],
965
+ middleware: [],
966
+ loader: [],
967
+ action: []
975
968
  };
976
- }
977
- async function recurseRight(impls, info, handler, index) {
978
- let impl = impls[index];
979
- if (!impl) {
980
- await handler();
981
- } else {
982
- await impl(async () => {
983
- await recurseRight(impls, info, handler, index - 1);
984
- }, info);
985
- }
986
- }
987
- function getInstrumentationInfo(args) {
988
- let { request, context, params, unstable_pattern } = args;
989
- return {
990
- // pseudo "Request" with the info they may want to read from
991
- request: {
992
- method: request.method,
993
- url: request.url,
994
- // Maybe make this a proxy that only supports `get`?
995
- headers: {
996
- get: (...args2) => request.headers.get(...args2)
997
- }
998
- },
999
- params: { ...params },
1000
- unstable_pattern,
1001
- context: {
1002
- get: (...args2) => context.get(...args2)
1003
- }
1004
- };
1005
- }
1006
- function getInstrumentationsByType(instrumentations, key) {
1007
- let value = [];
1008
- for (let i in instrumentations) {
1009
- let instrumentation = instrumentations[i];
1010
- if (key in instrumentation && instrumentation[key] != null) {
1011
- value.push(instrumentation[key]);
1012
- }
1013
- }
1014
- return value;
1015
- }
1016
- function getInstrumentationUpdates(fns, route) {
1017
- let instrumentations = [];
1018
969
  fns.forEach(
1019
970
  (fn) => fn({
1020
971
  id: route.id,
1021
972
  index: route.index,
1022
973
  path: route.path,
1023
974
  instrument(i) {
1024
- instrumentations.push(i);
975
+ let keys = Object.keys(aggregated);
976
+ for (let key of keys) {
977
+ if (i[key]) {
978
+ aggregated[key].push(i[key]);
979
+ }
980
+ }
1025
981
  }
1026
982
  })
1027
983
  );
1028
984
  let updates = {};
1029
- if (instrumentations.length > 0) {
1030
- ["lazy", "loader", "action"].forEach((key) => {
1031
- let func = route[key];
1032
- if (typeof func === "function") {
1033
- let original = _nullishCoalesce(func[UninstrumentedSymbol], () => ( func));
1034
- let instrumented = getInstrumentedImplementation(
1035
- getInstrumentationsByType(instrumentations, key),
1036
- original,
1037
- key === "lazy" ? () => void 0 : (...args) => getInstrumentationInfo(
1038
- args[0]
1039
- )
1040
- );
985
+ if (typeof route.lazy === "function" && aggregated.lazy.length > 0) {
986
+ let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => void 0);
987
+ if (instrumented) {
988
+ updates.lazy = instrumented;
989
+ }
990
+ }
991
+ if (typeof route.lazy === "object") {
992
+ let lazyObject = route.lazy;
993
+ ["middleware", "loader", "action"].forEach((key) => {
994
+ let lazyFn = lazyObject[key];
995
+ let instrumentations = aggregated[`lazy.${key}`];
996
+ if (typeof lazyFn === "function" && instrumentations.length > 0) {
997
+ let instrumented = wrapImpl(instrumentations, lazyFn, () => void 0);
1041
998
  if (instrumented) {
1042
- instrumented[UninstrumentedSymbol] = original;
1043
- updates[key] = instrumented;
999
+ updates.lazy = Object.assign(updates.lazy || {}, {
1000
+ [key]: instrumented
1001
+ });
1044
1002
  }
1045
1003
  }
1046
1004
  });
1047
- if (route.middleware && route.middleware.length > 0) {
1048
- updates.middleware = route.middleware.map((middleware) => {
1049
- let original = _nullishCoalesce(middleware[UninstrumentedSymbol], () => ( middleware));
1050
- let instrumented = getInstrumentedImplementation(
1051
- getInstrumentationsByType(instrumentations, "middleware"),
1052
- original,
1053
- (...args) => getInstrumentationInfo(
1054
- args[0]
1055
- )
1056
- );
1057
- if (instrumented) {
1058
- instrumented[UninstrumentedSymbol] = original;
1059
- return instrumented;
1060
- }
1061
- return middleware;
1062
- });
1063
- }
1064
- if (typeof route.lazy === "object") {
1065
- let lazyObject = route.lazy;
1066
- ["middleware", "loader", "action"].forEach((key) => {
1067
- let func = lazyObject[key];
1068
- if (typeof func === "function") {
1069
- let instrumented = getInstrumentedImplementation(
1070
- getInstrumentationsByType(instrumentations, `lazy.${key}`),
1071
- func
1072
- );
1073
- if (instrumented) {
1074
- updates.lazy = Object.assign(updates.lazy || {}, {
1075
- [key]: instrumented
1076
- });
1077
- }
1078
- }
1079
- });
1005
+ }
1006
+ ["loader", "action"].forEach((key) => {
1007
+ let handler = route[key];
1008
+ if (typeof handler === "function" && aggregated[key].length > 0) {
1009
+ let original = _nullishCoalesce(handler[UninstrumentedSymbol], () => ( handler));
1010
+ let instrumented = wrapImpl(
1011
+ aggregated[key],
1012
+ original,
1013
+ (...args) => getHandlerInfo(args[0])
1014
+ );
1015
+ if (instrumented) {
1016
+ instrumented[UninstrumentedSymbol] = original;
1017
+ updates[key] = instrumented;
1018
+ }
1080
1019
  }
1020
+ });
1021
+ if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) {
1022
+ updates.middleware = route.middleware.map((middleware) => {
1023
+ let original = _nullishCoalesce(middleware[UninstrumentedSymbol], () => ( middleware));
1024
+ let instrumented = wrapImpl(
1025
+ aggregated.middleware,
1026
+ original,
1027
+ (...args) => getHandlerInfo(args[0])
1028
+ );
1029
+ if (instrumented) {
1030
+ instrumented[UninstrumentedSymbol] = original;
1031
+ return instrumented;
1032
+ }
1033
+ return middleware;
1034
+ });
1081
1035
  }
1082
1036
  return updates;
1083
1037
  }
1084
1038
  function instrumentClientSideRouter(router, fns) {
1085
- let instrumentations = [];
1039
+ let aggregated = {
1040
+ navigate: [],
1041
+ fetch: []
1042
+ };
1086
1043
  fns.forEach(
1087
1044
  (fn) => fn({
1088
1045
  instrument(i) {
1089
- instrumentations.push(i);
1046
+ let keys = Object.keys(i);
1047
+ for (let key of keys) {
1048
+ if (i[key]) {
1049
+ aggregated[key].push(i[key]);
1050
+ }
1051
+ }
1090
1052
  }
1091
1053
  })
1092
1054
  );
1093
- if (instrumentations.length > 0) {
1055
+ if (aggregated.navigate.length > 0) {
1094
1056
  let navigate = _nullishCoalesce(router.navigate[UninstrumentedSymbol], () => ( router.navigate));
1095
- let instrumentedNavigate = getInstrumentedImplementation(
1096
- getInstrumentationsByType(instrumentations, "navigate"),
1057
+ let instrumentedNavigate = wrapImpl(
1058
+ aggregated.navigate,
1097
1059
  navigate,
1098
1060
  (...args) => {
1099
1061
  let [to, opts] = args;
1100
- opts = _nullishCoalesce(opts, () => ( {}));
1101
- let info = {
1062
+ return {
1102
1063
  to: typeof to === "number" || typeof to === "string" ? to : to ? createPath(to) : ".",
1103
- currentUrl: createPath(router.state.location),
1104
- ..."formMethod" in opts ? { formMethod: opts.formMethod } : {},
1105
- ..."formEncType" in opts ? { formEncType: opts.formEncType } : {},
1106
- ..."formData" in opts ? { formData: opts.formData } : {},
1107
- ..."body" in opts ? { body: opts.body } : {}
1064
+ ...getRouterInfo(router, _nullishCoalesce(opts, () => ( {})))
1108
1065
  };
1109
- return info;
1110
1066
  }
1111
1067
  );
1112
1068
  if (instrumentedNavigate) {
1113
1069
  instrumentedNavigate[UninstrumentedSymbol] = navigate;
1114
1070
  router.navigate = instrumentedNavigate;
1115
1071
  }
1072
+ }
1073
+ if (aggregated.fetch.length > 0) {
1116
1074
  let fetch2 = _nullishCoalesce(router.fetch[UninstrumentedSymbol], () => ( router.fetch));
1117
- let instrumentedFetch = getInstrumentedImplementation(
1118
- getInstrumentationsByType(instrumentations, "fetch"),
1119
- fetch2,
1120
- (...args) => {
1121
- let [key, , href, opts] = args;
1122
- opts = _nullishCoalesce(opts, () => ( {}));
1123
- let info = {
1124
- href: _nullishCoalesce(href, () => ( ".")),
1125
- currentUrl: createPath(router.state.location),
1126
- fetcherKey: key,
1127
- ..."formMethod" in opts ? { formMethod: opts.formMethod } : {},
1128
- ..."formEncType" in opts ? { formEncType: opts.formEncType } : {},
1129
- ..."formData" in opts ? { formData: opts.formData } : {},
1130
- ..."body" in opts ? { body: opts.body } : {}
1131
- };
1132
- return info;
1133
- }
1134
- );
1075
+ let instrumentedFetch = wrapImpl(aggregated.fetch, fetch2, (...args) => {
1076
+ let [key, , href, opts] = args;
1077
+ return {
1078
+ href: _nullishCoalesce(href, () => ( ".")),
1079
+ fetcherKey: key,
1080
+ ...getRouterInfo(router, _nullishCoalesce(opts, () => ( {})))
1081
+ };
1082
+ });
1135
1083
  if (instrumentedFetch) {
1136
1084
  instrumentedFetch[UninstrumentedSymbol] = fetch2;
1137
1085
  router.fetch = instrumentedFetch;
@@ -1140,38 +1088,94 @@ function instrumentClientSideRouter(router, fns) {
1140
1088
  return router;
1141
1089
  }
1142
1090
  function instrumentHandler(handler, fns) {
1143
- let instrumentations = [];
1091
+ let aggregated = {
1092
+ request: []
1093
+ };
1144
1094
  fns.forEach(
1145
1095
  (fn) => fn({
1146
1096
  instrument(i) {
1147
- instrumentations.push(i);
1097
+ let keys = Object.keys(i);
1098
+ for (let key of keys) {
1099
+ if (i[key]) {
1100
+ aggregated[key].push(i[key]);
1101
+ }
1102
+ }
1148
1103
  }
1149
1104
  })
1150
1105
  );
1151
- if (instrumentations.length === 0) {
1152
- return handler;
1153
- }
1154
- let instrumentedHandler = getInstrumentedImplementation(
1155
- getInstrumentationsByType(instrumentations, "request"),
1156
- handler,
1157
- (...args) => {
1106
+ let instrumentedHandler = handler;
1107
+ if (aggregated.request.length > 0) {
1108
+ instrumentedHandler = wrapImpl(aggregated.request, handler, (...args) => {
1158
1109
  let [request, context] = args;
1159
- let info = {
1160
- request: {
1161
- method: request.method,
1162
- url: request.url,
1163
- headers: {
1164
- get: (...args2) => request.headers.get(...args2)
1165
- }
1166
- },
1167
- context: {
1168
- get: (ctx) => context ? context.get(ctx) : void 0
1169
- }
1110
+ return {
1111
+ request: getReadonlyRequest(request),
1112
+ // TODO: Handle non-middleware flows
1113
+ // @ts-expect-error
1114
+ context: getReadonlyContext(context)
1170
1115
  };
1171
- return info;
1116
+ });
1117
+ }
1118
+ return instrumentedHandler;
1119
+ }
1120
+ function wrapImpl(impls, handler, getInfo) {
1121
+ if (impls.length === 0) {
1122
+ return null;
1123
+ }
1124
+ return async (...args) => {
1125
+ let value;
1126
+ let info = getInfo(...args);
1127
+ await recurseRight(
1128
+ impls,
1129
+ info,
1130
+ async () => {
1131
+ value = await handler(...args);
1132
+ },
1133
+ impls.length - 1
1134
+ );
1135
+ return value;
1136
+ };
1137
+ }
1138
+ async function recurseRight(impls, info, handler, index) {
1139
+ let impl = impls[index];
1140
+ if (!impl) {
1141
+ await handler();
1142
+ } else {
1143
+ await impl(async () => {
1144
+ await recurseRight(impls, info, handler, index - 1);
1145
+ }, info);
1146
+ }
1147
+ }
1148
+ function getHandlerInfo(args) {
1149
+ let { request, context, params, unstable_pattern } = args;
1150
+ return {
1151
+ request: getReadonlyRequest(request),
1152
+ params: { ...params },
1153
+ unstable_pattern,
1154
+ context: getReadonlyContext(context)
1155
+ };
1156
+ }
1157
+ function getRouterInfo(router, opts) {
1158
+ return {
1159
+ currentUrl: createPath(router.state.location),
1160
+ ..."formMethod" in opts ? { formMethod: opts.formMethod } : {},
1161
+ ..."formEncType" in opts ? { formEncType: opts.formEncType } : {},
1162
+ ..."formData" in opts ? { formData: opts.formData } : {},
1163
+ ..."body" in opts ? { body: opts.body } : {}
1164
+ };
1165
+ }
1166
+ function getReadonlyRequest(request) {
1167
+ return {
1168
+ method: request.method,
1169
+ url: request.url,
1170
+ headers: {
1171
+ get: (...args) => request.headers.get(...args)
1172
1172
  }
1173
- );
1174
- return _nullishCoalesce(instrumentedHandler, () => ( handler));
1173
+ };
1174
+ }
1175
+ function getReadonlyContext(context) {
1176
+ return {
1177
+ get: (ctx) => context.get(ctx)
1178
+ };
1175
1179
  }
1176
1180
 
1177
1181
  // lib/router/router.ts
@@ -1239,7 +1243,7 @@ function createRouter(init) {
1239
1243
  mapRouteProperties = (route) => {
1240
1244
  return {
1241
1245
  ..._mapRouteProperties(route),
1242
- ...getInstrumentationUpdates(
1246
+ ...getRouteInstrumentationUpdates(
1243
1247
  instrumentations.map((i) => i.route).filter(Boolean),
1244
1248
  route
1245
1249
  )
@@ -3019,7 +3023,7 @@ function createStaticHandler(routes, opts) {
3019
3023
  mapRouteProperties = (route) => {
3020
3024
  return {
3021
3025
  ..._mapRouteProperties(route),
3022
- ...getInstrumentationUpdates(
3026
+ ...getRouteInstrumentationUpdates(
3023
3027
  instrumentations.map((i) => i.route).filter(Boolean),
3024
3028
  route
3025
3029
  )
@@ -3517,13 +3521,14 @@ function createStaticHandler(routes, opts) {
3517
3521
  // Up to but not including the boundary
3518
3522
  matches.findIndex((m) => m.route.id === pendingActionResult[0]) - 1
3519
3523
  ) : void 0;
3524
+ let pattern = getRoutePattern(matches.map((m) => m.route.path));
3520
3525
  dsMatches = matches.map((match, index) => {
3521
3526
  if (maxIdx != null && index > maxIdx) {
3522
3527
  return getDataStrategyMatch(
3523
3528
  mapRouteProperties,
3524
3529
  manifest,
3525
3530
  request,
3526
- getRoutePattern(matches.map((m) => m.route.path)),
3531
+ pattern,
3527
3532
  match,
3528
3533
  [],
3529
3534
  requestContext,
@@ -3534,7 +3539,7 @@ function createStaticHandler(routes, opts) {
3534
3539
  mapRouteProperties,
3535
3540
  manifest,
3536
3541
  request,
3537
- getRoutePattern(matches.map((m) => m.route.path)),
3542
+ pattern,
3538
3543
  match,
3539
3544
  [],
3540
3545
  requestContext,
@@ -3816,7 +3821,6 @@ function getMatchesToLoad(request, scopedContext, mapRouteProperties, manifest,
3816
3821
  actionStatus
3817
3822
  };
3818
3823
  let pattern = getRoutePattern(matches.map((m) => m.route.path));
3819
- console.log(pattern, matches);
3820
3824
  let dsMatches = matches.map((match, index) => {
3821
3825
  let { route } = match;
3822
3826
  let forceShouldLoad = null;
@@ -4315,7 +4319,7 @@ function runClientMiddlewarePipeline(args, handler) {
4315
4319
  }
4316
4320
  }
4317
4321
  async function runMiddlewarePipeline(args, handler, processResult, isResult, errorHandler) {
4318
- let { matches, request, params, context } = args;
4322
+ let { matches, request, params, context, unstable_pattern } = args;
4319
4323
  let tuples = matches.flatMap(
4320
4324
  (m) => m.route.middleware ? m.route.middleware.map((fn) => [m.route.id, fn]) : []
4321
4325
  );
@@ -4324,7 +4328,7 @@ async function runMiddlewarePipeline(args, handler, processResult, isResult, err
4324
4328
  request,
4325
4329
  params,
4326
4330
  context,
4327
- unstable_pattern: getRoutePattern(matches.map((m) => m.route.path))
4331
+ unstable_pattern
4328
4332
  },
4329
4333
  tuples,
4330
4334
  handler,