react-router 0.0.0-experimental-e988dc602 → 0.0.0-experimental-00e730ed0

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 (50) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/dist/development/{chunk-EUVE7DCV.mjs → chunk-W26YWAGH.mjs} +1214 -1181
  3. package/dist/development/dom-export.d.mts +2 -2
  4. package/dist/development/dom-export.d.ts +1 -2
  5. package/dist/development/dom-export.js +34 -6135
  6. package/dist/development/dom-export.mjs +6 -3
  7. package/dist/development/index.d.mts +47 -93
  8. package/dist/development/index.d.ts +1904 -221
  9. package/dist/development/index.js +1214 -1190
  10. package/dist/development/index.mjs +2 -19
  11. package/dist/{production/lib/types/route-module.d.mts → development/lib/types/internal.d.mts} +88 -23
  12. package/dist/development/lib/types/{route-module.d.mts → internal.d.ts} +87 -23
  13. package/dist/development/lib/types/{route-module.js → internal.js} +4 -4
  14. package/dist/development/lib/types/{route-module.mjs → internal.mjs} +1 -1
  15. package/dist/development/{fog-of-war-DrUCUQQ-.d.ts → lib-DRnPBLeb.d.mts} +136 -178
  16. package/dist/development/{route-data-BIYebJr3.d.ts → register-BPC2Sp5k.d.ts} +30 -12
  17. package/dist/development/register-e9PGCFx1.d.mts +10 -0
  18. package/dist/{production/route-data-BIYebJr3.d.mts → development/route-data-Wlht-qYx.d.mts} +21 -12
  19. package/dist/production/{chunk-OIBET7ZQ.mjs → chunk-2WAHFPTY.mjs} +1214 -1181
  20. package/dist/production/dom-export.d.mts +2 -2
  21. package/dist/production/dom-export.d.ts +1 -2
  22. package/dist/production/dom-export.js +34 -6135
  23. package/dist/production/dom-export.mjs +6 -3
  24. package/dist/production/index.d.mts +47 -93
  25. package/dist/production/index.d.ts +1904 -221
  26. package/dist/production/index.js +1214 -1190
  27. package/dist/production/index.mjs +2 -19
  28. package/dist/production/lib/types/{route-module.d.ts → internal.d.mts} +88 -23
  29. package/dist/{development/lib/types/route-module.d.ts → production/lib/types/internal.d.ts} +87 -23
  30. package/dist/production/lib/types/{route-module.js → internal.js} +4 -4
  31. package/dist/production/lib/types/{route-module.mjs → internal.mjs} +1 -1
  32. package/dist/production/{fog-of-war-DrUCUQQ-.d.ts → lib-DRnPBLeb.d.mts} +136 -178
  33. package/dist/production/{route-data-BIYebJr3.d.ts → register-BPC2Sp5k.d.ts} +30 -12
  34. package/dist/production/register-e9PGCFx1.d.mts +10 -0
  35. package/dist/{development/route-data-BIYebJr3.d.mts → production/route-data-Wlht-qYx.d.mts} +21 -12
  36. package/package.json +9 -38
  37. package/dist/development/data-CQbyyGzl.d.mts +0 -11
  38. package/dist/development/data-CQbyyGzl.d.ts +0 -11
  39. package/dist/development/fog-of-war-C5L_Yd5M.d.mts +0 -1778
  40. package/dist/development/rsc-export.d.mts +0 -1788
  41. package/dist/development/rsc-export.d.ts +0 -1788
  42. package/dist/development/rsc-export.js +0 -2784
  43. package/dist/development/rsc-export.mjs +0 -2749
  44. package/dist/production/data-CQbyyGzl.d.mts +0 -11
  45. package/dist/production/data-CQbyyGzl.d.ts +0 -11
  46. package/dist/production/fog-of-war-C5L_Yd5M.d.mts +0 -1778
  47. package/dist/production/rsc-export.d.mts +0 -1788
  48. package/dist/production/rsc-export.d.ts +0 -1788
  49. package/dist/production/rsc-export.js +0 -2784
  50. package/dist/production/rsc-export.mjs +0 -2749
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-e988dc602
2
+ * react-router v0.0.0-experimental-00e730ed0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -45,19 +45,19 @@ function createMemoryHistory(options = {}) {
45
45
  return entries[index];
46
46
  }
47
47
  function createMemoryLocation(to, state = null, key) {
48
- let location2 = createLocation(
48
+ let location = createLocation(
49
49
  entries ? getCurrentLocation().pathname : "/",
50
50
  to,
51
51
  state,
52
52
  key
53
53
  );
54
54
  warning(
55
- location2.pathname.charAt(0) === "/",
55
+ location.pathname.charAt(0) === "/",
56
56
  `relative pathnames are not supported in memory history: ${JSON.stringify(
57
57
  to
58
58
  )}`
59
59
  );
60
- return location2;
60
+ return location;
61
61
  }
62
62
  function createHref2(to) {
63
63
  return typeof to === "string" ? to : createPath(to);
@@ -168,9 +168,9 @@ function createHashHistory(options = {}) {
168
168
  }
169
169
  return href2 + "#" + (typeof to === "string" ? to : createPath(to));
170
170
  }
171
- function validateHashLocation(location2, to) {
171
+ function validateHashLocation(location, to) {
172
172
  warning(
173
- location2.pathname.charAt(0) === "/",
173
+ location.pathname.charAt(0) === "/",
174
174
  `relative pathnames are not supported in hash history.push(${JSON.stringify(
175
175
  to
176
176
  )})`
@@ -200,15 +200,15 @@ function warning(cond, message) {
200
200
  function createKey() {
201
201
  return Math.random().toString(36).substring(2, 10);
202
202
  }
203
- function getHistoryState(location2, index) {
203
+ function getHistoryState(location, index) {
204
204
  return {
205
- usr: location2.state,
206
- key: location2.key,
205
+ usr: location.state,
206
+ key: location.key,
207
207
  idx: index
208
208
  };
209
209
  }
210
210
  function createLocation(current, to, state = null, key) {
211
- let location2 = {
211
+ let location = {
212
212
  pathname: typeof current === "string" ? current : current.pathname,
213
213
  search: "",
214
214
  hash: "",
@@ -220,7 +220,7 @@ function createLocation(current, to, state = null, key) {
220
220
  // keep as is for the time being and just let any incoming keys take precedence
221
221
  key: to && to.key || key || createKey()
222
222
  };
223
- return location2;
223
+ return location;
224
224
  }
225
225
  function createPath({
226
226
  pathname = "/",
@@ -277,11 +277,11 @@ function getUrlBasedHistory(getLocation, createHref2, validateLocation, options
277
277
  }
278
278
  function push(to, state) {
279
279
  action = "PUSH" /* Push */;
280
- let location2 = createLocation(history.location, to, state);
281
- if (validateLocation) validateLocation(location2, to);
280
+ let location = createLocation(history.location, to, state);
281
+ if (validateLocation) validateLocation(location, to);
282
282
  index = getIndex() + 1;
283
- let historyState = getHistoryState(location2, index);
284
- let url = history.createHref(location2);
283
+ let historyState = getHistoryState(location, index);
284
+ let url = history.createHref(location);
285
285
  try {
286
286
  globalHistory.pushState(historyState, "", url);
287
287
  } catch (error) {
@@ -296,25 +296,18 @@ function getUrlBasedHistory(getLocation, createHref2, validateLocation, options
296
296
  }
297
297
  function replace2(to, state) {
298
298
  action = "REPLACE" /* Replace */;
299
- let location2 = createLocation(history.location, to, state);
300
- if (validateLocation) validateLocation(location2, to);
299
+ let location = createLocation(history.location, to, state);
300
+ if (validateLocation) validateLocation(location, to);
301
301
  index = getIndex();
302
- let historyState = getHistoryState(location2, index);
303
- let url = history.createHref(location2);
302
+ let historyState = getHistoryState(location, index);
303
+ let url = history.createHref(location);
304
304
  globalHistory.replaceState(historyState, "", url);
305
305
  if (v5Compat && listener) {
306
306
  listener({ action, location: history.location, delta: 0 });
307
307
  }
308
308
  }
309
309
  function createURL(to) {
310
- let base = window2.location.origin !== "null" ? window2.location.origin : window2.location.href;
311
- let href2 = typeof to === "string" ? to : createPath(to);
312
- href2 = href2.replace(/ $/, "%20");
313
- invariant(
314
- base,
315
- `No window.location.(origin|href) available to create URL for href: ${href2}`
316
- );
317
- return new URL(href2, base);
310
+ return createBrowserURLImpl(to);
318
311
  }
319
312
  let history = {
320
313
  get action() {
@@ -354,6 +347,19 @@ function getUrlBasedHistory(getLocation, createHref2, validateLocation, options
354
347
  };
355
348
  return history;
356
349
  }
350
+ function createBrowserURLImpl(to, isAbsolute = false) {
351
+ let base = "http://localhost";
352
+ if (typeof window !== "undefined") {
353
+ base = window.location.origin !== "null" ? window.location.origin : window.location.href;
354
+ }
355
+ invariant(base, "No window.location.(origin|href) available to create URL");
356
+ let href2 = typeof to === "string" ? to : createPath(to);
357
+ href2 = href2.replace(/ $/, "%20");
358
+ if (!isAbsolute && href2.startsWith("//")) {
359
+ href2 = base + href2;
360
+ }
361
+ return new URL(href2, base);
362
+ }
357
363
 
358
364
  // lib/router/utils.ts
359
365
  function unstable_createContext(defaultValue) {
@@ -413,7 +419,7 @@ function isUnsupportedLazyRouteFunctionKey(key) {
413
419
  function isIndexRoute(route) {
414
420
  return route.index === true;
415
421
  }
416
- function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [], manifest = {}, allowInPlaceMutations = false) {
422
+ function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [], manifest = {}) {
417
423
  return routes.map((route, index) => {
418
424
  let treePath = [...parentPath, String(index)];
419
425
  let id = typeof route.id === "string" ? route.id : treePath.join("-");
@@ -422,7 +428,7 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [],
422
428
  `Cannot specify children on an index route`
423
429
  );
424
430
  invariant(
425
- allowInPlaceMutations || !manifest[id],
431
+ !manifest[id],
426
432
  `Found a route id collision on id "${id}". Route id's must be globally unique within Data Router usages`
427
433
  );
428
434
  if (isIndexRoute(route)) {
@@ -446,8 +452,7 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [],
446
452
  route.children,
447
453
  mapRouteProperties2,
448
454
  treePath,
449
- manifest,
450
- allowInPlaceMutations
455
+ manifest
451
456
  );
452
457
  }
453
458
  return pathOrLayoutRoute;
@@ -458,8 +463,8 @@ function matchRoutes(routes, locationArg, basename = "/") {
458
463
  return matchRoutesImpl(routes, locationArg, basename, false);
459
464
  }
460
465
  function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
461
- let location2 = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
462
- let pathname = stripBasename(location2.pathname || "/", basename);
466
+ let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
467
+ let pathname = stripBasename(location.pathname || "/", basename);
463
468
  if (pathname == null) {
464
469
  return null;
465
470
  }
@@ -651,19 +656,19 @@ function generatePath(originalPath, params = {}) {
651
656
  path = path.replace(/\*$/, "/*");
652
657
  }
653
658
  const prefix = path.startsWith("/") ? "/" : "";
654
- const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
659
+ const stringify2 = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
655
660
  const segments = path.split(/\/+/).map((segment, index, array) => {
656
661
  const isLastSegment = index === array.length - 1;
657
662
  if (isLastSegment && segment === "*") {
658
663
  const star = "*";
659
- return stringify(params[star]);
664
+ return stringify2(params[star]);
660
665
  }
661
666
  const keyMatch = segment.match(/^:([\w-]+)(\??)$/);
662
667
  if (keyMatch) {
663
668
  const [, key, optional] = keyMatch;
664
669
  let param = params[key];
665
670
  invariant(optional === "?" || param != null, `Missing ":${key}" param`);
666
- return stringify(param);
671
+ return stringify2(param);
667
672
  }
668
673
  return segment.replace(/\?$/g, "");
669
674
  }).filter((segment) => !!segment);
@@ -975,53 +980,57 @@ function createRouter(init) {
975
980
  let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
976
981
  let initialMatchesIsFOW = false;
977
982
  let initialErrors = null;
983
+ let initialized;
978
984
  if (initialMatches == null && !init.patchRoutesOnNavigation) {
979
985
  let error = getInternalRouterError(404, {
980
986
  pathname: init.history.location.pathname
981
987
  });
982
988
  let { matches, route } = getShortCircuitMatches(dataRoutes);
989
+ initialized = true;
983
990
  initialMatches = matches;
984
991
  initialErrors = { [route.id]: error };
985
- }
986
- if (initialMatches && !init.hydrationData) {
987
- let fogOfWar = checkFogOfWar(
988
- initialMatches,
989
- dataRoutes,
990
- init.history.location.pathname
991
- );
992
- if (fogOfWar.active) {
993
- initialMatches = null;
994
- }
995
- }
996
- let initialized;
997
- if (!initialMatches) {
998
- initialized = false;
999
- initialMatches = [];
1000
- let fogOfWar = checkFogOfWar(
1001
- null,
1002
- dataRoutes,
1003
- init.history.location.pathname
1004
- );
1005
- if (fogOfWar.active && fogOfWar.matches) {
1006
- initialMatchesIsFOW = true;
1007
- initialMatches = fogOfWar.matches;
1008
- }
1009
- } else if (initialMatches.some((m) => m.route.lazy)) {
1010
- initialized = false;
1011
- } else if (!initialMatches.some((m) => m.route.loader)) {
1012
- initialized = true;
1013
992
  } else {
1014
- let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
1015
- let errors = init.hydrationData ? init.hydrationData.errors : null;
1016
- if (errors) {
1017
- let idx = initialMatches.findIndex(
1018
- (m) => errors[m.route.id] !== void 0
993
+ if (initialMatches && !init.hydrationData) {
994
+ let fogOfWar = checkFogOfWar(
995
+ initialMatches,
996
+ dataRoutes,
997
+ init.history.location.pathname
1019
998
  );
1020
- initialized = initialMatches.slice(0, idx + 1).every((m) => !shouldLoadRouteOnHydration(m.route, loaderData, errors));
1021
- } else {
1022
- initialized = initialMatches.every(
1023
- (m) => !shouldLoadRouteOnHydration(m.route, loaderData, errors)
999
+ if (fogOfWar.active) {
1000
+ initialMatches = null;
1001
+ }
1002
+ }
1003
+ if (!initialMatches) {
1004
+ initialized = false;
1005
+ initialMatches = [];
1006
+ let fogOfWar = checkFogOfWar(
1007
+ null,
1008
+ dataRoutes,
1009
+ init.history.location.pathname
1024
1010
  );
1011
+ if (fogOfWar.active && fogOfWar.matches) {
1012
+ initialMatchesIsFOW = true;
1013
+ initialMatches = fogOfWar.matches;
1014
+ }
1015
+ } else if (initialMatches.some((m) => m.route.lazy)) {
1016
+ initialized = false;
1017
+ } else if (!initialMatches.some((m) => m.route.loader)) {
1018
+ initialized = true;
1019
+ } else {
1020
+ let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
1021
+ let errors = init.hydrationData ? init.hydrationData.errors : null;
1022
+ if (errors) {
1023
+ let idx = initialMatches.findIndex(
1024
+ (m) => errors[m.route.id] !== void 0
1025
+ );
1026
+ initialized = initialMatches.slice(0, idx + 1).every(
1027
+ (m) => !shouldLoadRouteOnHydration(m.route, loaderData, errors)
1028
+ );
1029
+ } else {
1030
+ initialized = initialMatches.every(
1031
+ (m) => !shouldLoadRouteOnHydration(m.route, loaderData, errors)
1032
+ );
1033
+ }
1025
1034
  }
1026
1035
  }
1027
1036
  let router;
@@ -1063,7 +1072,7 @@ function createRouter(init) {
1063
1072
  let pendingRevalidationDfd = null;
1064
1073
  function initialize() {
1065
1074
  unlistenHistory = init.history.listen(
1066
- ({ action: historyAction, location: location2, delta }) => {
1075
+ ({ action: historyAction, location, delta }) => {
1067
1076
  if (unblockBlockerHistoryUpdate) {
1068
1077
  unblockBlockerHistoryUpdate();
1069
1078
  unblockBlockerHistoryUpdate = void 0;
@@ -1075,7 +1084,7 @@ function createRouter(init) {
1075
1084
  );
1076
1085
  let blockerKey = shouldBlockNavigation({
1077
1086
  currentLocation: state.location,
1078
- nextLocation: location2,
1087
+ nextLocation: location,
1079
1088
  historyAction
1080
1089
  });
1081
1090
  if (blockerKey && delta != null) {
@@ -1085,13 +1094,13 @@ function createRouter(init) {
1085
1094
  init.history.go(delta * -1);
1086
1095
  updateBlocker(blockerKey, {
1087
1096
  state: "blocked",
1088
- location: location2,
1097
+ location,
1089
1098
  proceed() {
1090
1099
  updateBlocker(blockerKey, {
1091
1100
  state: "proceeding",
1092
1101
  proceed: void 0,
1093
1102
  reset: void 0,
1094
- location: location2
1103
+ location
1095
1104
  });
1096
1105
  nextHistoryUpdatePromise.then(() => init.history.go(delta));
1097
1106
  },
@@ -1103,7 +1112,7 @@ function createRouter(init) {
1103
1112
  });
1104
1113
  return;
1105
1114
  }
1106
- return startNavigation(historyAction, location2);
1115
+ return startNavigation(historyAction, location);
1107
1116
  }
1108
1117
  );
1109
1118
  if (isBrowser2) {
@@ -1136,19 +1145,6 @@ function createRouter(init) {
1136
1145
  return () => subscribers.delete(fn);
1137
1146
  }
1138
1147
  function updateState(newState, opts = {}) {
1139
- if (newState.matches) {
1140
- newState.matches = newState.matches.map((m) => {
1141
- let route = manifest[m.route.id];
1142
- let matchRoute = m.route;
1143
- if (matchRoute.element !== route.element || matchRoute.errorElement !== route.errorElement || matchRoute.hydrateFallbackElement !== route.hydrateFallbackElement) {
1144
- return {
1145
- ...m,
1146
- route
1147
- };
1148
- }
1149
- return m;
1150
- });
1151
- }
1152
1148
  state = {
1153
1149
  ...state,
1154
1150
  ...newState
@@ -1179,8 +1175,8 @@ function createRouter(init) {
1179
1175
  unmountedFetchers.forEach((key) => deleteFetcher(key));
1180
1176
  mountedFetchers.forEach((key) => state.fetchers.delete(key));
1181
1177
  }
1182
- function completeNavigation(location2, newState, { flushSync } = {}) {
1183
- let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && location2.state?._isRedirect !== true;
1178
+ function completeNavigation(location, newState, { flushSync } = {}) {
1179
+ let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && location.state?._isRedirect !== true;
1184
1180
  let actionData;
1185
1181
  if (newState.actionData) {
1186
1182
  if (Object.keys(newState.actionData).length > 0) {
@@ -1204,7 +1200,7 @@ function createRouter(init) {
1204
1200
  blockers = new Map(blockers);
1205
1201
  blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER));
1206
1202
  }
1207
- let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && location2.state?._isRedirect !== true;
1203
+ let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && location.state?._isRedirect !== true;
1208
1204
  if (inFlightDataRoutes) {
1209
1205
  dataRoutes = inFlightDataRoutes;
1210
1206
  inFlightDataRoutes = void 0;
@@ -1212,35 +1208,35 @@ function createRouter(init) {
1212
1208
  if (isUninterruptedRevalidation) {
1213
1209
  } else if (pendingAction === "POP" /* Pop */) {
1214
1210
  } else if (pendingAction === "PUSH" /* Push */) {
1215
- init.history.push(location2, location2.state);
1211
+ init.history.push(location, location.state);
1216
1212
  } else if (pendingAction === "REPLACE" /* Replace */) {
1217
- init.history.replace(location2, location2.state);
1213
+ init.history.replace(location, location.state);
1218
1214
  }
1219
1215
  let viewTransitionOpts;
1220
1216
  if (pendingAction === "POP" /* Pop */) {
1221
1217
  let priorPaths = appliedViewTransitions.get(state.location.pathname);
1222
- if (priorPaths && priorPaths.has(location2.pathname)) {
1218
+ if (priorPaths && priorPaths.has(location.pathname)) {
1223
1219
  viewTransitionOpts = {
1224
1220
  currentLocation: state.location,
1225
- nextLocation: location2
1221
+ nextLocation: location
1226
1222
  };
1227
- } else if (appliedViewTransitions.has(location2.pathname)) {
1223
+ } else if (appliedViewTransitions.has(location.pathname)) {
1228
1224
  viewTransitionOpts = {
1229
- currentLocation: location2,
1225
+ currentLocation: location,
1230
1226
  nextLocation: state.location
1231
1227
  };
1232
1228
  }
1233
1229
  } else if (pendingViewTransitionEnabled) {
1234
1230
  let toPaths = appliedViewTransitions.get(state.location.pathname);
1235
1231
  if (toPaths) {
1236
- toPaths.add(location2.pathname);
1232
+ toPaths.add(location.pathname);
1237
1233
  } else {
1238
- toPaths = /* @__PURE__ */ new Set([location2.pathname]);
1234
+ toPaths = /* @__PURE__ */ new Set([location.pathname]);
1239
1235
  appliedViewTransitions.set(state.location.pathname, toPaths);
1240
1236
  }
1241
1237
  viewTransitionOpts = {
1242
1238
  currentLocation: state.location,
1243
- nextLocation: location2
1239
+ nextLocation: location
1244
1240
  };
1245
1241
  }
1246
1242
  updateState(
@@ -1250,12 +1246,12 @@ function createRouter(init) {
1250
1246
  actionData,
1251
1247
  loaderData,
1252
1248
  historyAction: pendingAction,
1253
- location: location2,
1249
+ location,
1254
1250
  initialized: true,
1255
1251
  navigation: IDLE_NAVIGATION,
1256
1252
  revalidation: "idle",
1257
1253
  restoreScrollPosition: getSavedScrollPosition(
1258
- location2,
1254
+ location,
1259
1255
  newState.matches || state.matches
1260
1256
  ),
1261
1257
  preventScrollReset,
@@ -1372,7 +1368,7 @@ function createRouter(init) {
1372
1368
  );
1373
1369
  return promise;
1374
1370
  }
1375
- async function startNavigation(historyAction, location2, opts) {
1371
+ async function startNavigation(historyAction, location, opts) {
1376
1372
  pendingNavigationController && pendingNavigationController.abort();
1377
1373
  pendingNavigationController = null;
1378
1374
  pendingAction = historyAction;
@@ -1385,22 +1381,22 @@ function createRouter(init) {
1385
1381
  let matches = opts?.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ? (
1386
1382
  // `matchRoutes()` has already been called if we're in here via `router.initialize()`
1387
1383
  state.matches
1388
- ) : matchRoutes(routesToUse, location2, basename);
1384
+ ) : matchRoutes(routesToUse, location, basename);
1389
1385
  let flushSync = (opts && opts.flushSync) === true;
1390
- if (matches && state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location2) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
1391
- completeNavigation(location2, { matches }, { flushSync });
1386
+ if (matches && state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
1387
+ completeNavigation(location, { matches }, { flushSync });
1392
1388
  return;
1393
1389
  }
1394
- let fogOfWar = checkFogOfWar(matches, routesToUse, location2.pathname);
1390
+ let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
1395
1391
  if (fogOfWar.active && fogOfWar.matches) {
1396
1392
  matches = fogOfWar.matches;
1397
1393
  }
1398
1394
  if (!matches) {
1399
1395
  let { error, notFoundMatches, route } = handleNavigational404(
1400
- location2.pathname
1396
+ location.pathname
1401
1397
  );
1402
1398
  completeNavigation(
1403
- location2,
1399
+ location,
1404
1400
  {
1405
1401
  matches: notFoundMatches,
1406
1402
  loaderData: {},
@@ -1415,7 +1411,7 @@ function createRouter(init) {
1415
1411
  pendingNavigationController = new AbortController();
1416
1412
  let request = createClientSideRequest(
1417
1413
  init.history,
1418
- location2,
1414
+ location,
1419
1415
  pendingNavigationController.signal,
1420
1416
  opts && opts.submission
1421
1417
  );
@@ -1431,7 +1427,7 @@ function createRouter(init) {
1431
1427
  } else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
1432
1428
  let actionResult = await handleAction(
1433
1429
  request,
1434
- location2,
1430
+ location,
1435
1431
  opts.submission,
1436
1432
  matches,
1437
1433
  scopedContext,
@@ -1446,7 +1442,7 @@ function createRouter(init) {
1446
1442
  let [routeId, result] = actionResult.pendingActionResult;
1447
1443
  if (isErrorResult(result) && isRouteErrorResponse(result.error) && result.error.status === 404) {
1448
1444
  pendingNavigationController = null;
1449
- completeNavigation(location2, {
1445
+ completeNavigation(location, {
1450
1446
  matches: actionResult.matches,
1451
1447
  loaderData: {},
1452
1448
  errors: {
@@ -1458,7 +1454,7 @@ function createRouter(init) {
1458
1454
  }
1459
1455
  matches = actionResult.matches || matches;
1460
1456
  pendingActionResult = actionResult.pendingActionResult;
1461
- loadingNavigation = getLoadingNavigation(location2, opts.submission);
1457
+ loadingNavigation = getLoadingNavigation(location, opts.submission);
1462
1458
  flushSync = false;
1463
1459
  fogOfWar.active = false;
1464
1460
  request = createClientSideRequest(
@@ -1474,7 +1470,7 @@ function createRouter(init) {
1474
1470
  errors
1475
1471
  } = await handleLoaders(
1476
1472
  request,
1477
- location2,
1473
+ location,
1478
1474
  matches,
1479
1475
  scopedContext,
1480
1476
  fogOfWar.active,
@@ -1490,21 +1486,21 @@ function createRouter(init) {
1490
1486
  return;
1491
1487
  }
1492
1488
  pendingNavigationController = null;
1493
- completeNavigation(location2, {
1489
+ completeNavigation(location, {
1494
1490
  matches: updatedMatches || matches,
1495
1491
  ...getActionDataForCommit(pendingActionResult),
1496
1492
  loaderData,
1497
1493
  errors
1498
1494
  });
1499
1495
  }
1500
- async function handleAction(request, location2, submission, matches, scopedContext, isFogOfWar, initialHydration, opts = {}) {
1496
+ async function handleAction(request, location, submission, matches, scopedContext, isFogOfWar, initialHydration, opts = {}) {
1501
1497
  interruptActiveLoads();
1502
- let navigation = getSubmittingNavigation(location2, submission);
1498
+ let navigation = getSubmittingNavigation(location, submission);
1503
1499
  updateState({ navigation }, { flushSync: opts.flushSync === true });
1504
1500
  if (isFogOfWar) {
1505
1501
  let discoverResult = await discoverRoutes(
1506
1502
  matches,
1507
- location2.pathname,
1503
+ location.pathname,
1508
1504
  request.signal
1509
1505
  );
1510
1506
  if (discoverResult.type === "aborted") {
@@ -1523,7 +1519,7 @@ function createRouter(init) {
1523
1519
  };
1524
1520
  } else if (!discoverResult.matches) {
1525
1521
  let { notFoundMatches, error, route } = handleNavigational404(
1526
- location2.pathname
1522
+ location.pathname
1527
1523
  );
1528
1524
  return {
1529
1525
  matches: notFoundMatches,
@@ -1540,13 +1536,13 @@ function createRouter(init) {
1540
1536
  }
1541
1537
  }
1542
1538
  let result;
1543
- let actionMatch = getTargetMatch(matches, location2);
1539
+ let actionMatch = getTargetMatch(matches, location);
1544
1540
  if (!actionMatch.route.action && !actionMatch.route.lazy) {
1545
1541
  result = {
1546
1542
  type: "error" /* error */,
1547
1543
  error: getInternalRouterError(405, {
1548
1544
  method: request.method,
1549
- pathname: location2.pathname,
1545
+ pathname: location.pathname,
1550
1546
  routeId: actionMatch.route.id
1551
1547
  })
1552
1548
  };
@@ -1584,12 +1580,12 @@ function createRouter(init) {
1584
1580
  if (opts && opts.replace != null) {
1585
1581
  replace2 = opts.replace;
1586
1582
  } else {
1587
- let location3 = normalizeRedirectLocation(
1583
+ let location2 = normalizeRedirectLocation(
1588
1584
  result.response.headers.get("Location"),
1589
1585
  new URL(request.url),
1590
1586
  basename
1591
1587
  );
1592
- replace2 = location3 === state.location.pathname + state.location.search;
1588
+ replace2 = location2 === state.location.pathname + state.location.search;
1593
1589
  }
1594
1590
  await startRedirectNavigation(request, result, true, {
1595
1591
  submission,
@@ -1604,7 +1600,11 @@ function createRouter(init) {
1604
1600
  }
1605
1601
  return {
1606
1602
  matches,
1607
- pendingActionResult: [boundaryMatch.route.id, result]
1603
+ pendingActionResult: [
1604
+ boundaryMatch.route.id,
1605
+ result,
1606
+ actionMatch.route.id
1607
+ ]
1608
1608
  };
1609
1609
  }
1610
1610
  return {
@@ -1612,8 +1612,8 @@ function createRouter(init) {
1612
1612
  pendingActionResult: [actionMatch.route.id, result]
1613
1613
  };
1614
1614
  }
1615
- async function handleLoaders(request, location2, matches, scopedContext, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
1616
- let loadingNavigation = overrideNavigation || getLoadingNavigation(location2, submission);
1615
+ async function handleLoaders(request, location, matches, scopedContext, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
1616
+ let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
1617
1617
  let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
1618
1618
  let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
1619
1619
  if (isFogOfWar) {
@@ -1631,7 +1631,7 @@ function createRouter(init) {
1631
1631
  }
1632
1632
  let discoverResult = await discoverRoutes(
1633
1633
  matches,
1634
- location2.pathname,
1634
+ location.pathname,
1635
1635
  request.signal
1636
1636
  );
1637
1637
  if (discoverResult.type === "aborted") {
@@ -1647,7 +1647,7 @@ function createRouter(init) {
1647
1647
  };
1648
1648
  } else if (!discoverResult.matches) {
1649
1649
  let { error, notFoundMatches, route } = handleNavigational404(
1650
- location2.pathname
1650
+ location.pathname
1651
1651
  );
1652
1652
  return {
1653
1653
  matches: notFoundMatches,
@@ -1670,7 +1670,7 @@ function createRouter(init) {
1670
1670
  state,
1671
1671
  matches,
1672
1672
  activeSubmission,
1673
- location2,
1673
+ location,
1674
1674
  initialHydration ? [] : hydrationRouteProperties2,
1675
1675
  initialHydration === true,
1676
1676
  isRevalidationRequired,
@@ -1686,7 +1686,7 @@ function createRouter(init) {
1686
1686
  if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && revalidatingFetchers.length === 0) {
1687
1687
  let updatedFetchers2 = markFetchRedirectsDone();
1688
1688
  completeNavigation(
1689
- location2,
1689
+ location,
1690
1690
  {
1691
1691
  matches,
1692
1692
  loaderData: {},
@@ -2046,6 +2046,10 @@ function createRouter(init) {
2046
2046
  fetchReloadIds.delete(key);
2047
2047
  fetchControllers.delete(key);
2048
2048
  revalidatingFetchers.forEach((r) => fetchControllers.delete(r.key));
2049
+ if (state.fetchers.has(key)) {
2050
+ let doneFetcher = getDoneFetcher(actionResult.data);
2051
+ state.fetchers.set(key, doneFetcher);
2052
+ }
2049
2053
  let redirect2 = findRedirect(loaderResults);
2050
2054
  if (redirect2) {
2051
2055
  return startRedirectNavigation(
@@ -2073,10 +2077,6 @@ function createRouter(init) {
2073
2077
  revalidatingFetchers,
2074
2078
  fetcherResults
2075
2079
  );
2076
- if (state.fetchers.has(key)) {
2077
- let doneFetcher = getDoneFetcher(actionResult.data);
2078
- state.fetchers.set(key, doneFetcher);
2079
- }
2080
2080
  abortStaleFetchLoads(loadId);
2081
2081
  if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) {
2082
2082
  invariant(pendingAction, "Expected pending action");
@@ -2197,31 +2197,31 @@ function createRouter(init) {
2197
2197
  if (redirect2.response.headers.has("X-Remix-Revalidate")) {
2198
2198
  isRevalidationRequired = true;
2199
2199
  }
2200
- let location2 = redirect2.response.headers.get("Location");
2201
- invariant(location2, "Expected a Location header on the redirect Response");
2202
- location2 = normalizeRedirectLocation(
2203
- location2,
2200
+ let location = redirect2.response.headers.get("Location");
2201
+ invariant(location, "Expected a Location header on the redirect Response");
2202
+ location = normalizeRedirectLocation(
2203
+ location,
2204
2204
  new URL(request.url),
2205
2205
  basename
2206
2206
  );
2207
- let redirectLocation = createLocation(state.location, location2, {
2207
+ let redirectLocation = createLocation(state.location, location, {
2208
2208
  _isRedirect: true
2209
2209
  });
2210
2210
  if (isBrowser2) {
2211
2211
  let isDocumentReload = false;
2212
2212
  if (redirect2.response.headers.has("X-Remix-Reload-Document")) {
2213
2213
  isDocumentReload = true;
2214
- } else if (ABSOLUTE_URL_REGEX.test(location2)) {
2215
- const url = init.history.createURL(location2);
2214
+ } else if (ABSOLUTE_URL_REGEX.test(location)) {
2215
+ const url = createBrowserURLImpl(location, true);
2216
2216
  isDocumentReload = // Hard reload if it's an absolute URL to a new origin
2217
2217
  url.origin !== routerWindow.location.origin || // Hard reload if it's an absolute URL that does not match our basename
2218
2218
  stripBasename(url.pathname, basename) == null;
2219
2219
  }
2220
2220
  if (isDocumentReload) {
2221
2221
  if (replace2) {
2222
- routerWindow.location.replace(location2);
2222
+ routerWindow.location.replace(location);
2223
2223
  } else {
2224
- routerWindow.location.assign(location2);
2224
+ routerWindow.location.assign(location);
2225
2225
  }
2226
2226
  return;
2227
2227
  }
@@ -2237,7 +2237,7 @@ function createRouter(init) {
2237
2237
  await startNavigation(redirectNavigationType, redirectLocation, {
2238
2238
  submission: {
2239
2239
  ...activeSubmission,
2240
- formAction: location2
2240
+ formAction: location
2241
2241
  },
2242
2242
  // Preserve these flags across redirects
2243
2243
  preventScrollReset: preventScrollReset || pendingPreventScrollReset,
@@ -2279,6 +2279,9 @@ function createRouter(init) {
2279
2279
  });
2280
2280
  return dataResults;
2281
2281
  }
2282
+ if (request.signal.aborted) {
2283
+ return dataResults;
2284
+ }
2282
2285
  for (let [routeId, result] of Object.entries(results)) {
2283
2286
  if (isRedirectDataStrategyResult(result)) {
2284
2287
  let response = result.result;
@@ -2508,25 +2511,25 @@ function createRouter(init) {
2508
2511
  getScrollRestorationKey2 = null;
2509
2512
  };
2510
2513
  }
2511
- function getScrollKey(location2, matches) {
2514
+ function getScrollKey(location, matches) {
2512
2515
  if (getScrollRestorationKey2) {
2513
2516
  let key = getScrollRestorationKey2(
2514
- location2,
2517
+ location,
2515
2518
  matches.map((m) => convertRouteMatchToUiMatch(m, state.loaderData))
2516
2519
  );
2517
- return key || location2.key;
2520
+ return key || location.key;
2518
2521
  }
2519
- return location2.key;
2522
+ return location.key;
2520
2523
  }
2521
- function saveScrollPosition(location2, matches) {
2524
+ function saveScrollPosition(location, matches) {
2522
2525
  if (savedScrollPositions2 && getScrollPosition) {
2523
- let key = getScrollKey(location2, matches);
2526
+ let key = getScrollKey(location, matches);
2524
2527
  savedScrollPositions2[key] = getScrollPosition();
2525
2528
  }
2526
2529
  }
2527
- function getSavedScrollPosition(location2, matches) {
2530
+ function getSavedScrollPosition(location, matches) {
2528
2531
  if (savedScrollPositions2) {
2529
- let key = getScrollKey(location2, matches);
2532
+ let key = getScrollKey(location, matches);
2530
2533
  let y = savedScrollPositions2[key];
2531
2534
  if (typeof y === "number") {
2532
2535
  return y;
@@ -2580,8 +2583,7 @@ function createRouter(init) {
2580
2583
  children,
2581
2584
  routesToUse,
2582
2585
  localManifest,
2583
- mapRouteProperties2,
2584
- false
2586
+ mapRouteProperties2
2585
2587
  );
2586
2588
  }
2587
2589
  });
@@ -2622,7 +2624,7 @@ function createRouter(init) {
2622
2624
  manifest
2623
2625
  );
2624
2626
  }
2625
- function patchRoutes(routeId, children, unstable_allowElementMutations = false) {
2627
+ function patchRoutes(routeId, children) {
2626
2628
  let isNonHMR = inFlightDataRoutes == null;
2627
2629
  let routesToUse = inFlightDataRoutes || dataRoutes;
2628
2630
  patchRoutesImpl(
@@ -2630,8 +2632,7 @@ function createRouter(init) {
2630
2632
  children,
2631
2633
  routesToUse,
2632
2634
  manifest,
2633
- mapRouteProperties2,
2634
- unstable_allowElementMutations
2635
+ mapRouteProperties2
2635
2636
  );
2636
2637
  if (isNonHMR) {
2637
2638
  dataRoutes = [...dataRoutes];
@@ -2673,10 +2674,7 @@ function createRouter(init) {
2673
2674
  _internalFetchControllers: fetchControllers,
2674
2675
  // TODO: Remove setRoutes, it's temporary to avoid dealing with
2675
2676
  // updating the tree while validating the update algorithm.
2676
- _internalSetRoutes,
2677
- _internalSetStateDoNotUseOrYouWillBreakYourApp(newState) {
2678
- updateState(newState);
2679
- }
2677
+ _internalSetRoutes
2680
2678
  };
2681
2679
  return router;
2682
2680
  }
@@ -2704,15 +2702,15 @@ function createStaticHandler(routes, opts) {
2704
2702
  } = {}) {
2705
2703
  let url = new URL(request.url);
2706
2704
  let method = request.method;
2707
- let location2 = createLocation("", createPath(url), null, "default");
2708
- let matches = matchRoutes(dataRoutes, location2, basename);
2705
+ let location = createLocation("", createPath(url), null, "default");
2706
+ let matches = matchRoutes(dataRoutes, location, basename);
2709
2707
  requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
2710
2708
  if (!isValidMethod(method) && method !== "HEAD") {
2711
2709
  let error = getInternalRouterError(405, { method });
2712
2710
  let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
2713
2711
  let staticContext = {
2714
2712
  basename,
2715
- location: location2,
2713
+ location,
2716
2714
  matches: methodNotAllowedMatches,
2717
2715
  loaderData: {},
2718
2716
  actionData: null,
@@ -2725,11 +2723,11 @@ function createStaticHandler(routes, opts) {
2725
2723
  };
2726
2724
  return respond ? respond(staticContext) : staticContext;
2727
2725
  } else if (!matches) {
2728
- let error = getInternalRouterError(404, { pathname: location2.pathname });
2726
+ let error = getInternalRouterError(404, { pathname: location.pathname });
2729
2727
  let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
2730
2728
  let staticContext = {
2731
2729
  basename,
2732
- location: location2,
2730
+ location,
2733
2731
  matches: notFoundMatches,
2734
2732
  loaderData: {},
2735
2733
  actionData: null,
@@ -2769,7 +2767,7 @@ function createStaticHandler(routes, opts) {
2769
2767
  async () => {
2770
2768
  let result2 = await queryImpl(
2771
2769
  request,
2772
- location2,
2770
+ location,
2773
2771
  matches,
2774
2772
  requestContext,
2775
2773
  dataStrategy || null,
@@ -2781,7 +2779,7 @@ function createStaticHandler(routes, opts) {
2781
2779
  if (isResponse(result2)) {
2782
2780
  return result2;
2783
2781
  }
2784
- renderedStaticContext = { location: location2, basename, ...result2 };
2782
+ renderedStaticContext = { location, basename, ...result2 };
2785
2783
  let res = await respond(renderedStaticContext);
2786
2784
  return res;
2787
2785
  },
@@ -2798,20 +2796,24 @@ function createStaticHandler(routes, opts) {
2798
2796
  dataRoutes,
2799
2797
  renderedStaticContext,
2800
2798
  error,
2801
- findNearestBoundary(matches, routeId).route.id
2799
+ skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
2802
2800
  )
2803
2801
  );
2804
2802
  } else {
2805
- let loaderIdx = matches.findIndex((m) => m.route.loader);
2806
- let boundary = loaderIdx >= 0 ? findNearestBoundary(matches, matches[loaderIdx].route.id) : findNearestBoundary(matches);
2803
+ let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
2804
+ matches,
2805
+ matches.find(
2806
+ (m) => m.route.id === routeId || m.route.loader
2807
+ )?.route.id || routeId
2808
+ ).route.id;
2807
2809
  return respond({
2808
2810
  matches,
2809
- location: location2,
2811
+ location,
2810
2812
  basename,
2811
2813
  loaderData: {},
2812
2814
  actionData: null,
2813
2815
  errors: {
2814
- [boundary.route.id]: error
2816
+ [boundaryRouteId]: error
2815
2817
  },
2816
2818
  statusCode: isRouteErrorResponse(error) ? error.status : 500,
2817
2819
  actionHeaders: {},
@@ -2831,7 +2833,7 @@ function createStaticHandler(routes, opts) {
2831
2833
  }
2832
2834
  let result = await queryImpl(
2833
2835
  request,
2834
- location2,
2836
+ location,
2835
2837
  matches,
2836
2838
  requestContext,
2837
2839
  dataStrategy || null,
@@ -2843,7 +2845,7 @@ function createStaticHandler(routes, opts) {
2843
2845
  if (isResponse(result)) {
2844
2846
  return result;
2845
2847
  }
2846
- return { location: location2, basename, ...result };
2848
+ return { location, basename, ...result };
2847
2849
  }
2848
2850
  async function queryRoute(request, {
2849
2851
  routeId,
@@ -2853,22 +2855,22 @@ function createStaticHandler(routes, opts) {
2853
2855
  } = {}) {
2854
2856
  let url = new URL(request.url);
2855
2857
  let method = request.method;
2856
- let location2 = createLocation("", createPath(url), null, "default");
2857
- let matches = matchRoutes(dataRoutes, location2, basename);
2858
+ let location = createLocation("", createPath(url), null, "default");
2859
+ let matches = matchRoutes(dataRoutes, location, basename);
2858
2860
  requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
2859
2861
  if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
2860
2862
  throw getInternalRouterError(405, { method });
2861
2863
  } else if (!matches) {
2862
- throw getInternalRouterError(404, { pathname: location2.pathname });
2864
+ throw getInternalRouterError(404, { pathname: location.pathname });
2863
2865
  }
2864
- let match = routeId ? matches.find((m) => m.route.id === routeId) : getTargetMatch(matches, location2);
2866
+ let match = routeId ? matches.find((m) => m.route.id === routeId) : getTargetMatch(matches, location);
2865
2867
  if (routeId && !match) {
2866
2868
  throw getInternalRouterError(403, {
2867
- pathname: location2.pathname,
2869
+ pathname: location.pathname,
2868
2870
  routeId
2869
2871
  });
2870
2872
  } else if (!match) {
2871
- throw getInternalRouterError(404, { pathname: location2.pathname });
2873
+ throw getInternalRouterError(404, { pathname: location.pathname });
2872
2874
  }
2873
2875
  if (respond && matches.some(
2874
2876
  (m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
@@ -2891,7 +2893,7 @@ function createStaticHandler(routes, opts) {
2891
2893
  async () => {
2892
2894
  let result2 = await queryImpl(
2893
2895
  request,
2894
- location2,
2896
+ location,
2895
2897
  matches,
2896
2898
  requestContext,
2897
2899
  dataStrategy || null,
@@ -2924,7 +2926,7 @@ function createStaticHandler(routes, opts) {
2924
2926
  }
2925
2927
  let result = await queryImpl(
2926
2928
  request,
2927
- location2,
2929
+ location,
2928
2930
  matches,
2929
2931
  requestContext,
2930
2932
  dataStrategy || null,
@@ -2948,7 +2950,7 @@ function createStaticHandler(routes, opts) {
2948
2950
  }
2949
2951
  return void 0;
2950
2952
  }
2951
- async function queryImpl(request, location2, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
2953
+ async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
2952
2954
  invariant(
2953
2955
  request.signal,
2954
2956
  "query()/queryRoute() requests must contain an AbortController signal"
@@ -2958,7 +2960,7 @@ function createStaticHandler(routes, opts) {
2958
2960
  let result2 = await submit(
2959
2961
  request,
2960
2962
  matches,
2961
- routeMatch || getTargetMatch(matches, location2),
2963
+ routeMatch || getTargetMatch(matches, location),
2962
2964
  requestContext,
2963
2965
  dataStrategy,
2964
2966
  skipLoaderErrorBubbling,
@@ -3274,7 +3276,7 @@ function throwStaticHandlerAbortedError(request, isRouteRequest) {
3274
3276
  function isSubmissionNavigation(opts) {
3275
3277
  return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== void 0);
3276
3278
  }
3277
- function normalizeTo(location2, matches, basename, to, fromRouteId, relative) {
3279
+ function normalizeTo(location, matches, basename, to, fromRouteId, relative) {
3278
3280
  let contextualMatches;
3279
3281
  let activeRouteMatch;
3280
3282
  if (fromRouteId) {
@@ -3293,12 +3295,12 @@ function normalizeTo(location2, matches, basename, to, fromRouteId, relative) {
3293
3295
  let path = resolveTo(
3294
3296
  to ? to : ".",
3295
3297
  getResolveToMatches(contextualMatches),
3296
- stripBasename(location2.pathname, basename) || location2.pathname,
3298
+ stripBasename(location.pathname, basename) || location.pathname,
3297
3299
  relative === "path"
3298
3300
  );
3299
3301
  if (to == null) {
3300
- path.search = location2.search;
3301
- path.hash = location2.hash;
3302
+ path.search = location.search;
3303
+ path.hash = location.hash;
3302
3304
  }
3303
3305
  if ((to == null || to === "" || to === ".") && activeRouteMatch) {
3304
3306
  let nakedIndex = hasNakedIndexQuery(path.search);
@@ -3425,10 +3427,10 @@ function normalizeNavigateOptions(isFetcher, path, opts) {
3425
3427
  parsedPath.search = `?${searchParams}`;
3426
3428
  return { path: createPath(parsedPath), submission };
3427
3429
  }
3428
- function getMatchesToLoad(request, scopedContext, mapRouteProperties2, manifest, history, state, matches, submission, location2, lazyRoutePropertiesToSkip, initialHydration, isRevalidationRequired, cancelledFetcherLoads, fetchersQueuedForDeletion, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult) {
3430
+ function getMatchesToLoad(request, scopedContext, mapRouteProperties2, manifest, history, state, matches, submission, location, lazyRoutePropertiesToSkip, initialHydration, isRevalidationRequired, cancelledFetcherLoads, fetchersQueuedForDeletion, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult) {
3429
3431
  let actionResult = pendingActionResult ? isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : pendingActionResult[1].data : void 0;
3430
3432
  let currentUrl = history.createURL(state.location);
3431
- let nextUrl = history.createURL(location2);
3433
+ let nextUrl = history.createURL(location);
3432
3434
  let maxIdx;
3433
3435
  if (initialHydration && state.errors) {
3434
3436
  let boundaryId = Object.keys(state.errors)[0];
@@ -3590,7 +3592,7 @@ function shouldLoadRouteOnHydration(route, loaderData, errors) {
3590
3592
  if (!route.loader) {
3591
3593
  return false;
3592
3594
  }
3593
- let hasData = loaderData != null && loaderData[route.id] !== void 0;
3595
+ let hasData = loaderData != null && route.id in loaderData;
3594
3596
  let hasError = errors != null && errors[route.id] !== void 0;
3595
3597
  if (!hasData && hasError) {
3596
3598
  return false;
@@ -3627,7 +3629,7 @@ function shouldRevalidateLoader(loaderMatch, arg) {
3627
3629
  }
3628
3630
  return arg.defaultShouldRevalidate;
3629
3631
  }
3630
- function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties2, allowElementMutations) {
3632
+ function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties2) {
3631
3633
  let childrenToPatch;
3632
3634
  if (routeId) {
3633
3635
  let route = manifest[routeId];
@@ -3642,47 +3644,18 @@ function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRoutePrope
3642
3644
  } else {
3643
3645
  childrenToPatch = routesToUse;
3644
3646
  }
3645
- let uniqueChildren = [];
3646
- let existingChildren = [];
3647
- children.forEach((newRoute) => {
3648
- let existingRoute = childrenToPatch.find(
3649
- (existingRoute2) => isSameRoute(newRoute, existingRoute2)
3650
- );
3651
- if (existingRoute) {
3652
- existingChildren.push({ existingRoute, newRoute });
3653
- } else {
3654
- uniqueChildren.push(newRoute);
3655
- }
3656
- });
3657
- if (uniqueChildren.length > 0) {
3658
- let newRoutes = convertRoutesToDataRoutes(
3659
- uniqueChildren,
3660
- mapRouteProperties2,
3661
- [routeId || "_", "patch", String(childrenToPatch?.length || "0")],
3662
- manifest
3663
- );
3664
- childrenToPatch.push(...newRoutes);
3665
- }
3666
- if (allowElementMutations && existingChildren.length > 0) {
3667
- for (let i = 0; i < existingChildren.length; i++) {
3668
- let { existingRoute, newRoute } = existingChildren[i];
3669
- let existingRouteTyped = existingRoute;
3670
- let [newRouteTyped] = convertRoutesToDataRoutes(
3671
- [newRoute],
3672
- mapRouteProperties2,
3673
- [],
3674
- // Doesn't matter for mutated routes since they already have an id
3675
- {},
3676
- // Don't touch the manifest here since we're updating in place
3677
- true
3678
- );
3679
- Object.assign(existingRouteTyped, {
3680
- element: newRouteTyped.element ? newRouteTyped.element : existingRouteTyped.element,
3681
- errorElement: newRouteTyped.errorElement ? newRouteTyped.errorElement : existingRouteTyped.errorElement,
3682
- hydrateFallbackElement: newRouteTyped.hydrateFallbackElement ? newRouteTyped.hydrateFallbackElement : existingRouteTyped.hydrateFallbackElement
3683
- });
3684
- }
3685
- }
3647
+ let uniqueChildren = children.filter(
3648
+ (newRoute) => !childrenToPatch.some(
3649
+ (existingRoute) => isSameRoute(newRoute, existingRoute)
3650
+ )
3651
+ );
3652
+ let newRoutes = convertRoutesToDataRoutes(
3653
+ uniqueChildren,
3654
+ mapRouteProperties2,
3655
+ [routeId || "_", "patch", String(childrenToPatch?.length || "0")],
3656
+ manifest
3657
+ );
3658
+ childrenToPatch.push(...newRoutes);
3686
3659
  }
3687
3660
  function isSameRoute(newRoute, existingRoute) {
3688
3661
  if ("id" in newRoute && "id" in existingRoute && newRoute.id === existingRoute.id) {
@@ -3895,15 +3868,9 @@ async function runMiddlewarePipeline(args, propagateResult, handler, errorHandle
3895
3868
  handlerResult: void 0
3896
3869
  };
3897
3870
  try {
3898
- let tuples = [];
3899
- for (let m of matches) {
3900
- if (m.route.unstable_middleware) {
3901
- for (let fn of m.route.unstable_middleware) {
3902
- let tuple = [m.route.id, fn];
3903
- tuples.push(tuple);
3904
- }
3905
- }
3906
- }
3871
+ let tuples = matches.flatMap(
3872
+ (m) => m.route.unstable_middleware ? m.route.unstable_middleware.map((fn) => [m.route.id, fn]) : []
3873
+ );
3907
3874
  let result = await callRouteMiddleware(
3908
3875
  { request, params, context },
3909
3876
  tuples,
@@ -4037,7 +4004,7 @@ function getDataStrategyMatch(mapRouteProperties2, manifest, request, match, laz
4037
4004
  return shouldRevalidateLoader(match, unstable_shouldRevalidateArgs);
4038
4005
  },
4039
4006
  resolve(handlerOverride) {
4040
- if (isUsingNewApi || shouldLoad || handlerOverride && !isMutationMethod(request.method) && (match.route.lazy || match.route.loader)) {
4007
+ if (isUsingNewApi || shouldLoad || handlerOverride && request.method === "GET" && (match.route.lazy || match.route.loader)) {
4041
4008
  return callLoaderOrAction({
4042
4009
  request,
4043
4010
  match,
@@ -4297,39 +4264,39 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
4297
4264
  return { type: "data" /* data */, data: result };
4298
4265
  }
4299
4266
  function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
4300
- let location2 = response.headers.get("Location");
4267
+ let location = response.headers.get("Location");
4301
4268
  invariant(
4302
- location2,
4269
+ location,
4303
4270
  "Redirects returned/thrown from loaders/actions must have a Location header"
4304
4271
  );
4305
- if (!ABSOLUTE_URL_REGEX.test(location2)) {
4272
+ if (!ABSOLUTE_URL_REGEX.test(location)) {
4306
4273
  let trimmedMatches = matches.slice(
4307
4274
  0,
4308
4275
  matches.findIndex((m) => m.route.id === routeId) + 1
4309
4276
  );
4310
- location2 = normalizeTo(
4277
+ location = normalizeTo(
4311
4278
  new URL(request.url),
4312
4279
  trimmedMatches,
4313
4280
  basename,
4314
- location2
4281
+ location
4315
4282
  );
4316
- response.headers.set("Location", location2);
4283
+ response.headers.set("Location", location);
4317
4284
  }
4318
4285
  return response;
4319
4286
  }
4320
- function normalizeRedirectLocation(location2, currentUrl, basename) {
4321
- if (ABSOLUTE_URL_REGEX.test(location2)) {
4322
- let normalizedLocation = location2;
4287
+ function normalizeRedirectLocation(location, currentUrl, basename) {
4288
+ if (ABSOLUTE_URL_REGEX.test(location)) {
4289
+ let normalizedLocation = location;
4323
4290
  let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
4324
4291
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4325
4292
  if (url.origin === currentUrl.origin && isSameBasename) {
4326
4293
  return url.pathname + url.search + url.hash;
4327
4294
  }
4328
4295
  }
4329
- return location2;
4296
+ return location;
4330
4297
  }
4331
- function createClientSideRequest(history, location2, signal, submission) {
4332
- let url = history.createURL(stripHashFromPath(location2)).toString();
4298
+ function createClientSideRequest(history, location, signal, submission) {
4299
+ let url = history.createURL(stripHashFromPath(location)).toString();
4333
4300
  let init = { signal };
4334
4301
  if (submission && isMutationMethod(submission.formMethod)) {
4335
4302
  let { formMethod, formEncType } = submission;
@@ -4415,7 +4382,9 @@ function processRouteLoaderData(matches, results, pendingActionResult, isStaticH
4415
4382
  });
4416
4383
  if (pendingError !== void 0 && pendingActionResult) {
4417
4384
  errors = { [pendingActionResult[0]]: pendingError };
4418
- loaderData[pendingActionResult[0]] = void 0;
4385
+ if (pendingActionResult[2]) {
4386
+ loaderData[pendingActionResult[2]] = void 0;
4387
+ }
4419
4388
  }
4420
4389
  return {
4421
4390
  loaderData,
@@ -4599,8 +4568,8 @@ function isMutationMethod(method) {
4599
4568
  function hasNakedIndexQuery(search) {
4600
4569
  return new URLSearchParams(search).getAll("index").some((v) => v === "");
4601
4570
  }
4602
- function getTargetMatch(matches, location2) {
4603
- let search = typeof location2 === "string" ? parsePath(location2).search : location2.search;
4571
+ function getTargetMatch(matches, location) {
4572
+ let search = typeof location === "string" ? parsePath(location).search : location.search;
4604
4573
  if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
4605
4574
  return matches[matches.length - 1];
4606
4575
  }
@@ -4641,11 +4610,11 @@ function getSubmissionFromNavigation(navigation) {
4641
4610
  };
4642
4611
  }
4643
4612
  }
4644
- function getLoadingNavigation(location2, submission) {
4613
+ function getLoadingNavigation(location, submission) {
4645
4614
  if (submission) {
4646
4615
  let navigation = {
4647
4616
  state: "loading",
4648
- location: location2,
4617
+ location,
4649
4618
  formMethod: submission.formMethod,
4650
4619
  formAction: submission.formAction,
4651
4620
  formEncType: submission.formEncType,
@@ -4657,7 +4626,7 @@ function getLoadingNavigation(location2, submission) {
4657
4626
  } else {
4658
4627
  let navigation = {
4659
4628
  state: "loading",
4660
- location: location2,
4629
+ location,
4661
4630
  formMethod: void 0,
4662
4631
  formAction: void 0,
4663
4632
  formEncType: void 0,
@@ -4668,10 +4637,10 @@ function getLoadingNavigation(location2, submission) {
4668
4637
  return navigation;
4669
4638
  }
4670
4639
  }
4671
- function getSubmittingNavigation(location2, submission) {
4640
+ function getSubmittingNavigation(location, submission) {
4672
4641
  let navigation = {
4673
4642
  state: "submitting",
4674
- location: location2,
4643
+ location,
4675
4644
  formMethod: submission.formMethod,
4676
4645
  formAction: submission.formAction,
4677
4646
  formEncType: submission.formEncType,
@@ -4832,10 +4801,10 @@ var RouteContext = React.createContext({
4832
4801
  RouteContext.displayName = "Route";
4833
4802
  var RouteErrorContext = React.createContext(null);
4834
4803
  RouteErrorContext.displayName = "RouteError";
4804
+ var ENABLE_DEV_WARNINGS = true;
4835
4805
 
4836
4806
  // lib/hooks.tsx
4837
4807
  import * as React2 from "react";
4838
- var ENABLE_DEV_WARNINGS = true;
4839
4808
  function useHref(to, { relative } = {}) {
4840
4809
  invariant(
4841
4810
  useInRouterContext(),
@@ -4843,13 +4812,13 @@ function useHref(to, { relative } = {}) {
4843
4812
  // router loaded. We can help them understand how to avoid that.
4844
4813
  `useHref() may be used only in the context of a <Router> component.`
4845
4814
  );
4846
- let { basename, navigator: navigator2 } = React2.useContext(NavigationContext);
4815
+ let { basename, navigator } = React2.useContext(NavigationContext);
4847
4816
  let { hash, pathname, search } = useResolvedPath(to, { relative });
4848
4817
  let joinedPathname = pathname;
4849
4818
  if (basename !== "/") {
4850
4819
  joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
4851
4820
  }
4852
- return navigator2.createHref({ pathname: joinedPathname, search, hash });
4821
+ return navigator.createHref({ pathname: joinedPathname, search, hash });
4853
4822
  }
4854
4823
  function useInRouterContext() {
4855
4824
  return React2.useContext(LocationContext) != null;
@@ -4898,7 +4867,7 @@ function useNavigateUnstable() {
4898
4867
  `useNavigate() may be used only in the context of a <Router> component.`
4899
4868
  );
4900
4869
  let dataRouterContext = React2.useContext(DataRouterContext);
4901
- let { basename, navigator: navigator2 } = React2.useContext(NavigationContext);
4870
+ let { basename, navigator } = React2.useContext(NavigationContext);
4902
4871
  let { matches } = React2.useContext(RouteContext);
4903
4872
  let { pathname: locationPathname } = useLocation();
4904
4873
  let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
@@ -4911,7 +4880,7 @@ function useNavigateUnstable() {
4911
4880
  warning(activeRef.current, navigateEffectWarning);
4912
4881
  if (!activeRef.current) return;
4913
4882
  if (typeof to === "number") {
4914
- navigator2.go(to);
4883
+ navigator.go(to);
4915
4884
  return;
4916
4885
  }
4917
4886
  let path = resolveTo(
@@ -4923,7 +4892,7 @@ function useNavigateUnstable() {
4923
4892
  if (dataRouterContext == null && basename !== "/") {
4924
4893
  path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
4925
4894
  }
4926
- (!!options.replace ? navigator2.replace : navigator2.push)(
4895
+ (!!options.replace ? navigator.replace : navigator.push)(
4927
4896
  path,
4928
4897
  options.state,
4929
4898
  options
@@ -4931,7 +4900,7 @@ function useNavigateUnstable() {
4931
4900
  },
4932
4901
  [
4933
4902
  basename,
4934
- navigator2,
4903
+ navigator,
4935
4904
  routePathnamesJson,
4936
4905
  locationPathname,
4937
4906
  dataRouterContext
@@ -4979,7 +4948,7 @@ function useRoutesImpl(routes, locationArg, dataRouterState, future) {
4979
4948
  // router loaded. We can help them understand how to avoid that.
4980
4949
  `useRoutes() may be used only in the context of a <Router> component.`
4981
4950
  );
4982
- let { navigator: navigator2, static: isStatic } = React2.useContext(NavigationContext);
4951
+ let { navigator, static: isStatic } = React2.useContext(NavigationContext);
4983
4952
  let { matches: parentMatches } = React2.useContext(RouteContext);
4984
4953
  let routeMatch = parentMatches[parentMatches.length - 1];
4985
4954
  let parentParams = routeMatch ? routeMatch.params : {};
@@ -4997,18 +4966,18 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
4997
4966
  );
4998
4967
  }
4999
4968
  let locationFromContext = useLocation();
5000
- let location2;
4969
+ let location;
5001
4970
  if (locationArg) {
5002
4971
  let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
5003
4972
  invariant(
5004
4973
  parentPathnameBase === "/" || parsedLocationArg.pathname?.startsWith(parentPathnameBase),
5005
4974
  `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.`
5006
4975
  );
5007
- location2 = parsedLocationArg;
4976
+ location = parsedLocationArg;
5008
4977
  } else {
5009
- location2 = locationFromContext;
4978
+ location = locationFromContext;
5010
4979
  }
5011
- let pathname = location2.pathname || "/";
4980
+ let pathname = location.pathname || "/";
5012
4981
  let remainingPathname = pathname;
5013
4982
  if (parentPathnameBase !== "/") {
5014
4983
  let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
@@ -5019,11 +4988,11 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
5019
4988
  if (ENABLE_DEV_WARNINGS) {
5020
4989
  warning(
5021
4990
  parentRoute || matches != null,
5022
- `No routes matched location "${location2.pathname}${location2.search}${location2.hash}" `
4991
+ `No routes matched location "${location.pathname}${location.search}${location.hash}" `
5023
4992
  );
5024
4993
  warning(
5025
4994
  matches == null || matches[matches.length - 1].route.element !== void 0 || matches[matches.length - 1].route.Component !== void 0 || matches[matches.length - 1].route.lazy !== void 0,
5026
- `Matched leaf route at location "${location2.pathname}${location2.search}${location2.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
4995
+ `Matched leaf route at location "${location.pathname}${location.search}${location.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
5027
4996
  );
5028
4997
  }
5029
4998
  let renderedMatches = _renderMatches(
@@ -5033,12 +5002,12 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
5033
5002
  pathname: joinPaths([
5034
5003
  parentPathnameBase,
5035
5004
  // Re-encode pathnames that were decoded inside matchRoutes
5036
- navigator2.encodeLocation ? navigator2.encodeLocation(match.pathname).pathname : match.pathname
5005
+ navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname
5037
5006
  ]),
5038
5007
  pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
5039
5008
  parentPathnameBase,
5040
5009
  // Re-encode pathnames that were decoded inside matchRoutes
5041
- navigator2.encodeLocation ? navigator2.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
5010
+ navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
5042
5011
  ])
5043
5012
  })
5044
5013
  ),
@@ -5057,7 +5026,7 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
5057
5026
  hash: "",
5058
5027
  state: null,
5059
5028
  key: "default",
5060
- ...location2
5029
+ ...location
5061
5030
  },
5062
5031
  navigationType: "POP" /* Pop */
5063
5032
  }
@@ -5288,14 +5257,12 @@ function useNavigation() {
5288
5257
  function useRevalidator() {
5289
5258
  let dataRouterContext = useDataRouterContext("useRevalidator" /* UseRevalidator */);
5290
5259
  let state = useDataRouterState("useRevalidator" /* UseRevalidator */);
5260
+ let revalidate = React2.useCallback(async () => {
5261
+ await dataRouterContext.router.revalidate();
5262
+ }, [dataRouterContext.router]);
5291
5263
  return React2.useMemo(
5292
- () => ({
5293
- async revalidate() {
5294
- await dataRouterContext.router.revalidate();
5295
- },
5296
- state: state.revalidation
5297
- }),
5298
- [dataRouterContext.router, state.revalidation]
5264
+ () => ({ revalidate, state: state.revalidation }),
5265
+ [revalidate, state.revalidation]
5299
5266
  );
5300
5267
  }
5301
5268
  function useMatches() {
@@ -5417,7 +5384,6 @@ function warnOnce(condition, message) {
5417
5384
  }
5418
5385
 
5419
5386
  // lib/components.tsx
5420
- var ENABLE_DEV_WARNINGS2 = true;
5421
5387
  function mapRouteProperties(route) {
5422
5388
  let updates = {
5423
5389
  // Note: this check also occurs in createRoutesFromChildren so update
@@ -5425,7 +5391,7 @@ function mapRouteProperties(route) {
5425
5391
  hasErrorBoundary: route.hasErrorBoundary || route.ErrorBoundary != null || route.errorElement != null
5426
5392
  };
5427
5393
  if (route.Component) {
5428
- if (ENABLE_DEV_WARNINGS2) {
5394
+ if (ENABLE_DEV_WARNINGS) {
5429
5395
  if (route.element) {
5430
5396
  warning(
5431
5397
  false,
@@ -5439,7 +5405,7 @@ function mapRouteProperties(route) {
5439
5405
  });
5440
5406
  }
5441
5407
  if (route.HydrateFallback) {
5442
- if (ENABLE_DEV_WARNINGS2) {
5408
+ if (ENABLE_DEV_WARNINGS) {
5443
5409
  if (route.hydrateFallbackElement) {
5444
5410
  warning(
5445
5411
  false,
@@ -5453,7 +5419,7 @@ function mapRouteProperties(route) {
5453
5419
  });
5454
5420
  }
5455
5421
  if (route.ErrorBoundary) {
5456
- if (ENABLE_DEV_WARNINGS2) {
5422
+ if (ENABLE_DEV_WARNINGS) {
5457
5423
  if (route.errorElement) {
5458
5424
  warning(
5459
5425
  false,
@@ -5633,7 +5599,7 @@ function RouterProvider({
5633
5599
  setInterruption(void 0);
5634
5600
  }
5635
5601
  }, [vtContext.isTransitioning, interruption]);
5636
- let navigator2 = React3.useMemo(() => {
5602
+ let navigator = React3.useMemo(() => {
5637
5603
  return {
5638
5604
  createHref: router.createHref,
5639
5605
  encodeLocation: router.encodeLocation,
@@ -5653,11 +5619,11 @@ function RouterProvider({
5653
5619
  let dataRouterContext = React3.useMemo(
5654
5620
  () => ({
5655
5621
  router,
5656
- navigator: navigator2,
5622
+ navigator,
5657
5623
  static: false,
5658
5624
  basename
5659
5625
  }),
5660
- [router, navigator2, basename]
5626
+ [router, navigator, basename]
5661
5627
  );
5662
5628
  return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(DataRouterContext.Provider, { value: dataRouterContext }, /* @__PURE__ */ React3.createElement(DataRouterStateContext.Provider, { value: state }, /* @__PURE__ */ React3.createElement(FetchersContext.Provider, { value: fetcherData.current }, /* @__PURE__ */ React3.createElement(ViewTransitionContext.Provider, { value: vtContext }, /* @__PURE__ */ React3.createElement(
5663
5629
  Router,
@@ -5665,7 +5631,7 @@ function RouterProvider({
5665
5631
  basename,
5666
5632
  location: state.location,
5667
5633
  navigationType: state.historyAction,
5668
- navigator: navigator2
5634
+ navigator
5669
5635
  },
5670
5636
  /* @__PURE__ */ React3.createElement(
5671
5637
  MemoizedDataRoutes,
@@ -5768,7 +5734,7 @@ function Router({
5768
5734
  children = null,
5769
5735
  location: locationProp,
5770
5736
  navigationType = "POP" /* Pop */,
5771
- navigator: navigator2,
5737
+ navigator,
5772
5738
  static: staticProp = false
5773
5739
  }) {
5774
5740
  invariant(
@@ -5779,11 +5745,11 @@ function Router({
5779
5745
  let navigationContext = React3.useMemo(
5780
5746
  () => ({
5781
5747
  basename,
5782
- navigator: navigator2,
5748
+ navigator,
5783
5749
  static: staticProp,
5784
5750
  future: {}
5785
5751
  }),
5786
- [basename, navigator2, staticProp]
5752
+ [basename, navigator, staticProp]
5787
5753
  );
5788
5754
  if (typeof locationProp === "string") {
5789
5755
  locationProp = parsePath(locationProp);
@@ -5822,9 +5788,9 @@ function Router({
5822
5788
  }
5823
5789
  function Routes({
5824
5790
  children,
5825
- location: location2
5791
+ location
5826
5792
  }) {
5827
- return useRoutes(createRoutesFromChildren(children), location2);
5793
+ return useRoutes(createRoutesFromChildren(children), location);
5828
5794
  }
5829
5795
  function Await({
5830
5796
  children,
@@ -5894,38 +5860,6 @@ function ResolveAwait({
5894
5860
  let toRender = typeof children === "function" ? children(data2) : children;
5895
5861
  return /* @__PURE__ */ React3.createElement(React3.Fragment, null, toRender);
5896
5862
  }
5897
- function WithRouteComponentProps({
5898
- children
5899
- }) {
5900
- let props = {
5901
- loaderData: useLoaderData(),
5902
- actionData: useActionData(),
5903
- params: useParams(),
5904
- matches: useMatches()
5905
- };
5906
- return React3.cloneElement(children, props);
5907
- }
5908
- function WithHydrateFallbackProps({
5909
- children
5910
- }) {
5911
- let props = {
5912
- loaderData: useLoaderData(),
5913
- actionData: useActionData(),
5914
- params: useParams()
5915
- };
5916
- return React3.cloneElement(children, props);
5917
- }
5918
- function WithErrorBoundaryProps({
5919
- children
5920
- }) {
5921
- let props = {
5922
- loaderData: useLoaderData(),
5923
- actionData: useActionData(),
5924
- params: useParams(),
5925
- error: useRouteError()
5926
- };
5927
- return React3.cloneElement(children, props);
5928
- }
5929
5863
  function createRoutesFromChildren(children, parentPath = []) {
5930
5864
  let routes = [];
5931
5865
  React3.Children.forEach(children, (element, index) => {
@@ -6248,7 +6182,7 @@ async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
6248
6182
  )
6249
6183
  );
6250
6184
  }
6251
- function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location2, mode) {
6185
+ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
6252
6186
  let isNew = (match, index) => {
6253
6187
  if (!currentMatches[index]) return true;
6254
6188
  return match.route.id !== currentMatches[index].route.id;
@@ -6278,7 +6212,7 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
6278
6212
  if (match.route.shouldRevalidate) {
6279
6213
  let routeChoice = match.route.shouldRevalidate({
6280
6214
  currentUrl: new URL(
6281
- location2.pathname + location2.search + location2.hash,
6215
+ location.pathname + location.search + location.hash,
6282
6216
  window.origin
6283
6217
  ),
6284
6218
  currentParams: currentMatches[0]?.params || {},
@@ -6373,7 +6307,669 @@ function createHtml(html) {
6373
6307
 
6374
6308
  // lib/dom/ssr/single-fetch.tsx
6375
6309
  import * as React4 from "react";
6376
- import { decode } from "turbo-stream";
6310
+
6311
+ // vendor/turbo-stream-v2/utils.ts
6312
+ var HOLE = -1;
6313
+ var NAN = -2;
6314
+ var NEGATIVE_INFINITY = -3;
6315
+ var NEGATIVE_ZERO = -4;
6316
+ var NULL = -5;
6317
+ var POSITIVE_INFINITY = -6;
6318
+ var UNDEFINED = -7;
6319
+ var TYPE_BIGINT = "B";
6320
+ var TYPE_DATE = "D";
6321
+ var TYPE_ERROR = "E";
6322
+ var TYPE_MAP = "M";
6323
+ var TYPE_NULL_OBJECT = "N";
6324
+ var TYPE_PROMISE = "P";
6325
+ var TYPE_REGEXP = "R";
6326
+ var TYPE_SET = "S";
6327
+ var TYPE_SYMBOL = "Y";
6328
+ var TYPE_URL = "U";
6329
+ var TYPE_PREVIOUS_RESOLVED = "Z";
6330
+ var Deferred2 = class {
6331
+ constructor() {
6332
+ this.promise = new Promise((resolve, reject) => {
6333
+ this.resolve = resolve;
6334
+ this.reject = reject;
6335
+ });
6336
+ }
6337
+ };
6338
+ function createLineSplittingTransform() {
6339
+ const decoder = new TextDecoder();
6340
+ let leftover = "";
6341
+ return new TransformStream({
6342
+ transform(chunk, controller) {
6343
+ const str = decoder.decode(chunk, { stream: true });
6344
+ const parts = (leftover + str).split("\n");
6345
+ leftover = parts.pop() || "";
6346
+ for (const part of parts) {
6347
+ controller.enqueue(part);
6348
+ }
6349
+ },
6350
+ flush(controller) {
6351
+ if (leftover) {
6352
+ controller.enqueue(leftover);
6353
+ }
6354
+ }
6355
+ });
6356
+ }
6357
+
6358
+ // vendor/turbo-stream-v2/flatten.ts
6359
+ function flatten(input) {
6360
+ const { indices } = this;
6361
+ const existing = indices.get(input);
6362
+ if (existing) return [existing];
6363
+ if (input === void 0) return UNDEFINED;
6364
+ if (input === null) return NULL;
6365
+ if (Number.isNaN(input)) return NAN;
6366
+ if (input === Number.POSITIVE_INFINITY) return POSITIVE_INFINITY;
6367
+ if (input === Number.NEGATIVE_INFINITY) return NEGATIVE_INFINITY;
6368
+ if (input === 0 && 1 / input < 0) return NEGATIVE_ZERO;
6369
+ const index = this.index++;
6370
+ indices.set(input, index);
6371
+ stringify.call(this, input, index);
6372
+ return index;
6373
+ }
6374
+ function stringify(input, index) {
6375
+ const { deferred, plugins, postPlugins } = this;
6376
+ const str = this.stringified;
6377
+ const stack = [[input, index]];
6378
+ while (stack.length > 0) {
6379
+ const [input2, index2] = stack.pop();
6380
+ const partsForObj = (obj) => Object.keys(obj).map((k) => `"_${flatten.call(this, k)}":${flatten.call(this, obj[k])}`).join(",");
6381
+ let error = null;
6382
+ switch (typeof input2) {
6383
+ case "boolean":
6384
+ case "number":
6385
+ case "string":
6386
+ str[index2] = JSON.stringify(input2);
6387
+ break;
6388
+ case "bigint":
6389
+ str[index2] = `["${TYPE_BIGINT}","${input2}"]`;
6390
+ break;
6391
+ case "symbol": {
6392
+ const keyFor = Symbol.keyFor(input2);
6393
+ if (!keyFor) {
6394
+ error = new Error(
6395
+ "Cannot encode symbol unless created with Symbol.for()"
6396
+ );
6397
+ } else {
6398
+ str[index2] = `["${TYPE_SYMBOL}",${JSON.stringify(keyFor)}]`;
6399
+ }
6400
+ break;
6401
+ }
6402
+ case "object": {
6403
+ if (!input2) {
6404
+ str[index2] = `${NULL}`;
6405
+ break;
6406
+ }
6407
+ const isArray = Array.isArray(input2);
6408
+ let pluginHandled = false;
6409
+ if (!isArray && plugins) {
6410
+ for (const plugin of plugins) {
6411
+ const pluginResult = plugin(input2);
6412
+ if (Array.isArray(pluginResult)) {
6413
+ pluginHandled = true;
6414
+ const [pluginIdentifier, ...rest] = pluginResult;
6415
+ str[index2] = `[${JSON.stringify(pluginIdentifier)}`;
6416
+ if (rest.length > 0) {
6417
+ str[index2] += `,${rest.map((v) => flatten.call(this, v)).join(",")}`;
6418
+ }
6419
+ str[index2] += "]";
6420
+ break;
6421
+ }
6422
+ }
6423
+ }
6424
+ if (!pluginHandled) {
6425
+ let result = isArray ? "[" : "{";
6426
+ if (isArray) {
6427
+ for (let i = 0; i < input2.length; i++)
6428
+ result += (i ? "," : "") + (i in input2 ? flatten.call(this, input2[i]) : HOLE);
6429
+ str[index2] = `${result}]`;
6430
+ } else if (input2 instanceof Date) {
6431
+ str[index2] = `["${TYPE_DATE}",${input2.getTime()}]`;
6432
+ } else if (input2 instanceof URL) {
6433
+ str[index2] = `["${TYPE_URL}",${JSON.stringify(input2.href)}]`;
6434
+ } else if (input2 instanceof RegExp) {
6435
+ str[index2] = `["${TYPE_REGEXP}",${JSON.stringify(
6436
+ input2.source
6437
+ )},${JSON.stringify(input2.flags)}]`;
6438
+ } else if (input2 instanceof Set) {
6439
+ if (input2.size > 0) {
6440
+ str[index2] = `["${TYPE_SET}",${[...input2].map((val) => flatten.call(this, val)).join(",")}]`;
6441
+ } else {
6442
+ str[index2] = `["${TYPE_SET}"]`;
6443
+ }
6444
+ } else if (input2 instanceof Map) {
6445
+ if (input2.size > 0) {
6446
+ str[index2] = `["${TYPE_MAP}",${[...input2].flatMap(([k, v]) => [
6447
+ flatten.call(this, k),
6448
+ flatten.call(this, v)
6449
+ ]).join(",")}]`;
6450
+ } else {
6451
+ str[index2] = `["${TYPE_MAP}"]`;
6452
+ }
6453
+ } else if (input2 instanceof Promise) {
6454
+ str[index2] = `["${TYPE_PROMISE}",${index2}]`;
6455
+ deferred[index2] = input2;
6456
+ } else if (input2 instanceof Error) {
6457
+ str[index2] = `["${TYPE_ERROR}",${JSON.stringify(input2.message)}`;
6458
+ if (input2.name !== "Error") {
6459
+ str[index2] += `,${JSON.stringify(input2.name)}`;
6460
+ }
6461
+ str[index2] += "]";
6462
+ } else if (Object.getPrototypeOf(input2) === null) {
6463
+ str[index2] = `["${TYPE_NULL_OBJECT}",{${partsForObj(input2)}}]`;
6464
+ } else if (isPlainObject(input2)) {
6465
+ str[index2] = `{${partsForObj(input2)}}`;
6466
+ } else {
6467
+ error = new Error("Cannot encode object with prototype");
6468
+ }
6469
+ }
6470
+ break;
6471
+ }
6472
+ default: {
6473
+ const isArray = Array.isArray(input2);
6474
+ let pluginHandled = false;
6475
+ if (!isArray && plugins) {
6476
+ for (const plugin of plugins) {
6477
+ const pluginResult = plugin(input2);
6478
+ if (Array.isArray(pluginResult)) {
6479
+ pluginHandled = true;
6480
+ const [pluginIdentifier, ...rest] = pluginResult;
6481
+ str[index2] = `[${JSON.stringify(pluginIdentifier)}`;
6482
+ if (rest.length > 0) {
6483
+ str[index2] += `,${rest.map((v) => flatten.call(this, v)).join(",")}`;
6484
+ }
6485
+ str[index2] += "]";
6486
+ break;
6487
+ }
6488
+ }
6489
+ }
6490
+ if (!pluginHandled) {
6491
+ error = new Error("Cannot encode function or unexpected type");
6492
+ }
6493
+ }
6494
+ }
6495
+ if (error) {
6496
+ let pluginHandled = false;
6497
+ if (postPlugins) {
6498
+ for (const plugin of postPlugins) {
6499
+ const pluginResult = plugin(input2);
6500
+ if (Array.isArray(pluginResult)) {
6501
+ pluginHandled = true;
6502
+ const [pluginIdentifier, ...rest] = pluginResult;
6503
+ str[index2] = `[${JSON.stringify(pluginIdentifier)}`;
6504
+ if (rest.length > 0) {
6505
+ str[index2] += `,${rest.map((v) => flatten.call(this, v)).join(",")}`;
6506
+ }
6507
+ str[index2] += "]";
6508
+ break;
6509
+ }
6510
+ }
6511
+ }
6512
+ if (!pluginHandled) {
6513
+ throw error;
6514
+ }
6515
+ }
6516
+ }
6517
+ }
6518
+ var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
6519
+ function isPlainObject(thing) {
6520
+ const proto = Object.getPrototypeOf(thing);
6521
+ return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
6522
+ }
6523
+
6524
+ // vendor/turbo-stream-v2/unflatten.ts
6525
+ var globalObj = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : void 0;
6526
+ function unflatten(parsed) {
6527
+ const { hydrated, values } = this;
6528
+ if (typeof parsed === "number") return hydrate.call(this, parsed);
6529
+ if (!Array.isArray(parsed) || !parsed.length) throw new SyntaxError();
6530
+ const startIndex = values.length;
6531
+ for (const value of parsed) {
6532
+ values.push(value);
6533
+ }
6534
+ hydrated.length = values.length;
6535
+ return hydrate.call(this, startIndex);
6536
+ }
6537
+ function hydrate(index) {
6538
+ const { hydrated, values, deferred, plugins } = this;
6539
+ let result;
6540
+ const stack = [
6541
+ [
6542
+ index,
6543
+ (v) => {
6544
+ result = v;
6545
+ }
6546
+ ]
6547
+ ];
6548
+ let postRun = [];
6549
+ while (stack.length > 0) {
6550
+ const [index2, set] = stack.pop();
6551
+ switch (index2) {
6552
+ case UNDEFINED:
6553
+ set(void 0);
6554
+ continue;
6555
+ case NULL:
6556
+ set(null);
6557
+ continue;
6558
+ case NAN:
6559
+ set(NaN);
6560
+ continue;
6561
+ case POSITIVE_INFINITY:
6562
+ set(Infinity);
6563
+ continue;
6564
+ case NEGATIVE_INFINITY:
6565
+ set(-Infinity);
6566
+ continue;
6567
+ case NEGATIVE_ZERO:
6568
+ set(-0);
6569
+ continue;
6570
+ }
6571
+ if (hydrated[index2]) {
6572
+ set(hydrated[index2]);
6573
+ continue;
6574
+ }
6575
+ const value = values[index2];
6576
+ if (!value || typeof value !== "object") {
6577
+ hydrated[index2] = value;
6578
+ set(value);
6579
+ continue;
6580
+ }
6581
+ if (Array.isArray(value)) {
6582
+ if (typeof value[0] === "string") {
6583
+ const [type, b, c] = value;
6584
+ switch (type) {
6585
+ case TYPE_DATE:
6586
+ set(hydrated[index2] = new Date(b));
6587
+ continue;
6588
+ case TYPE_URL:
6589
+ set(hydrated[index2] = new URL(b));
6590
+ continue;
6591
+ case TYPE_BIGINT:
6592
+ set(hydrated[index2] = BigInt(b));
6593
+ continue;
6594
+ case TYPE_REGEXP:
6595
+ set(hydrated[index2] = new RegExp(b, c));
6596
+ continue;
6597
+ case TYPE_SYMBOL:
6598
+ set(hydrated[index2] = Symbol.for(b));
6599
+ continue;
6600
+ case TYPE_SET:
6601
+ const newSet = /* @__PURE__ */ new Set();
6602
+ hydrated[index2] = newSet;
6603
+ for (let i = value.length - 1; i > 0; i--)
6604
+ stack.push([
6605
+ value[i],
6606
+ (v) => {
6607
+ newSet.add(v);
6608
+ }
6609
+ ]);
6610
+ set(newSet);
6611
+ continue;
6612
+ case TYPE_MAP:
6613
+ const map = /* @__PURE__ */ new Map();
6614
+ hydrated[index2] = map;
6615
+ for (let i = value.length - 2; i > 0; i -= 2) {
6616
+ const r = [];
6617
+ stack.push([
6618
+ value[i + 1],
6619
+ (v) => {
6620
+ r[1] = v;
6621
+ }
6622
+ ]);
6623
+ stack.push([
6624
+ value[i],
6625
+ (k) => {
6626
+ r[0] = k;
6627
+ }
6628
+ ]);
6629
+ postRun.push(() => {
6630
+ map.set(r[0], r[1]);
6631
+ });
6632
+ }
6633
+ set(map);
6634
+ continue;
6635
+ case TYPE_NULL_OBJECT:
6636
+ const obj = /* @__PURE__ */ Object.create(null);
6637
+ hydrated[index2] = obj;
6638
+ for (const key of Object.keys(b).reverse()) {
6639
+ const r = [];
6640
+ stack.push([
6641
+ b[key],
6642
+ (v) => {
6643
+ r[1] = v;
6644
+ }
6645
+ ]);
6646
+ stack.push([
6647
+ Number(key.slice(1)),
6648
+ (k) => {
6649
+ r[0] = k;
6650
+ }
6651
+ ]);
6652
+ postRun.push(() => {
6653
+ obj[r[0]] = r[1];
6654
+ });
6655
+ }
6656
+ set(obj);
6657
+ continue;
6658
+ case TYPE_PROMISE:
6659
+ if (hydrated[b]) {
6660
+ set(hydrated[index2] = hydrated[b]);
6661
+ } else {
6662
+ const d = new Deferred2();
6663
+ deferred[b] = d;
6664
+ set(hydrated[index2] = d.promise);
6665
+ }
6666
+ continue;
6667
+ case TYPE_ERROR:
6668
+ const [, message, errorType] = value;
6669
+ let error = errorType && globalObj && globalObj[errorType] ? new globalObj[errorType](message) : new Error(message);
6670
+ hydrated[index2] = error;
6671
+ set(error);
6672
+ continue;
6673
+ case TYPE_PREVIOUS_RESOLVED:
6674
+ set(hydrated[index2] = hydrated[b]);
6675
+ continue;
6676
+ default:
6677
+ if (Array.isArray(plugins)) {
6678
+ const r = [];
6679
+ const vals = value.slice(1);
6680
+ for (let i = 0; i < vals.length; i++) {
6681
+ const v = vals[i];
6682
+ stack.push([
6683
+ v,
6684
+ (v2) => {
6685
+ r[i] = v2;
6686
+ }
6687
+ ]);
6688
+ }
6689
+ postRun.push(() => {
6690
+ for (const plugin of plugins) {
6691
+ const result2 = plugin(value[0], ...r);
6692
+ if (result2) {
6693
+ set(hydrated[index2] = result2.value);
6694
+ return;
6695
+ }
6696
+ }
6697
+ throw new SyntaxError();
6698
+ });
6699
+ continue;
6700
+ }
6701
+ throw new SyntaxError();
6702
+ }
6703
+ } else {
6704
+ const array = [];
6705
+ hydrated[index2] = array;
6706
+ for (let i = 0; i < value.length; i++) {
6707
+ const n = value[i];
6708
+ if (n !== HOLE) {
6709
+ stack.push([
6710
+ n,
6711
+ (v) => {
6712
+ array[i] = v;
6713
+ }
6714
+ ]);
6715
+ }
6716
+ }
6717
+ set(array);
6718
+ continue;
6719
+ }
6720
+ } else {
6721
+ const object = {};
6722
+ hydrated[index2] = object;
6723
+ for (const key of Object.keys(value).reverse()) {
6724
+ const r = [];
6725
+ stack.push([
6726
+ value[key],
6727
+ (v) => {
6728
+ r[1] = v;
6729
+ }
6730
+ ]);
6731
+ stack.push([
6732
+ Number(key.slice(1)),
6733
+ (k) => {
6734
+ r[0] = k;
6735
+ }
6736
+ ]);
6737
+ postRun.push(() => {
6738
+ object[r[0]] = r[1];
6739
+ });
6740
+ }
6741
+ set(object);
6742
+ continue;
6743
+ }
6744
+ }
6745
+ while (postRun.length > 0) {
6746
+ postRun.pop()();
6747
+ }
6748
+ return result;
6749
+ }
6750
+
6751
+ // vendor/turbo-stream-v2/turbo-stream.ts
6752
+ async function decode(readable, options) {
6753
+ const { plugins } = options ?? {};
6754
+ const done = new Deferred2();
6755
+ const reader = readable.pipeThrough(createLineSplittingTransform()).getReader();
6756
+ const decoder = {
6757
+ values: [],
6758
+ hydrated: [],
6759
+ deferred: {},
6760
+ plugins
6761
+ };
6762
+ const decoded = await decodeInitial.call(decoder, reader);
6763
+ let donePromise = done.promise;
6764
+ if (decoded.done) {
6765
+ done.resolve();
6766
+ } else {
6767
+ donePromise = decodeDeferred.call(decoder, reader).then(done.resolve).catch((reason) => {
6768
+ for (const deferred of Object.values(decoder.deferred)) {
6769
+ deferred.reject(reason);
6770
+ }
6771
+ done.reject(reason);
6772
+ });
6773
+ }
6774
+ return {
6775
+ done: donePromise.then(() => reader.closed),
6776
+ value: decoded.value
6777
+ };
6778
+ }
6779
+ async function decodeInitial(reader) {
6780
+ const read = await reader.read();
6781
+ if (!read.value) {
6782
+ throw new SyntaxError();
6783
+ }
6784
+ let line;
6785
+ try {
6786
+ line = JSON.parse(read.value);
6787
+ } catch (reason) {
6788
+ throw new SyntaxError();
6789
+ }
6790
+ return {
6791
+ done: read.done,
6792
+ value: unflatten.call(this, line)
6793
+ };
6794
+ }
6795
+ async function decodeDeferred(reader) {
6796
+ let read = await reader.read();
6797
+ while (!read.done) {
6798
+ if (!read.value) continue;
6799
+ const line = read.value;
6800
+ switch (line[0]) {
6801
+ case TYPE_PROMISE: {
6802
+ const colonIndex = line.indexOf(":");
6803
+ const deferredId = Number(line.slice(1, colonIndex));
6804
+ const deferred = this.deferred[deferredId];
6805
+ if (!deferred) {
6806
+ throw new Error(`Deferred ID ${deferredId} not found in stream`);
6807
+ }
6808
+ const lineData = line.slice(colonIndex + 1);
6809
+ let jsonLine;
6810
+ try {
6811
+ jsonLine = JSON.parse(lineData);
6812
+ } catch (reason) {
6813
+ throw new SyntaxError();
6814
+ }
6815
+ const value = unflatten.call(this, jsonLine);
6816
+ deferred.resolve(value);
6817
+ break;
6818
+ }
6819
+ case TYPE_ERROR: {
6820
+ const colonIndex = line.indexOf(":");
6821
+ const deferredId = Number(line.slice(1, colonIndex));
6822
+ const deferred = this.deferred[deferredId];
6823
+ if (!deferred) {
6824
+ throw new Error(`Deferred ID ${deferredId} not found in stream`);
6825
+ }
6826
+ const lineData = line.slice(colonIndex + 1);
6827
+ let jsonLine;
6828
+ try {
6829
+ jsonLine = JSON.parse(lineData);
6830
+ } catch (reason) {
6831
+ throw new SyntaxError();
6832
+ }
6833
+ const value = unflatten.call(this, jsonLine);
6834
+ deferred.reject(value);
6835
+ break;
6836
+ }
6837
+ default:
6838
+ throw new SyntaxError();
6839
+ }
6840
+ read = await reader.read();
6841
+ }
6842
+ }
6843
+ function encode(input, options) {
6844
+ const { plugins, postPlugins, signal } = options ?? {};
6845
+ const encoder2 = {
6846
+ deferred: {},
6847
+ index: 0,
6848
+ indices: /* @__PURE__ */ new Map(),
6849
+ stringified: [],
6850
+ plugins,
6851
+ postPlugins,
6852
+ signal
6853
+ };
6854
+ const textEncoder = new TextEncoder();
6855
+ let lastSentIndex = 0;
6856
+ const readable = new ReadableStream({
6857
+ async start(controller) {
6858
+ const id = flatten.call(encoder2, input);
6859
+ if (Array.isArray(id)) {
6860
+ throw new Error("This should never happen");
6861
+ }
6862
+ if (id < 0) {
6863
+ controller.enqueue(textEncoder.encode(`${id}
6864
+ `));
6865
+ } else {
6866
+ controller.enqueue(
6867
+ textEncoder.encode(`[${encoder2.stringified.join(",")}]
6868
+ `)
6869
+ );
6870
+ lastSentIndex = encoder2.stringified.length - 1;
6871
+ }
6872
+ const seenPromises = /* @__PURE__ */ new WeakSet();
6873
+ if (Object.keys(encoder2.deferred).length) {
6874
+ let raceDone;
6875
+ const racePromise = new Promise((resolve, reject) => {
6876
+ raceDone = resolve;
6877
+ if (signal) {
6878
+ const rejectPromise = () => reject(signal.reason || new Error("Signal was aborted."));
6879
+ if (signal.aborted) {
6880
+ rejectPromise();
6881
+ } else {
6882
+ signal.addEventListener("abort", (event) => {
6883
+ rejectPromise();
6884
+ });
6885
+ }
6886
+ }
6887
+ });
6888
+ while (Object.keys(encoder2.deferred).length > 0) {
6889
+ for (const [deferredId, deferred] of Object.entries(
6890
+ encoder2.deferred
6891
+ )) {
6892
+ if (seenPromises.has(deferred)) continue;
6893
+ seenPromises.add(
6894
+ // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
6895
+ encoder2.deferred[Number(deferredId)] = Promise.race([
6896
+ racePromise,
6897
+ deferred
6898
+ ]).then(
6899
+ (resolved) => {
6900
+ const id2 = flatten.call(encoder2, resolved);
6901
+ if (Array.isArray(id2)) {
6902
+ controller.enqueue(
6903
+ textEncoder.encode(
6904
+ `${TYPE_PROMISE}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
6905
+ `
6906
+ )
6907
+ );
6908
+ encoder2.index++;
6909
+ lastSentIndex++;
6910
+ } else if (id2 < 0) {
6911
+ controller.enqueue(
6912
+ textEncoder.encode(
6913
+ `${TYPE_PROMISE}${deferredId}:${id2}
6914
+ `
6915
+ )
6916
+ );
6917
+ } else {
6918
+ const values = encoder2.stringified.slice(lastSentIndex + 1).join(",");
6919
+ controller.enqueue(
6920
+ textEncoder.encode(
6921
+ `${TYPE_PROMISE}${deferredId}:[${values}]
6922
+ `
6923
+ )
6924
+ );
6925
+ lastSentIndex = encoder2.stringified.length - 1;
6926
+ }
6927
+ },
6928
+ (reason) => {
6929
+ if (!reason || typeof reason !== "object" || !(reason instanceof Error)) {
6930
+ reason = new Error("An unknown error occurred");
6931
+ }
6932
+ const id2 = flatten.call(encoder2, reason);
6933
+ if (Array.isArray(id2)) {
6934
+ controller.enqueue(
6935
+ textEncoder.encode(
6936
+ `${TYPE_ERROR}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
6937
+ `
6938
+ )
6939
+ );
6940
+ encoder2.index++;
6941
+ lastSentIndex++;
6942
+ } else if (id2 < 0) {
6943
+ controller.enqueue(
6944
+ textEncoder.encode(`${TYPE_ERROR}${deferredId}:${id2}
6945
+ `)
6946
+ );
6947
+ } else {
6948
+ const values = encoder2.stringified.slice(lastSentIndex + 1).join(",");
6949
+ controller.enqueue(
6950
+ textEncoder.encode(
6951
+ `${TYPE_ERROR}${deferredId}:[${values}]
6952
+ `
6953
+ )
6954
+ );
6955
+ lastSentIndex = encoder2.stringified.length - 1;
6956
+ }
6957
+ }
6958
+ ).finally(() => {
6959
+ delete encoder2.deferred[Number(deferredId)];
6960
+ })
6961
+ );
6962
+ }
6963
+ await Promise.race(Object.values(encoder2.deferred));
6964
+ }
6965
+ raceDone();
6966
+ }
6967
+ await Promise.all(Object.values(encoder2.deferred));
6968
+ controller.close();
6969
+ }
6970
+ });
6971
+ return readable;
6972
+ }
6377
6973
 
6378
6974
  // lib/dom/ssr/data.ts
6379
6975
  async function createRequestInit(request) {
@@ -6398,6 +6994,9 @@ async function createRequestInit(request) {
6398
6994
 
6399
6995
  // lib/dom/ssr/single-fetch.tsx
6400
6996
  var SingleFetchRedirectSymbol = Symbol("SingleFetchRedirect");
6997
+ var SingleFetchNoResultError = class extends Error {
6998
+ };
6999
+ var SINGLE_FETCH_REDIRECT_STATUS = 202;
6401
7000
  var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205]);
6402
7001
  function StreamTransfer({
6403
7002
  context,
@@ -6525,7 +7124,7 @@ async function singleFetchActionStrategy(args, fetchAndDecode, basename) {
6525
7124
  });
6526
7125
  return result2;
6527
7126
  });
6528
- if (isResponse(result.result) || isRouteErrorResponse(result.result)) {
7127
+ if (isResponse(result.result) || isRouteErrorResponse(result.result) || isDataWithResponseInit(result.result)) {
6529
7128
  return { [actionMatch.route.id]: result };
6530
7129
  }
6531
7130
  return {
@@ -6610,7 +7209,8 @@ async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, f
6610
7209
  )
6611
7210
  );
6612
7211
  await Promise.all(routeDfds.map((d) => d.promise));
6613
- if ((!router.state.initialized || routesParams.size === 0) && !window.__reactRouterHdrActive) {
7212
+ let isInitialLoad = !router.state.initialized && router.state.navigation.state === "idle";
7213
+ if ((isInitialLoad || routesParams.size === 0) && !window.__reactRouterHdrActive) {
6614
7214
  singleFetchDfd.resolve({ routes: {} });
6615
7215
  } else {
6616
7216
  let targetRoutes = ssr && foundOptOutRoute && routesParams.size > 0 ? [...routesParams.keys()] : void 0;
@@ -6622,18 +7222,49 @@ async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, f
6622
7222
  }
6623
7223
  }
6624
7224
  await resolvePromise;
7225
+ await bubbleMiddlewareErrors(
7226
+ singleFetchDfd.promise,
7227
+ args.matches,
7228
+ routesParams,
7229
+ results
7230
+ );
6625
7231
  return results;
6626
7232
  }
6627
- async function singleFetchLoaderFetcherStrategy(args, fetchAndDecode, basename) {
6628
- let fetcherMatch = args.matches.find((m) => m.unstable_shouldCallHandler());
6629
- invariant2(fetcherMatch, "No fetcher match found");
6630
- let routeId = fetcherMatch.route.id;
6631
- let result = await fetcherMatch.resolve(
6632
- async (handler) => handler(async () => {
6633
- let { data: data2 } = await fetchAndDecode(args, basename, [routeId]);
6634
- return unwrapSingleFetchResult(data2, routeId);
6635
- })
6636
- );
7233
+ async function bubbleMiddlewareErrors(singleFetchPromise, matches, routesParams, results) {
7234
+ try {
7235
+ let middlewareError;
7236
+ let fetchedData = await singleFetchPromise;
7237
+ if ("routes" in fetchedData) {
7238
+ for (let match of matches) {
7239
+ if (match.route.id in fetchedData.routes) {
7240
+ let routeResult = fetchedData.routes[match.route.id];
7241
+ if ("error" in routeResult) {
7242
+ middlewareError = routeResult.error;
7243
+ break;
7244
+ }
7245
+ }
7246
+ }
7247
+ }
7248
+ if (middlewareError !== void 0) {
7249
+ Array.from(routesParams.values()).forEach((routeId) => {
7250
+ if (results[routeId].result instanceof SingleFetchNoResultError) {
7251
+ results[routeId].result = middlewareError;
7252
+ }
7253
+ });
7254
+ }
7255
+ } catch (e) {
7256
+ }
7257
+ }
7258
+ async function singleFetchLoaderFetcherStrategy(args, fetchAndDecode, basename) {
7259
+ let fetcherMatch = args.matches.find((m) => m.unstable_shouldCallHandler());
7260
+ invariant2(fetcherMatch, "No fetcher match found");
7261
+ let routeId = fetcherMatch.route.id;
7262
+ let result = await fetcherMatch.resolve(
7263
+ async (handler) => handler(async () => {
7264
+ let { data: data2 } = await fetchAndDecode(args, basename, [routeId]);
7265
+ return unwrapSingleFetchResult(data2, routeId);
7266
+ })
7267
+ );
6637
7268
  return { [fetcherMatch.route.id]: result };
6638
7269
  }
6639
7270
  function stripIndexParam(url) {
@@ -6650,7 +7281,7 @@ function stripIndexParam(url) {
6650
7281
  }
6651
7282
  return url;
6652
7283
  }
6653
- function singleFetchUrl(reqUrl, basename, extension) {
7284
+ function singleFetchUrl(reqUrl, basename) {
6654
7285
  let url = typeof reqUrl === "string" ? new URL(
6655
7286
  reqUrl,
6656
7287
  // This can be called during the SSR flow via PrefetchPageLinksImpl so
@@ -6658,17 +7289,17 @@ function singleFetchUrl(reqUrl, basename, extension) {
6658
7289
  typeof window === "undefined" ? "server://singlefetch/" : window.location.origin
6659
7290
  ) : reqUrl;
6660
7291
  if (url.pathname === "/") {
6661
- url.pathname = `_root.${extension}`;
7292
+ url.pathname = "_root.data";
6662
7293
  } else if (basename && stripBasename(url.pathname, basename) === "/") {
6663
- url.pathname = `${basename.replace(/\/$/, "")}/_root.${extension}`;
7294
+ url.pathname = `${basename.replace(/\/$/, "")}/_root.data`;
6664
7295
  } else {
6665
- url.pathname = `${url.pathname.replace(/\/$/, "")}.${extension}`;
7296
+ url.pathname = `${url.pathname.replace(/\/$/, "")}.data`;
6666
7297
  }
6667
7298
  return url;
6668
7299
  }
6669
7300
  async function fetchAndDecodeViaTurboStream(args, basename, targetRoutes) {
6670
7301
  let { request } = args;
6671
- let url = singleFetchUrl(request.url, basename, "data");
7302
+ let url = singleFetchUrl(request.url, basename);
6672
7303
  if (request.method === "GET") {
6673
7304
  url = stripIndexParam(url);
6674
7305
  if (targetRoutes) {
@@ -6679,6 +7310,20 @@ async function fetchAndDecodeViaTurboStream(args, basename, targetRoutes) {
6679
7310
  if (res.status === 404 && !res.headers.has("X-Remix-Response")) {
6680
7311
  throw new ErrorResponseImpl(404, "Not Found", true);
6681
7312
  }
7313
+ if (res.status === 204 && res.headers.has("X-Remix-Redirect")) {
7314
+ return {
7315
+ status: SINGLE_FETCH_REDIRECT_STATUS,
7316
+ data: {
7317
+ redirect: {
7318
+ redirect: res.headers.get("X-Remix-Redirect"),
7319
+ status: Number(res.headers.get("X-Remix-Status") || "302"),
7320
+ revalidate: res.headers.get("X-Remix-Revalidate") === "true",
7321
+ reload: res.headers.get("X-Remix-Reload-Document") === "true",
7322
+ replace: res.headers.get("X-Remix-Replace") === "true"
7323
+ }
7324
+ }
7325
+ };
7326
+ }
6682
7327
  if (NO_BODY_STATUS_CODES.has(res.status)) {
6683
7328
  let routes = {};
6684
7329
  if (targetRoutes && request.method !== "GET") {
@@ -6751,13 +7396,13 @@ function decodeViaTurboStream(body, global2) {
6751
7396
  function unwrapSingleFetchResult(result, routeId) {
6752
7397
  if ("redirect" in result) {
6753
7398
  let {
6754
- redirect: location2,
7399
+ redirect: location,
6755
7400
  revalidate,
6756
7401
  reload,
6757
7402
  replace: replace2,
6758
7403
  status
6759
7404
  } = result.redirect;
6760
- throw redirect(location2, {
7405
+ throw redirect(location, {
6761
7406
  status,
6762
7407
  headers: {
6763
7408
  // Three R's of redirecting (lol Veep)
@@ -6768,8 +7413,11 @@ function unwrapSingleFetchResult(result, routeId) {
6768
7413
  });
6769
7414
  }
6770
7415
  let routeResult = result.routes[routeId];
6771
- invariant2(routeResult, `No response found for routeId "${routeId}"`);
6772
- if ("error" in routeResult) {
7416
+ if (routeResult == null) {
7417
+ throw new SingleFetchNoResultError(
7418
+ `No result found for routeId "${routeId}"`
7419
+ );
7420
+ } else if ("error" in routeResult) {
6773
7421
  throw routeResult.error;
6774
7422
  } else if ("data" in routeResult) {
6775
7423
  return routeResult.data;
@@ -6852,14 +7500,14 @@ function RemixRootDefaultErrorBoundary({
6852
7500
  dangerouslySetInnerHTML: {
6853
7501
  __html: `
6854
7502
  console.log(
6855
- "\u{1F4BF} Hey developer \u{1F44B}. You can provide a way better UX than this when your app throws errors. Check out https://remix.run/guides/errors for more information."
7503
+ "\u{1F4BF} Hey developer \u{1F44B}. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
6856
7504
  );
6857
7505
  `
6858
7506
  }
6859
7507
  }
6860
7508
  );
6861
7509
  if (isRouteErrorResponse(error)) {
6862
- return /* @__PURE__ */ React5.createElement(BoundaryShell, { title: "Unhandled Thrown Response!" }, /* @__PURE__ */ React5.createElement("h1", { style: { fontSize: "24px" } }, error.status, " ", error.statusText), heyDeveloper);
7510
+ return /* @__PURE__ */ React5.createElement(BoundaryShell, { title: "Unhandled Thrown Response!" }, /* @__PURE__ */ React5.createElement("h1", { style: { fontSize: "24px" } }, error.status, " ", error.statusText), ENABLE_DEV_WARNINGS ? heyDeveloper : null);
6863
7511
  }
6864
7512
  let errorInstance;
6865
7513
  if (error instanceof Error) {
@@ -6912,7 +7560,7 @@ function BoundaryShell({
6912
7560
  // lib/dom/ssr/fallback.tsx
6913
7561
  import * as React6 from "react";
6914
7562
  function RemixRootDefaultHydrateFallback() {
6915
- return /* @__PURE__ */ React6.createElement(BoundaryShell, { title: "Loading...", renderScripts: true }, /* @__PURE__ */ React6.createElement(
7563
+ return /* @__PURE__ */ React6.createElement(BoundaryShell, { title: "Loading...", renderScripts: true }, ENABLE_DEV_WARNINGS ? /* @__PURE__ */ React6.createElement(
6916
7564
  "script",
6917
7565
  {
6918
7566
  dangerouslySetInnerHTML: {
@@ -6920,13 +7568,13 @@ function RemixRootDefaultHydrateFallback() {
6920
7568
  console.log(
6921
7569
  "\u{1F4BF} Hey developer \u{1F44B}. You can provide a way better UX than this " +
6922
7570
  "when your app is loading JS modules and/or running \`clientLoader\` " +
6923
- "functions. Check out https://remix.run/route/hydrate-fallback " +
7571
+ "functions. Check out https://reactrouter.com/start/framework/route-module#hydratefallback " +
6924
7572
  "for more information."
6925
7573
  );
6926
7574
  `
6927
7575
  }
6928
7576
  }
6929
- ));
7577
+ ) : null);
6930
7578
  }
6931
7579
 
6932
7580
  // lib/dom/ssr/routes.tsx
@@ -7339,8 +7987,8 @@ var nextPaths = /* @__PURE__ */ new Set();
7339
7987
  var discoveredPathsMaxSize = 1e3;
7340
7988
  var discoveredPaths = /* @__PURE__ */ new Set();
7341
7989
  var URL_LIMIT = 7680;
7342
- function isFogOfWarEnabled(ssr) {
7343
- return ssr === true;
7990
+ function isFogOfWarEnabled(routeDiscovery, ssr) {
7991
+ return routeDiscovery.mode === "lazy" && ssr === true;
7344
7992
  }
7345
7993
  function getPartialManifest({ sri, ...manifest }, router) {
7346
7994
  let routeIds = new Set(router.state.matches.map((m) => m.route.id));
@@ -7367,8 +8015,8 @@ function getPartialManifest({ sri, ...manifest }, router) {
7367
8015
  sri: sri ? true : void 0
7368
8016
  };
7369
8017
  }
7370
- function getPatchRoutesOnNavigationFunction(manifest, routeModules, ssr, isSpaMode, basename) {
7371
- if (!isFogOfWarEnabled(ssr)) {
8018
+ function getPatchRoutesOnNavigationFunction(manifest, routeModules, ssr, routeDiscovery, isSpaMode, basename) {
8019
+ if (!isFogOfWarEnabled(routeDiscovery, ssr)) {
7372
8020
  return void 0;
7373
8021
  }
7374
8022
  return async ({ path, patch, signal, fetcherKey }) => {
@@ -7383,14 +8031,16 @@ function getPatchRoutesOnNavigationFunction(manifest, routeModules, ssr, isSpaMo
7383
8031
  ssr,
7384
8032
  isSpaMode,
7385
8033
  basename,
8034
+ routeDiscovery.manifestPath,
7386
8035
  patch,
7387
8036
  signal
7388
8037
  );
7389
8038
  };
7390
8039
  }
7391
- function useFogOFWarDiscovery(router, manifest, routeModules, ssr, isSpaMode) {
8040
+ function useFogOFWarDiscovery(router, manifest, routeModules, ssr, routeDiscovery, isSpaMode) {
7392
8041
  React8.useEffect(() => {
7393
- if (!isFogOfWarEnabled(ssr) || navigator.connection?.saveData === true) {
8042
+ if (!isFogOfWarEnabled(routeDiscovery, ssr) || // @ts-expect-error - TS doesn't know about this yet
8043
+ window.navigator?.connection?.saveData === true) {
7394
8044
  return;
7395
8045
  }
7396
8046
  function registerElement(el) {
@@ -7424,6 +8074,7 @@ function useFogOFWarDiscovery(router, manifest, routeModules, ssr, isSpaMode) {
7424
8074
  ssr,
7425
8075
  isSpaMode,
7426
8076
  router.basename,
8077
+ routeDiscovery.manifestPath,
7427
8078
  router.patchRoutes
7428
8079
  );
7429
8080
  } catch (e) {
@@ -7440,15 +8091,21 @@ function useFogOFWarDiscovery(router, manifest, routeModules, ssr, isSpaMode) {
7440
8091
  attributeFilter: ["data-discover", "href", "action"]
7441
8092
  });
7442
8093
  return () => observer.disconnect();
7443
- }, [ssr, isSpaMode, manifest, routeModules, router]);
8094
+ }, [ssr, isSpaMode, manifest, routeModules, router, routeDiscovery]);
8095
+ }
8096
+ function getManifestPath(_manifestPath, basename) {
8097
+ let manifestPath = _manifestPath || "/__manifest";
8098
+ if (basename == null) {
8099
+ return manifestPath;
8100
+ }
8101
+ return `${basename}${manifestPath}`.replace(/\/+/g, "/");
7444
8102
  }
7445
8103
  var MANIFEST_VERSION_STORAGE_KEY = "react-router-manifest-version";
7446
- async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, patchRoutes, signal) {
7447
- let manifestPath = `${basename != null ? basename : "/"}/__manifest`.replace(
7448
- /\/+/g,
7449
- "/"
8104
+ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, routeModules, ssr, isSpaMode, basename, manifestPath, patchRoutes, signal) {
8105
+ let url = new URL(
8106
+ getManifestPath(manifestPath, basename),
8107
+ window.location.origin
7450
8108
  );
7451
- let url = new URL(manifestPath, window.location.origin);
7452
8109
  paths.sort().forEach((path) => url.searchParams.append("p", path));
7453
8110
  url.searchParams.set("version", manifest.version);
7454
8111
  if (url.toString().length > URL_LIMIT) {
@@ -7475,7 +8132,9 @@ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, ro
7475
8132
  }
7476
8133
  sessionStorage.setItem(MANIFEST_VERSION_STORAGE_KEY, manifest.version);
7477
8134
  window.location.href = errorReloadPath;
7478
- throw new Error("Detected manifest version mismatch, reloading...");
8135
+ console.warn("Detected manifest version mismatch, reloading...");
8136
+ await new Promise(() => {
8137
+ });
7479
8138
  } else if (res.status >= 400) {
7480
8139
  throw new Error(await res.text());
7481
8140
  }
@@ -7674,7 +8333,7 @@ function PrefetchPageLinksImpl({
7674
8333
  matches: nextMatches,
7675
8334
  ...linkProps
7676
8335
  }) {
7677
- let location2 = useLocation();
8336
+ let location = useLocation();
7678
8337
  let { manifest, routeModules } = useFrameworkContext();
7679
8338
  let { basename } = useDataRouterContext2();
7680
8339
  let { loaderData, matches } = useDataRouterStateContext();
@@ -7684,10 +8343,10 @@ function PrefetchPageLinksImpl({
7684
8343
  nextMatches,
7685
8344
  matches,
7686
8345
  manifest,
7687
- location2,
8346
+ location,
7688
8347
  "data"
7689
8348
  ),
7690
- [page, nextMatches, matches, manifest, location2]
8349
+ [page, nextMatches, matches, manifest, location]
7691
8350
  );
7692
8351
  let newMatchesForAssets = React9.useMemo(
7693
8352
  () => getNewMatchesForLinks(
@@ -7695,13 +8354,13 @@ function PrefetchPageLinksImpl({
7695
8354
  nextMatches,
7696
8355
  matches,
7697
8356
  manifest,
7698
- location2,
8357
+ location,
7699
8358
  "assets"
7700
8359
  ),
7701
- [page, nextMatches, matches, manifest, location2]
8360
+ [page, nextMatches, matches, manifest, location]
7702
8361
  );
7703
8362
  let dataHrefs = React9.useMemo(() => {
7704
- if (page === location2.pathname + location2.search + location2.hash) {
8363
+ if (page === location.pathname + location.search + location.hash) {
7705
8364
  return [];
7706
8365
  }
7707
8366
  let routesParams = /* @__PURE__ */ new Set();
@@ -7722,7 +8381,7 @@ function PrefetchPageLinksImpl({
7722
8381
  if (routesParams.size === 0) {
7723
8382
  return [];
7724
8383
  }
7725
- let url = singleFetchUrl(page, basename, "data");
8384
+ let url = singleFetchUrl(page, basename);
7726
8385
  if (foundOptOutRoute && routesParams.size > 0) {
7727
8386
  url.searchParams.set(
7728
8387
  "_routes",
@@ -7733,7 +8392,7 @@ function PrefetchPageLinksImpl({
7733
8392
  }, [
7734
8393
  basename,
7735
8394
  loaderData,
7736
- location2,
8395
+ location,
7737
8396
  manifest,
7738
8397
  newMatchesForData,
7739
8398
  nextMatches,
@@ -7758,7 +8417,7 @@ function Meta() {
7758
8417
  matches: routerMatches,
7759
8418
  loaderData
7760
8419
  } = useDataRouterStateContext();
7761
- let location2 = useLocation();
8420
+ let location = useLocation();
7762
8421
  let _matches = getActiveMatches(routerMatches, errors, isSpaMode);
7763
8422
  let error = null;
7764
8423
  if (errors) {
@@ -7788,7 +8447,7 @@ function Meta() {
7788
8447
  routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
7789
8448
  data: data2,
7790
8449
  params,
7791
- location: location2,
8450
+ location,
7792
8451
  matches,
7793
8452
  error
7794
8453
  }) : Array.isArray(routeModule.meta) ? [...routeModule.meta] : routeModule.meta;
@@ -7854,10 +8513,17 @@ function isValidMetaTag(tagName) {
7854
8513
  }
7855
8514
  var isHydrated = false;
7856
8515
  function Scripts(props) {
7857
- let { manifest, serverHandoffString, isSpaMode, ssr, renderMeta } = useFrameworkContext();
8516
+ let {
8517
+ manifest,
8518
+ serverHandoffString,
8519
+ isSpaMode,
8520
+ renderMeta,
8521
+ routeDiscovery,
8522
+ ssr
8523
+ } = useFrameworkContext();
7858
8524
  let { router, static: isStatic, staticContext } = useDataRouterContext2();
7859
8525
  let { matches: routerMatches } = useDataRouterStateContext();
7860
- let enableFogOfWar = isFogOfWarEnabled(ssr);
8526
+ let enableFogOfWar = isFogOfWarEnabled(routeDiscovery, ssr);
7861
8527
  if (renderMeta) {
7862
8528
  renderMeta.didRenderScripts = true;
7863
8529
  }
@@ -8013,7 +8679,7 @@ function mergeRefs(...refs) {
8013
8679
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
8014
8680
  try {
8015
8681
  if (isBrowser) {
8016
- window.__reactRouterVersion = "0.0.0-experimental-e988dc602";
8682
+ window.__reactRouterVersion = "0.0.0-experimental-00e730ed0";
8017
8683
  }
8018
8684
  } catch (e) {
8019
8685
  }
@@ -8271,14 +8937,14 @@ var NavLink = React10.forwardRef(
8271
8937
  ...rest
8272
8938
  }, ref) {
8273
8939
  let path = useResolvedPath(to, { relative: rest.relative });
8274
- let location2 = useLocation();
8940
+ let location = useLocation();
8275
8941
  let routerState = React10.useContext(DataRouterStateContext);
8276
- let { navigator: navigator2, basename } = React10.useContext(NavigationContext);
8942
+ let { navigator, basename } = React10.useContext(NavigationContext);
8277
8943
  let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
8278
8944
  // eslint-disable-next-line react-hooks/rules-of-hooks
8279
8945
  useViewTransitionState(path) && viewTransition === true;
8280
- let toPathname = navigator2.encodeLocation ? navigator2.encodeLocation(path).pathname : path.pathname;
8281
- let locationPathname = location2.pathname;
8946
+ let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
8947
+ let locationPathname = location.pathname;
8282
8948
  let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
8283
8949
  if (!caseSensitive) {
8284
8950
  locationPathname = locationPathname.toLowerCase();
@@ -8383,19 +9049,19 @@ function ScrollRestoration({
8383
9049
  }) {
8384
9050
  let remixContext = React10.useContext(FrameworkContext);
8385
9051
  let { basename } = React10.useContext(NavigationContext);
8386
- let location2 = useLocation();
9052
+ let location = useLocation();
8387
9053
  let matches = useMatches();
8388
9054
  useScrollRestoration({ getKey, storageKey });
8389
9055
  let ssrKey = React10.useMemo(
8390
9056
  () => {
8391
9057
  if (!remixContext || !getKey) return null;
8392
9058
  let userKey = getScrollRestorationKey(
8393
- location2,
9059
+ location,
8394
9060
  matches,
8395
9061
  basename,
8396
9062
  getKey
8397
9063
  );
8398
- return userKey !== location2.key ? userKey : null;
9064
+ return userKey !== location.key ? userKey : null;
8399
9065
  },
8400
9066
  // Nah, we only need this the first time for the SSR render
8401
9067
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -8456,13 +9122,13 @@ function useLinkClickHandler(to, {
8456
9122
  viewTransition
8457
9123
  } = {}) {
8458
9124
  let navigate = useNavigate();
8459
- let location2 = useLocation();
9125
+ let location = useLocation();
8460
9126
  let path = useResolvedPath(to, { relative });
8461
9127
  return React10.useCallback(
8462
9128
  (event) => {
8463
9129
  if (shouldProcessLinkClick(event, target)) {
8464
9130
  event.preventDefault();
8465
- let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location2) === createPath(path);
9131
+ let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
8466
9132
  navigate(to, {
8467
9133
  replace: replace2,
8468
9134
  state,
@@ -8473,7 +9139,7 @@ function useLinkClickHandler(to, {
8473
9139
  }
8474
9140
  },
8475
9141
  [
8476
- location2,
9142
+ location,
8477
9143
  navigate,
8478
9144
  path,
8479
9145
  replaceProp,
@@ -8493,18 +9159,18 @@ function useSearchParams(defaultInit) {
8493
9159
  );
8494
9160
  let defaultSearchParamsRef = React10.useRef(createSearchParams(defaultInit));
8495
9161
  let hasSetSearchParamsRef = React10.useRef(false);
8496
- let location2 = useLocation();
9162
+ let location = useLocation();
8497
9163
  let searchParams = React10.useMemo(
8498
9164
  () => (
8499
9165
  // Only merge in the defaults if we haven't yet called setSearchParams.
8500
9166
  // Once we call that we want those to take precedence, otherwise you can't
8501
9167
  // remove a param with setSearchParams({}) if it has an initial value
8502
9168
  getSearchParamsForLocation(
8503
- location2.search,
9169
+ location.search,
8504
9170
  hasSetSearchParamsRef.current ? null : defaultSearchParamsRef.current
8505
9171
  )
8506
9172
  ),
8507
- [location2.search]
9173
+ [location.search]
8508
9174
  );
8509
9175
  let navigate = useNavigate();
8510
9176
  let setSearchParams = React10.useCallback(
@@ -8565,9 +9231,9 @@ function useFormAction(action, { relative } = {}) {
8565
9231
  invariant(routeContext, "useFormAction must be used inside a RouteContext");
8566
9232
  let [match] = routeContext.matches.slice(-1);
8567
9233
  let path = { ...useResolvedPath(action ? action : ".", { relative }) };
8568
- let location2 = useLocation();
9234
+ let location = useLocation();
8569
9235
  if (action == null) {
8570
- path.search = location2.search;
9236
+ path.search = location.search;
8571
9237
  let params = new URLSearchParams(path.search);
8572
9238
  let indexValues = params.getAll("index");
8573
9239
  let hasNakedIndexParam = indexValues.some((v) => v === "");
@@ -8659,23 +9325,23 @@ function useFetchers() {
8659
9325
  }
8660
9326
  var SCROLL_RESTORATION_STORAGE_KEY = "react-router-scroll-positions";
8661
9327
  var savedScrollPositions = {};
8662
- function getScrollRestorationKey(location2, matches, basename, getKey) {
9328
+ function getScrollRestorationKey(location, matches, basename, getKey) {
8663
9329
  let key = null;
8664
9330
  if (getKey) {
8665
9331
  if (basename !== "/") {
8666
9332
  key = getKey(
8667
9333
  {
8668
- ...location2,
8669
- pathname: stripBasename(location2.pathname, basename) || location2.pathname
9334
+ ...location,
9335
+ pathname: stripBasename(location.pathname, basename) || location.pathname
8670
9336
  },
8671
9337
  matches
8672
9338
  );
8673
9339
  } else {
8674
- key = getKey(location2, matches);
9340
+ key = getKey(location, matches);
8675
9341
  }
8676
9342
  }
8677
9343
  if (key == null) {
8678
- key = location2.key;
9344
+ key = location.key;
8679
9345
  }
8680
9346
  return key;
8681
9347
  }
@@ -8688,7 +9354,7 @@ function useScrollRestoration({
8688
9354
  "useScrollRestoration" /* UseScrollRestoration */
8689
9355
  );
8690
9356
  let { basename } = React10.useContext(NavigationContext);
8691
- let location2 = useLocation();
9357
+ let location = useLocation();
8692
9358
  let matches = useMatches();
8693
9359
  let navigation = useNavigation();
8694
9360
  React10.useEffect(() => {
@@ -8700,7 +9366,7 @@ function useScrollRestoration({
8700
9366
  usePageHide(
8701
9367
  React10.useCallback(() => {
8702
9368
  if (navigation.state === "idle") {
8703
- let key = getScrollRestorationKey(location2, matches, basename, getKey);
9369
+ let key = getScrollRestorationKey(location, matches, basename, getKey);
8704
9370
  savedScrollPositions[key] = window.scrollY;
8705
9371
  }
8706
9372
  try {
@@ -8715,7 +9381,7 @@ function useScrollRestoration({
8715
9381
  );
8716
9382
  }
8717
9383
  window.history.scrollRestoration = "auto";
8718
- }, [navigation.state, getKey, basename, location2, matches, storageKey])
9384
+ }, [navigation.state, getKey, basename, location, matches, storageKey])
8719
9385
  );
8720
9386
  if (typeof document !== "undefined") {
8721
9387
  React10.useLayoutEffect(() => {
@@ -8733,7 +9399,7 @@ function useScrollRestoration({
8733
9399
  let disableScrollRestoration = router?.enableScrollRestoration(
8734
9400
  savedScrollPositions,
8735
9401
  () => window.scrollY,
8736
- getKey ? (location3, matches2) => getScrollRestorationKey(location3, matches2, basename, getKey) : void 0
9402
+ getKey ? (location2, matches2) => getScrollRestorationKey(location2, matches2, basename, getKey) : void 0
8737
9403
  );
8738
9404
  return () => disableScrollRestoration && disableScrollRestoration();
8739
9405
  }, [router, basename, getKey]);
@@ -8745,9 +9411,9 @@ function useScrollRestoration({
8745
9411
  window.scrollTo(0, restoreScrollPosition);
8746
9412
  return;
8747
9413
  }
8748
- if (location2.hash) {
9414
+ if (location.hash) {
8749
9415
  let el = document.getElementById(
8750
- decodeURIComponent(location2.hash.slice(1))
9416
+ decodeURIComponent(location.hash.slice(1))
8751
9417
  );
8752
9418
  if (el) {
8753
9419
  el.scrollIntoView();
@@ -8758,7 +9424,7 @@ function useScrollRestoration({
8758
9424
  return;
8759
9425
  }
8760
9426
  window.scrollTo(0, 0);
8761
- }, [location2, restoreScrollPosition, preventScrollReset]);
9427
+ }, [location, restoreScrollPosition, preventScrollReset]);
8762
9428
  }
8763
9429
  }
8764
9430
  function useBeforeUnload(callback, options) {
@@ -8831,7 +9497,7 @@ function StaticRouter({
8831
9497
  locationProp = parsePath(locationProp);
8832
9498
  }
8833
9499
  let action = "POP" /* Pop */;
8834
- let location2 = {
9500
+ let location = {
8835
9501
  pathname: locationProp.pathname || "/",
8836
9502
  search: locationProp.search || "",
8837
9503
  hash: locationProp.hash || "",
@@ -8844,7 +9510,7 @@ function StaticRouter({
8844
9510
  {
8845
9511
  basename,
8846
9512
  children,
8847
- location: location2,
9513
+ location,
8848
9514
  navigationType: action,
8849
9515
  navigator: staticNavigator,
8850
9516
  static: true
@@ -8854,7 +9520,7 @@ function StaticRouter({
8854
9520
  function StaticRouterProvider({
8855
9521
  context,
8856
9522
  router,
8857
- hydrate = true,
9523
+ hydrate: hydrate2 = true,
8858
9524
  nonce
8859
9525
  }) {
8860
9526
  invariant(
@@ -8870,7 +9536,7 @@ function StaticRouterProvider({
8870
9536
  };
8871
9537
  let fetchersContext = /* @__PURE__ */ new Map();
8872
9538
  let hydrateScript = "";
8873
- if (hydrate !== false) {
9539
+ if (hydrate2 !== false) {
8874
9540
  let data2 = {
8875
9541
  loaderData: context.loaderData,
8876
9542
  actionData: context.actionData,
@@ -9063,9 +9729,6 @@ function createStaticRouter(routes, context, opts = {}) {
9063
9729
  _internalFetchControllers: /* @__PURE__ */ new Map(),
9064
9730
  _internalSetRoutes() {
9065
9731
  throw msg("_internalSetRoutes");
9066
- },
9067
- _internalSetStateDoNotUseOrYouWillBreakYourApp() {
9068
- throw msg("_internalSetStateDoNotUseOrYouWillBreakYourApp");
9069
9732
  }
9070
9733
  };
9071
9734
  }
@@ -9140,6 +9803,7 @@ function ServerRouter({
9140
9803
  future: context.future,
9141
9804
  ssr: context.ssr,
9142
9805
  isSpaMode: context.isSpaMode,
9806
+ routeDiscovery: context.routeDiscovery,
9143
9807
  serializeError: context.serializeError,
9144
9808
  renderMeta: context.renderMeta
9145
9809
  }
@@ -9189,7 +9853,8 @@ function createRoutesStub(routes, unstable_getContext) {
9189
9853
  },
9190
9854
  routeModules: {},
9191
9855
  ssr: false,
9192
- isSpaMode: false
9856
+ isSpaMode: false,
9857
+ routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" }
9193
9858
  };
9194
9859
  let patched = processRoutes(
9195
9860
  // @ts-expect-error `StubRouteObject` is stricter about `loader`/`action`
@@ -9208,6 +9873,37 @@ function createRoutesStub(routes, unstable_getContext) {
9208
9873
  return /* @__PURE__ */ React13.createElement(FrameworkContext.Provider, { value: remixContextRef.current }, /* @__PURE__ */ React13.createElement(RouterProvider, { router: routerRef.current }));
9209
9874
  };
9210
9875
  }
9876
+ function withComponentProps(Component4) {
9877
+ return function Wrapped() {
9878
+ return React13.createElement(Component4, {
9879
+ params: useParams(),
9880
+ loaderData: useLoaderData(),
9881
+ actionData: useActionData(),
9882
+ matches: useMatches()
9883
+ });
9884
+ };
9885
+ }
9886
+ function withHydrateFallbackProps(HydrateFallback) {
9887
+ return function Wrapped() {
9888
+ const props = {
9889
+ params: useParams(),
9890
+ loaderData: useLoaderData(),
9891
+ actionData: useActionData()
9892
+ };
9893
+ return React13.createElement(HydrateFallback, props);
9894
+ };
9895
+ }
9896
+ function withErrorBoundaryProps(ErrorBoundary) {
9897
+ return function Wrapped() {
9898
+ const props = {
9899
+ params: useParams(),
9900
+ loaderData: useLoaderData(),
9901
+ actionData: useActionData(),
9902
+ error: useRouteError()
9903
+ };
9904
+ return React13.createElement(ErrorBoundary, props);
9905
+ };
9906
+ }
9211
9907
  function processRoutes(routes, manifest, routeModules, parentId) {
9212
9908
  return routes.map((route) => {
9213
9909
  if (!route.id) {
@@ -9219,9 +9915,9 @@ function processRoutes(routes, manifest, routeModules, parentId) {
9219
9915
  id: route.id,
9220
9916
  path: route.path,
9221
9917
  index: route.index,
9222
- Component: route.Component,
9223
- HydrateFallback: route.HydrateFallback,
9224
- ErrorBoundary: route.ErrorBoundary,
9918
+ Component: route.Component ? withComponentProps(route.Component) : void 0,
9919
+ HydrateFallback: route.HydrateFallback ? withHydrateFallbackProps(route.HydrateFallback) : void 0,
9920
+ ErrorBoundary: route.ErrorBoundary ? withErrorBoundaryProps(route.ErrorBoundary) : void 0,
9225
9921
  action: route.action,
9226
9922
  loader: route.loader,
9227
9923
  handle: route.handle,
@@ -9250,8 +9946,8 @@ function processRoutes(routes, manifest, routeModules, parentId) {
9250
9946
  };
9251
9947
  manifest.routes[newRoute.id] = entryRoute;
9252
9948
  routeModules[route.id] = {
9253
- default: route.Component || Outlet,
9254
- ErrorBoundary: route.ErrorBoundary || void 0,
9949
+ default: newRoute.Component || Outlet,
9950
+ ErrorBoundary: newRoute.ErrorBoundary || void 0,
9255
9951
  handle: route.handle,
9256
9952
  links: route.links,
9257
9953
  meta: route.meta,
@@ -9273,7 +9969,7 @@ function processRoutes(routes, manifest, routeModules, parentId) {
9273
9969
  import { parse, serialize } from "cookie";
9274
9970
 
9275
9971
  // lib/server-runtime/crypto.ts
9276
- var encoder = new TextEncoder();
9972
+ var encoder = /* @__PURE__ */ new TextEncoder();
9277
9973
  var sign = async (value, secret) => {
9278
9974
  let data2 = encoder.encode(value);
9279
9975
  let key = await createKey2(secret, ["sign"]);
@@ -9593,6 +10289,26 @@ function invariant3(value, message) {
9593
10289
  }
9594
10290
  }
9595
10291
 
10292
+ // lib/server-runtime/dev.ts
10293
+ var globalDevServerHooksKey = "__reactRouterDevServerHooks";
10294
+ function setDevServerHooks(devServerHooks) {
10295
+ globalThis[globalDevServerHooksKey] = devServerHooks;
10296
+ }
10297
+ function getDevServerHooks() {
10298
+ return globalThis[globalDevServerHooksKey];
10299
+ }
10300
+ function getBuildTimeHeader(request, headerName) {
10301
+ if (typeof process !== "undefined") {
10302
+ try {
10303
+ if (process.env?.IS_RR_BUILD_REQUEST === "yes") {
10304
+ return request.headers.get(headerName);
10305
+ }
10306
+ } catch (e) {
10307
+ }
10308
+ }
10309
+ return null;
10310
+ }
10311
+
9596
10312
  // lib/server-runtime/routes.ts
9597
10313
  function groupRoutesByParentId2(manifest) {
9598
10314
  let routes = {};
@@ -9624,10 +10340,11 @@ function createStaticHandlerDataRoutes(manifest, future, parentId = "", routesBy
9624
10340
  // Need to use RR's version in the param typed here to permit the optional
9625
10341
  // context even though we know it'll always be provided in remix
9626
10342
  loader: route.module.loader ? async (args) => {
9627
- if (args.request.headers.has("X-React-Router-Prerender-Data")) {
9628
- const preRenderedData = args.request.headers.get(
9629
- "X-React-Router-Prerender-Data"
9630
- );
10343
+ let preRenderedData = getBuildTimeHeader(
10344
+ args.request,
10345
+ "X-React-Router-Prerender-Data"
10346
+ );
10347
+ if (preRenderedData != null) {
9631
10348
  let encoded = preRenderedData ? decodeURI(preRenderedData) : preRenderedData;
9632
10349
  invariant3(encoded, "Missing prerendered data for route");
9633
10350
  let uint8array = new TextEncoder().encode(encoded);
@@ -9702,21 +10419,9 @@ function createServerHandoffString(serverHandoff) {
9702
10419
  return escapeHtml2(JSON.stringify(serverHandoff));
9703
10420
  }
9704
10421
 
9705
- // lib/server-runtime/dev.ts
9706
- var globalDevServerHooksKey = "__reactRouterDevServerHooks";
9707
- function setDevServerHooks(devServerHooks) {
9708
- globalThis[globalDevServerHooksKey] = devServerHooks;
9709
- }
9710
- function getDevServerHooks() {
9711
- return globalThis[globalDevServerHooksKey];
9712
- }
9713
-
9714
- // lib/server-runtime/single-fetch.ts
9715
- import { encode } from "turbo-stream";
9716
-
9717
10422
  // lib/server-runtime/headers.ts
9718
10423
  import { splitCookiesString } from "set-cookie-parser";
9719
- function getDocumentHeaders(context, getRouteHeadersFn) {
10424
+ function getDocumentHeaders(build, context) {
9720
10425
  let boundaryIdx = context.errors ? context.matches.findIndex((m) => context.errors[m.route.id]) : -1;
9721
10426
  let matches = boundaryIdx >= 0 ? context.matches.slice(0, boundaryIdx + 1) : context.matches;
9722
10427
  let errorHeaders;
@@ -9734,12 +10439,14 @@ function getDocumentHeaders(context, getRouteHeadersFn) {
9734
10439
  }
9735
10440
  return matches.reduce((parentHeaders, match, idx) => {
9736
10441
  let { id } = match.route;
10442
+ let route = build.routes[id];
10443
+ invariant3(route, `Route with id "${id}" not found in build`);
10444
+ let routeModule = route.module;
9737
10445
  let loaderHeaders = context.loaderHeaders[id] || new Headers();
9738
10446
  let actionHeaders = context.actionHeaders[id] || new Headers();
9739
10447
  let includeErrorHeaders = errorHeaders != null && idx === matches.length - 1;
9740
10448
  let includeErrorCookies = includeErrorHeaders && errorHeaders !== loaderHeaders && errorHeaders !== actionHeaders;
9741
- let headersFn = getRouteHeadersFn(match);
9742
- if (headersFn == null) {
10449
+ if (routeModule.headers == null) {
9743
10450
  let headers2 = new Headers(parentHeaders);
9744
10451
  if (includeErrorCookies) {
9745
10452
  prependCookies(errorHeaders, headers2);
@@ -9749,12 +10456,12 @@ function getDocumentHeaders(context, getRouteHeadersFn) {
9749
10456
  return headers2;
9750
10457
  }
9751
10458
  let headers = new Headers(
9752
- typeof headersFn === "function" ? headersFn({
10459
+ routeModule.headers ? typeof routeModule.headers === "function" ? routeModule.headers({
9753
10460
  loaderHeaders,
9754
10461
  parentHeaders,
9755
10462
  actionHeaders,
9756
10463
  errorHeaders: includeErrorHeaders ? errorHeaders : void 0
9757
- }) : headersFn
10464
+ }) : routeModule.headers : void 0
9758
10465
  );
9759
10466
  if (includeErrorCookies) {
9760
10467
  prependCookies(errorHeaders, headers);
@@ -9779,7 +10486,6 @@ function prependCookies(parentHeaders, childHeaders) {
9779
10486
  }
9780
10487
 
9781
10488
  // lib/server-runtime/single-fetch.ts
9782
- var SINGLE_FETCH_REDIRECT_STATUS = 202;
9783
10489
  var SERVER_NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([
9784
10490
  ...NO_BODY_STATUS_CODES,
9785
10491
  304
@@ -9787,10 +10493,7 @@ var SERVER_NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([
9787
10493
  async function singleFetchAction(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
9788
10494
  try {
9789
10495
  let respond2 = function(context) {
9790
- let headers = getDocumentHeaders(
9791
- context,
9792
- (m) => build.routes[m.route.id]?.module.headers
9793
- );
10496
+ let headers = getDocumentHeaders(build, context);
9794
10497
  if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
9795
10498
  return generateSingleFetchResponse(request, build, serverMode, {
9796
10499
  result: getSingleFetchRedirect(
@@ -9865,10 +10568,7 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
9865
10568
  async function singleFetchLoaders(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
9866
10569
  try {
9867
10570
  let respond2 = function(context) {
9868
- let headers = getDocumentHeaders(
9869
- context,
9870
- (m) => build.routes[m.route.id]?.module.headers
9871
- );
10571
+ let headers = getDocumentHeaders(build, context);
9872
10572
  if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
9873
10573
  return generateSingleFetchResponse(request, build, serverMode, {
9874
10574
  result: {
@@ -10124,9 +10824,10 @@ Error: ${e instanceof Error ? e.toString() : e}`
10124
10824
  if (stripBasename(normalizedPath, normalizedBasename) !== "/" && normalizedPath.endsWith("/")) {
10125
10825
  normalizedPath = normalizedPath.slice(0, -1);
10126
10826
  }
10827
+ let isSpaMode = getBuildTimeHeader(request, "X-React-Router-SPA-Mode") === "yes";
10127
10828
  if (!_build.ssr) {
10128
10829
  if (_build.prerender.length === 0) {
10129
- request.headers.set("X-React-Router-SPA-Mode", "yes");
10830
+ isSpaMode = true;
10130
10831
  } else if (!_build.prerender.includes(normalizedPath) && !_build.prerender.includes(normalizedPath + "/")) {
10131
10832
  if (url.pathname.endsWith(".data")) {
10132
10833
  errorHandler(
@@ -10146,11 +10847,14 @@ Error: ${e instanceof Error ? e.toString() : e}`
10146
10847
  statusText: "Not Found"
10147
10848
  });
10148
10849
  } else {
10149
- request.headers.set("X-React-Router-SPA-Mode", "yes");
10850
+ isSpaMode = true;
10150
10851
  }
10151
10852
  }
10152
10853
  }
10153
- let manifestUrl = `${normalizedBasename}/__manifest`.replace(/\/+/g, "/");
10854
+ let manifestUrl = getManifestPath(
10855
+ _build.routeDiscovery.manifestPath,
10856
+ normalizedBasename
10857
+ );
10154
10858
  if (url.pathname === manifestUrl) {
10155
10859
  try {
10156
10860
  let res = await handleManifestRequest(_build, routes, url);
@@ -10160,7 +10864,7 @@ Error: ${e instanceof Error ? e.toString() : e}`
10160
10864
  return new Response("Unknown Server Error", { status: 500 });
10161
10865
  }
10162
10866
  }
10163
- let matches = matchServerRoutes(routes, url.pathname, _build.basename);
10867
+ let matches = matchServerRoutes(routes, normalizedPath, _build.basename);
10164
10868
  if (matches && matches.length > 0) {
10165
10869
  Object.assign(params, matches[0].params);
10166
10870
  }
@@ -10215,7 +10919,7 @@ Error: ${e instanceof Error ? e.toString() : e}`
10215
10919
  );
10216
10920
  }
10217
10921
  }
10218
- } else if (!request.headers.has("X-React-Router-SPA-Mode") && matches && matches[matches.length - 1].route.module.default == null && matches[matches.length - 1].route.module.ErrorBoundary == null) {
10922
+ } else if (!isSpaMode && matches && matches[matches.length - 1].route.module.default == null && matches[matches.length - 1].route.module.ErrorBoundary == null) {
10219
10923
  response = await handleResourceRequest(
10220
10924
  serverMode,
10221
10925
  _build,
@@ -10240,6 +10944,7 @@ Error: ${e instanceof Error ? e.toString() : e}`
10240
10944
  request,
10241
10945
  loadContext,
10242
10946
  handleError,
10947
+ isSpaMode,
10243
10948
  criticalCss
10244
10949
  );
10245
10950
  }
@@ -10315,8 +11020,7 @@ async function handleSingleFetchRequest(serverMode, build, staticHandler, reques
10315
11020
  );
10316
11021
  return response;
10317
11022
  }
10318
- async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, criticalCss) {
10319
- let isSpaMode = request.headers.has("X-React-Router-SPA-Mode");
11023
+ async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, isSpaMode, criticalCss) {
10320
11024
  try {
10321
11025
  let response = await staticHandler.query(request, {
10322
11026
  requestContext: loadContext,
@@ -10331,10 +11035,7 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
10331
11035
  if (isResponse(context)) {
10332
11036
  return context;
10333
11037
  }
10334
- let headers = getDocumentHeaders(
10335
- context,
10336
- (m) => build.routes[m.route.id]?.module.headers
10337
- );
11038
+ let headers = getDocumentHeaders(build, context);
10338
11039
  if (SERVER_NO_BODY_STATUS_CODES.has(context.statusCode)) {
10339
11040
  return new Response(null, { status: context.statusCode, headers });
10340
11041
  }
@@ -10351,17 +11052,21 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
10351
11052
  actionData: context.actionData,
10352
11053
  errors: serializeErrors2(context.errors, serverMode)
10353
11054
  };
11055
+ let baseServerHandoff = {
11056
+ basename: build.basename,
11057
+ future: build.future,
11058
+ routeDiscovery: build.routeDiscovery,
11059
+ ssr: build.ssr,
11060
+ isSpaMode: isSpaMode2
11061
+ };
10354
11062
  let entryContext = {
10355
11063
  manifest: build.assets,
10356
11064
  routeModules: createEntryRouteModules(build.routes),
10357
11065
  staticHandlerContext: context,
10358
11066
  criticalCss,
10359
11067
  serverHandoffString: createServerHandoffString({
10360
- basename: build.basename,
10361
- criticalCss,
10362
- future: build.future,
10363
- ssr: build.ssr,
10364
- isSpaMode: isSpaMode2
11068
+ ...baseServerHandoff,
11069
+ criticalCss
10365
11070
  }),
10366
11071
  serverHandoffStream: encodeViaTurboStream(
10367
11072
  state,
@@ -10372,6 +11077,7 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
10372
11077
  renderMeta: {},
10373
11078
  future: build.future,
10374
11079
  ssr: build.ssr,
11080
+ routeDiscovery: build.routeDiscovery,
10375
11081
  isSpaMode: isSpaMode2,
10376
11082
  serializeError: (err) => serializeError(err, serverMode)
10377
11083
  };
@@ -10414,12 +11120,7 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
10414
11120
  entryContext = {
10415
11121
  ...entryContext,
10416
11122
  staticHandlerContext: context,
10417
- serverHandoffString: createServerHandoffString({
10418
- basename: build.basename,
10419
- future: build.future,
10420
- ssr: build.ssr,
10421
- isSpaMode: isSpaMode2
10422
- }),
11123
+ serverHandoffString: createServerHandoffString(baseServerHandoff),
10423
11124
  serverHandoffStream: encodeViaTurboStream(
10424
11125
  state2,
10425
11126
  request.signal,
@@ -10592,7 +11293,7 @@ function createSessionStorage({
10592
11293
  function warnOnceAboutSigningSessionCookie(cookie) {
10593
11294
  warnOnce(
10594
11295
  cookie.isSigned,
10595
- `The "${cookie.name}" cookie is not signed, but session cookies should be signed to prevent tampering on the client before they are sent back to the server. See https://remix.run/utils/cookies#signing-cookies for more information.`
11296
+ `The "${cookie.name}" cookie is not signed, but session cookies should be signed to prevent tampering on the client before they are sent back to the server. See https://reactrouter.com/explanation/sessions-and-cookies#signing-cookies for more information.`
10596
11297
  );
10597
11298
  }
10598
11299
 
@@ -10672,692 +11373,6 @@ function href(path, ...args) {
10672
11373
  }).filter((segment) => segment !== void 0).join("/");
10673
11374
  }
10674
11375
 
10675
- // lib/rsc/browser.tsx
10676
- import * as React14 from "react";
10677
-
10678
- // lib/dom/ssr/hydration.tsx
10679
- function getHydrationData(state, routes, getRouteInfo, location2, basename, isSpaMode) {
10680
- let hydrationData = {
10681
- ...state,
10682
- loaderData: { ...state.loaderData }
10683
- };
10684
- let initialMatches = matchRoutes(routes, location2, basename);
10685
- if (initialMatches) {
10686
- for (let match of initialMatches) {
10687
- let routeId = match.route.id;
10688
- let routeInfo = getRouteInfo(routeId);
10689
- if (shouldHydrateRouteLoader(
10690
- routeId,
10691
- routeInfo.clientLoader,
10692
- routeInfo.hasLoader,
10693
- isSpaMode
10694
- ) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) {
10695
- delete hydrationData.loaderData[routeId];
10696
- } else if (!routeInfo.hasLoader) {
10697
- hydrationData.loaderData[routeId] = null;
10698
- }
10699
- }
10700
- }
10701
- return hydrationData;
10702
- }
10703
-
10704
- // lib/rsc/browser.tsx
10705
- function createCallServer({
10706
- decode: decode2,
10707
- encodeAction
10708
- }) {
10709
- let landedActionId = 0;
10710
- return async (id, args) => {
10711
- let actionId = window.__routerActionID = (window.__routerActionID ?? (window.__routerActionID = 0)) + 1;
10712
- const response = await fetch(location.href, {
10713
- body: await encodeAction(args),
10714
- method: "POST",
10715
- headers: {
10716
- Accept: "text/x-component",
10717
- "rsc-action-id": id
10718
- }
10719
- });
10720
- if (!response.body) {
10721
- throw new Error("No response body");
10722
- }
10723
- const payload = await decode2(response.body);
10724
- if (payload.type !== "action") {
10725
- throw new Error("Unexpected payload type");
10726
- }
10727
- if (payload.rerender) {
10728
- (async () => {
10729
- const rerender = await payload.rerender;
10730
- if (!rerender) return;
10731
- if (landedActionId < actionId && window.__routerActionID <= actionId) {
10732
- landedActionId = actionId;
10733
- if (rerender.type === "redirect") {
10734
- if (rerender.reload) {
10735
- window.location.href = rerender.location;
10736
- return;
10737
- }
10738
- window.__router.navigate(rerender.location, {
10739
- replace: rerender.replace
10740
- });
10741
- return;
10742
- }
10743
- let lastMatch;
10744
- for (const match of rerender.matches) {
10745
- window.__router.patchRoutes(
10746
- lastMatch?.id ?? null,
10747
- [createRouteFromServerManifest(match)],
10748
- true
10749
- );
10750
- lastMatch = match;
10751
- }
10752
- window.__router._internalSetStateDoNotUseOrYouWillBreakYourApp({});
10753
- React14.startTransition(() => {
10754
- window.__router._internalSetStateDoNotUseOrYouWillBreakYourApp({
10755
- loaderData: Object.assign(
10756
- {},
10757
- window.__router.state.loaderData,
10758
- rerender.loaderData
10759
- ),
10760
- errors: rerender.errors ? Object.assign(
10761
- {},
10762
- window.__router.state.errors,
10763
- rerender.errors
10764
- ) : null
10765
- });
10766
- });
10767
- }
10768
- })();
10769
- }
10770
- return payload.actionResult;
10771
- };
10772
- }
10773
- function createRouterFromPayload({
10774
- decode: decode2,
10775
- payload
10776
- }) {
10777
- if (window.__router) return window.__router;
10778
- if (payload.type !== "render") throw new Error("Invalid payload type");
10779
- let patches = /* @__PURE__ */ new Map();
10780
- payload.patches?.forEach((patch) => {
10781
- invariant(patch.parentId, "Invalid patch parentId");
10782
- if (!patches.has(patch.parentId)) {
10783
- patches.set(patch.parentId, []);
10784
- }
10785
- patches.get(patch.parentId)?.push(patch);
10786
- });
10787
- let routes = payload.matches.reduceRight((previous, match) => {
10788
- const route = createRouteFromServerManifest(
10789
- match,
10790
- payload
10791
- );
10792
- if (previous.length > 0) {
10793
- route.children = previous;
10794
- let childrenToPatch = patches.get(match.id);
10795
- if (childrenToPatch) {
10796
- route.children.push(
10797
- ...childrenToPatch.map((r) => createRouteFromServerManifest(r))
10798
- );
10799
- }
10800
- }
10801
- return [route];
10802
- }, []);
10803
- window.__router = createRouter({
10804
- routes,
10805
- basename: payload.basename,
10806
- history: createBrowserHistory(),
10807
- hydrationData: getHydrationData(
10808
- {
10809
- loaderData: payload.loaderData,
10810
- actionData: payload.actionData,
10811
- errors: payload.errors
10812
- },
10813
- routes,
10814
- (routeId) => {
10815
- let match = payload.matches.find((m) => m.id === routeId);
10816
- invariant(match, "Route not found in payload");
10817
- return {
10818
- clientLoader: match.clientLoader,
10819
- hasLoader: match.hasLoader,
10820
- hasHydrateFallback: match.hydrateFallbackElement != null
10821
- };
10822
- },
10823
- payload.location,
10824
- void 0,
10825
- false
10826
- ),
10827
- async patchRoutesOnNavigation({ patch, path, signal }) {
10828
- let response = await fetch(`${path}.manifest`, { signal });
10829
- if (!response.body || response.status < 200 || response.status >= 300) {
10830
- throw new Error("Unable to fetch new route matches from the server");
10831
- }
10832
- let payload2 = await decode2(response.body);
10833
- if (payload2.type !== "manifest") {
10834
- throw new Error("Failed to patch routes on navigation");
10835
- }
10836
- payload2.matches.forEach(
10837
- (match, i) => patch(payload2.matches[i - 1]?.id ?? null, [
10838
- createRouteFromServerManifest(match)
10839
- ])
10840
- );
10841
- payload2.patches.forEach((p) => {
10842
- patch(p.parentId ?? null, [createRouteFromServerManifest(p)]);
10843
- });
10844
- },
10845
- // FIXME: Pass `build.ssr` and `build.basename` into this function
10846
- dataStrategy: getRSCSingleFetchDataStrategy(
10847
- () => window.__router,
10848
- true,
10849
- void 0,
10850
- decode2
10851
- )
10852
- });
10853
- if (window.__router.state.initialized) {
10854
- window.__routerInitialized = true;
10855
- window.__router.initialize();
10856
- } else {
10857
- window.__routerInitialized = false;
10858
- }
10859
- let lastLoaderData = void 0;
10860
- window.__router.subscribe(({ loaderData, actionData }) => {
10861
- if (lastLoaderData !== loaderData) {
10862
- window.__routerActionID = (window.__routerActionID ?? (window.__routerActionID = 0)) + 1;
10863
- }
10864
- });
10865
- return window.__router;
10866
- }
10867
- var renderedRoutesContext = unstable_createContext();
10868
- function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, decode2) {
10869
- let dataStrategy = getSingleFetchDataStrategyImpl(
10870
- getRouter,
10871
- (match) => {
10872
- let M = match;
10873
- return {
10874
- hasLoader: M.route.hasLoader,
10875
- hasClientLoader: M.route.hasClientLoader,
10876
- hasAction: M.route.hasAction,
10877
- hasClientAction: M.route.hasClientAction,
10878
- hasShouldRevalidate: M.route.hasShouldRevalidate
10879
- };
10880
- },
10881
- // pass map into fetchAndDecode so it can add payloads
10882
- getFetchAndDecodeViaRSC(decode2),
10883
- ssr,
10884
- basename
10885
- );
10886
- return async (args) => args.unstable_runClientMiddleware(async () => {
10887
- let context = args.context;
10888
- context.set(renderedRoutesContext, []);
10889
- let results = await dataStrategy(args);
10890
- const renderedRouteById = new Map(
10891
- context.get(renderedRoutesContext).map((r) => [r.id, r])
10892
- );
10893
- for (const match of args.matches) {
10894
- const rendered = renderedRouteById.get(match.route.id);
10895
- if (rendered) {
10896
- window.__router.patchRoutes(
10897
- rendered.parentId ?? null,
10898
- [createRouteFromServerManifest(rendered)],
10899
- true
10900
- );
10901
- }
10902
- }
10903
- return results;
10904
- });
10905
- }
10906
- function getFetchAndDecodeViaRSC(decode2) {
10907
- return async (args, basename, targetRoutes) => {
10908
- let { request, context } = args;
10909
- let url = singleFetchUrl(request.url, basename, "rsc");
10910
- if (request.method === "GET") {
10911
- url = stripIndexParam(url);
10912
- if (targetRoutes) {
10913
- url.searchParams.set("_routes", targetRoutes.join(","));
10914
- }
10915
- }
10916
- let res = await fetch(url, await createRequestInit(request));
10917
- if (res.status === 404 && !res.headers.has("X-Remix-Response")) {
10918
- throw new ErrorResponseImpl(404, "Not Found", true);
10919
- }
10920
- invariant(res.body, "No response body to decode");
10921
- try {
10922
- const payload = await decode2(res.body);
10923
- if (payload.type === "redirect") {
10924
- return {
10925
- status: res.status,
10926
- data: {
10927
- redirect: {
10928
- redirect: payload.location,
10929
- reload: false,
10930
- replace: payload.replace,
10931
- revalidate: false,
10932
- status: payload.status
10933
- }
10934
- }
10935
- };
10936
- }
10937
- if (payload.type !== "render") {
10938
- throw new Error("Unexpected payload type");
10939
- }
10940
- context.get(renderedRoutesContext).push(...payload.matches);
10941
- let results = { routes: {} };
10942
- const dataKey = isMutationMethod(request.method) ? "actionData" : "loaderData";
10943
- for (let [routeId, data2] of Object.entries(payload[dataKey] || {})) {
10944
- results.routes[routeId] = { data: data2 };
10945
- }
10946
- if (payload.errors) {
10947
- for (let [routeId, error] of Object.entries(payload.errors)) {
10948
- results.routes[routeId] = { error };
10949
- }
10950
- }
10951
- return { status: res.status, data: results };
10952
- } catch (e) {
10953
- throw new Error("Unable to decode RSC response");
10954
- }
10955
- };
10956
- }
10957
- function RSCHydratedRouter({
10958
- decode: decode2,
10959
- payload
10960
- }) {
10961
- if (payload.type !== "render") throw new Error("Invalid payload type");
10962
- let router = React14.useMemo(
10963
- () => createRouterFromPayload({ decode: decode2, payload }),
10964
- // eslint-disable-next-line react-hooks/exhaustive-deps
10965
- []
10966
- );
10967
- React14.useLayoutEffect(() => {
10968
- if (!window.__routerInitialized) {
10969
- window.__routerInitialized = true;
10970
- window.__router.initialize();
10971
- }
10972
- }, []);
10973
- const frameworkContext = {
10974
- future: {
10975
- // These flags have no runtime impact so can always be false. If we add
10976
- // flags that drive runtime behavior they'll need to be proxied through.
10977
- unstable_middleware: false,
10978
- unstable_subResourceIntegrity: false
10979
- },
10980
- isSpaMode: true,
10981
- ssr: true,
10982
- criticalCss: "",
10983
- manifest: {
10984
- routes: {},
10985
- version: "1",
10986
- url: "",
10987
- entry: {
10988
- module: "",
10989
- imports: []
10990
- }
10991
- },
10992
- routeModules: {}
10993
- };
10994
- return /* @__PURE__ */ React14.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React14.createElement(RouterProvider, { router }));
10995
- }
10996
- function createRouteFromServerManifest(match, payload) {
10997
- let hasInitialData = payload && match.id in payload.loaderData;
10998
- let initialData = payload?.loaderData[match.id];
10999
- let hasInitialError = payload?.errors && match.id in payload.errors;
11000
- let initialError = payload?.errors?.[match.id];
11001
- let isHydrationRequest = match.clientLoader?.hydrate === true || !match.hasLoader;
11002
- let dataRoute = {
11003
- id: match.id,
11004
- element: match.element,
11005
- errorElement: match.errorElement,
11006
- handle: match.handle,
11007
- hasErrorBoundary: match.hasErrorBoundary,
11008
- hydrateFallbackElement: match.hydrateFallbackElement,
11009
- index: match.index,
11010
- loader: match.clientLoader ? async (args, singleFetch) => {
11011
- try {
11012
- let result = await match.clientLoader({
11013
- ...args,
11014
- serverLoader: () => {
11015
- preventInvalidServerHandlerCall2(
11016
- "loader",
11017
- match.id,
11018
- match.hasLoader
11019
- );
11020
- if (isHydrationRequest) {
11021
- if (hasInitialData) {
11022
- return initialData;
11023
- }
11024
- if (hasInitialError) {
11025
- throw initialError;
11026
- }
11027
- }
11028
- return callSingleFetch(singleFetch);
11029
- }
11030
- });
11031
- return result;
11032
- } finally {
11033
- isHydrationRequest = false;
11034
- }
11035
- } : (
11036
- // We always make the call in this RSC world since even if we don't
11037
- // have a `loader` we may need to get the `element` implementation
11038
- (_, singleFetch) => callSingleFetch(singleFetch)
11039
- ),
11040
- action: match.clientAction ? (args, singleFetch) => match.clientAction({
11041
- ...args,
11042
- serverAction: async () => {
11043
- preventInvalidServerHandlerCall2(
11044
- "loader",
11045
- match.id,
11046
- match.hasLoader
11047
- );
11048
- return await callSingleFetch(singleFetch);
11049
- }
11050
- }) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : void 0,
11051
- path: match.path,
11052
- shouldRevalidate: match.shouldRevalidate,
11053
- // We always have a "loader" in this RSC world since even if we don't
11054
- // have a `loader` we may need to get the `element` implementation
11055
- hasLoader: true,
11056
- hasClientLoader: match.clientLoader != null,
11057
- hasAction: match.hasAction,
11058
- hasClientAction: match.clientAction != null,
11059
- hasShouldRevalidate: match.shouldRevalidate != null
11060
- };
11061
- if (typeof dataRoute.loader === "function") {
11062
- dataRoute.loader.hydrate = shouldHydrateRouteLoader(
11063
- match.id,
11064
- match.clientLoader,
11065
- match.hasLoader,
11066
- false
11067
- );
11068
- }
11069
- return dataRoute;
11070
- }
11071
- function callSingleFetch(singleFetch) {
11072
- invariant(typeof singleFetch === "function", "Invalid singleFetch parameter");
11073
- return singleFetch();
11074
- }
11075
- function preventInvalidServerHandlerCall2(type, routeId, hasHandler) {
11076
- if (!hasHandler) {
11077
- let fn = type === "action" ? "serverAction()" : "serverLoader()";
11078
- let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${routeId}")`;
11079
- console.error(msg);
11080
- throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
11081
- }
11082
- }
11083
-
11084
- // lib/rsc/server.ssr.tsx
11085
- import * as React15 from "react";
11086
-
11087
- // lib/rsc/html-stream/server.ts
11088
- var encoder2 = new TextEncoder();
11089
- var trailer = "</body></html>";
11090
- function injectRSCPayload(rscStream) {
11091
- let decoder = new TextDecoder();
11092
- let resolveFlightDataPromise;
11093
- let flightDataPromise = new Promise(
11094
- (resolve) => resolveFlightDataPromise = resolve
11095
- );
11096
- let startedRSC = false;
11097
- let buffered = [];
11098
- let timeout = null;
11099
- function flushBufferedChunks(controller) {
11100
- for (let chunk of buffered) {
11101
- let buf = decoder.decode(chunk, { stream: true });
11102
- if (buf.endsWith(trailer)) {
11103
- buf = buf.slice(0, -trailer.length);
11104
- }
11105
- controller.enqueue(encoder2.encode(buf));
11106
- }
11107
- buffered.length = 0;
11108
- timeout = null;
11109
- }
11110
- return new TransformStream({
11111
- transform(chunk, controller) {
11112
- buffered.push(chunk);
11113
- if (timeout) {
11114
- return;
11115
- }
11116
- timeout = setTimeout(async () => {
11117
- flushBufferedChunks(controller);
11118
- if (!startedRSC) {
11119
- startedRSC = true;
11120
- writeRSCStream(rscStream, controller).catch((err) => controller.error(err)).then(resolveFlightDataPromise);
11121
- }
11122
- }, 0);
11123
- },
11124
- async flush(controller) {
11125
- await flightDataPromise;
11126
- if (timeout) {
11127
- clearTimeout(timeout);
11128
- flushBufferedChunks(controller);
11129
- }
11130
- controller.enqueue(encoder2.encode("</body></html>"));
11131
- }
11132
- });
11133
- }
11134
- async function writeRSCStream(rscStream, controller) {
11135
- let decoder = new TextDecoder("utf-8", { fatal: true });
11136
- const reader = rscStream.getReader();
11137
- try {
11138
- let read;
11139
- while ((read = await reader.read()) && !read.done) {
11140
- const chunk = read.value;
11141
- try {
11142
- writeChunk(
11143
- JSON.stringify(decoder.decode(chunk, { stream: true })),
11144
- controller
11145
- );
11146
- } catch (err) {
11147
- let base64 = JSON.stringify(btoa(String.fromCodePoint(...chunk)));
11148
- writeChunk(
11149
- `Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`,
11150
- controller
11151
- );
11152
- }
11153
- }
11154
- } finally {
11155
- reader.releaseLock();
11156
- }
11157
- let remaining = decoder.decode();
11158
- if (remaining.length) {
11159
- writeChunk(JSON.stringify(remaining), controller);
11160
- }
11161
- }
11162
- function writeChunk(chunk, controller) {
11163
- controller.enqueue(
11164
- encoder2.encode(
11165
- `<script>${escapeScript(
11166
- `(self.__FLIGHT_DATA||=[]).push(${chunk})`
11167
- )}</script>`
11168
- )
11169
- );
11170
- }
11171
- function escapeScript(script) {
11172
- return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
11173
- }
11174
-
11175
- // lib/rsc/server.ssr.tsx
11176
- async function routeRSCServerRequest(request, requestServer, decode2, renderHTML) {
11177
- const url = new URL(request.url);
11178
- let serverRequest = request;
11179
- const isDataRequest = isReactServerRequest(url);
11180
- const respondWithRSCPayload = isDataRequest || isManifestRequest(url) || request.headers.has("rsc-action-id");
11181
- if (isDataRequest) {
11182
- const serverURL = new URL(request.url);
11183
- serverURL.pathname = serverURL.pathname.replace(/(_root)?\.rsc$/, "");
11184
- let headers = new Headers(request.headers);
11185
- headers.set("X-React-Router-Data-Request", "true");
11186
- serverRequest = new Request(serverURL, {
11187
- body: request.body,
11188
- duplex: request.body ? "half" : void 0,
11189
- headers,
11190
- method: request.method,
11191
- signal: request.signal
11192
- });
11193
- }
11194
- const serverResponse = await requestServer(serverRequest);
11195
- if (respondWithRSCPayload) {
11196
- return serverResponse;
11197
- }
11198
- if (!serverResponse.body) {
11199
- throw new Error("Missing body in server response");
11200
- }
11201
- const serverResponseB = serverResponse.clone();
11202
- if (!serverResponseB.body) {
11203
- throw new Error("Failed to clone server response");
11204
- }
11205
- const body = serverResponse.body;
11206
- let payloadPromise;
11207
- const getPayload = async () => {
11208
- if (payloadPromise) return payloadPromise;
11209
- payloadPromise = decode2(body);
11210
- return payloadPromise;
11211
- };
11212
- try {
11213
- const html = await renderHTML(getPayload);
11214
- const body2 = html.pipeThrough(injectRSCPayload(serverResponseB.body));
11215
- const headers = new Headers(serverResponse.headers);
11216
- headers.set("Content-Type", "text/html");
11217
- return new Response(body2, {
11218
- status: serverResponse.status,
11219
- headers
11220
- });
11221
- } catch (reason) {
11222
- if (reason instanceof Response) {
11223
- return reason;
11224
- }
11225
- throw reason;
11226
- }
11227
- }
11228
- function RSCStaticRouter({
11229
- getPayload
11230
- }) {
11231
- const payload = React15.use(getPayload());
11232
- if (payload.type === "redirect") {
11233
- throw new Response(null, {
11234
- status: payload.status,
11235
- headers: {
11236
- Location: payload.location
11237
- }
11238
- });
11239
- }
11240
- if (payload.type !== "render") return null;
11241
- const context = {
11242
- actionData: payload.actionData,
11243
- actionHeaders: {},
11244
- basename: payload.basename,
11245
- errors: payload.errors,
11246
- loaderData: payload.loaderData,
11247
- loaderHeaders: {},
11248
- location: payload.location,
11249
- statusCode: 200,
11250
- matches: payload.matches.map((match) => ({
11251
- params: match.params,
11252
- pathname: match.pathname,
11253
- pathnameBase: match.pathnameBase,
11254
- route: {
11255
- id: match.id,
11256
- action: match.hasAction || !!match.clientAction,
11257
- handle: match.handle,
11258
- hasErrorBoundary: match.hasErrorBoundary,
11259
- loader: match.hasLoader || !!match.clientLoader,
11260
- index: match.index,
11261
- path: match.path,
11262
- shouldRevalidate: match.shouldRevalidate
11263
- }
11264
- }))
11265
- };
11266
- const router = createStaticRouter(
11267
- payload.matches.reduceRight((previous, match) => {
11268
- const route = {
11269
- id: match.id,
11270
- action: match.hasAction || !!match.clientAction,
11271
- element: match.element,
11272
- errorElement: match.errorElement,
11273
- handle: match.handle,
11274
- hasErrorBoundary: !!match.errorElement,
11275
- hydrateFallbackElement: match.hydrateFallbackElement,
11276
- index: match.index,
11277
- loader: match.hasLoader || !!match.clientLoader,
11278
- path: match.path,
11279
- shouldRevalidate: match.shouldRevalidate
11280
- };
11281
- if (previous.length > 0) {
11282
- route.children = previous;
11283
- }
11284
- return [route];
11285
- }, []),
11286
- context
11287
- );
11288
- const frameworkContext = {
11289
- future: {
11290
- // These flags have no runtime impact so can always be false. If we add
11291
- // flags that drive runtime behavior they'll need to be proxied through.
11292
- unstable_middleware: false,
11293
- unstable_subResourceIntegrity: false
11294
- },
11295
- isSpaMode: false,
11296
- ssr: true,
11297
- criticalCss: "",
11298
- manifest: {
11299
- routes: {},
11300
- version: "1",
11301
- url: "",
11302
- entry: {
11303
- module: "",
11304
- imports: []
11305
- }
11306
- },
11307
- routeModules: {}
11308
- };
11309
- return /* @__PURE__ */ React15.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React15.createElement(
11310
- StaticRouterProvider,
11311
- {
11312
- context,
11313
- router,
11314
- hydrate: false,
11315
- nonce: payload.nonce
11316
- }
11317
- ));
11318
- }
11319
- function isReactServerRequest(url) {
11320
- return url.pathname.endsWith(".rsc");
11321
- }
11322
- function isManifestRequest(url) {
11323
- return url.pathname.endsWith(".manifest");
11324
- }
11325
-
11326
- // lib/rsc/html-stream/browser.ts
11327
- function getServerStream() {
11328
- let encoder3 = new TextEncoder();
11329
- let streamController = null;
11330
- let rscStream = new ReadableStream({
11331
- start(controller) {
11332
- if (typeof window === "undefined") {
11333
- return;
11334
- }
11335
- let handleChunk = (chunk) => {
11336
- if (typeof chunk === "string") {
11337
- controller.enqueue(encoder3.encode(chunk));
11338
- } else {
11339
- controller.enqueue(chunk);
11340
- }
11341
- };
11342
- window.__FLIGHT_DATA || (window.__FLIGHT_DATA = []);
11343
- window.__FLIGHT_DATA.forEach(handleChunk);
11344
- window.__FLIGHT_DATA.push = (chunk) => {
11345
- handleChunk(chunk);
11346
- return 0;
11347
- };
11348
- streamController = controller;
11349
- }
11350
- });
11351
- if (typeof document !== "undefined" && document.readyState === "loading") {
11352
- document.addEventListener("DOMContentLoaded", () => {
11353
- streamController?.close();
11354
- });
11355
- } else {
11356
- streamController?.close();
11357
- }
11358
- return rscStream;
11359
- }
11360
-
11361
11376
  // lib/dom/ssr/errors.ts
11362
11377
  function deserializeErrors2(errors) {
11363
11378
  if (!errors) return null;
@@ -11395,6 +11410,32 @@ function deserializeErrors2(errors) {
11395
11410
  return serialized;
11396
11411
  }
11397
11412
 
11413
+ // lib/dom/ssr/hydration.tsx
11414
+ function getHydrationData(state, routes, getRouteInfo, location, basename, isSpaMode) {
11415
+ let hydrationData = {
11416
+ ...state,
11417
+ loaderData: { ...state.loaderData }
11418
+ };
11419
+ let initialMatches = matchRoutes(routes, location, basename);
11420
+ if (initialMatches) {
11421
+ for (let match of initialMatches) {
11422
+ let routeId = match.route.id;
11423
+ let routeInfo = getRouteInfo(routeId);
11424
+ if (shouldHydrateRouteLoader(
11425
+ routeId,
11426
+ routeInfo.clientLoader,
11427
+ routeInfo.hasLoader,
11428
+ isSpaMode
11429
+ ) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) {
11430
+ delete hydrationData.loaderData[routeId];
11431
+ } else if (!routeInfo.hasLoader) {
11432
+ hydrationData.loaderData[routeId] = null;
11433
+ }
11434
+ }
11435
+ }
11436
+ return hydrationData;
11437
+ }
11438
+
11398
11439
  export {
11399
11440
  Action,
11400
11441
  createBrowserHistory,
@@ -11456,9 +11497,6 @@ export {
11456
11497
  Router,
11457
11498
  Routes,
11458
11499
  Await,
11459
- WithRouteComponentProps,
11460
- WithHydrateFallbackProps,
11461
- WithErrorBoundaryProps,
11462
11500
  createRoutesFromChildren,
11463
11501
  createRoutesFromElements,
11464
11502
  renderMatches,
@@ -11513,11 +11551,6 @@ export {
11513
11551
  createCookieSessionStorage,
11514
11552
  createMemorySessionStorage,
11515
11553
  href,
11516
- getHydrationData,
11517
- createCallServer,
11518
- RSCHydratedRouter,
11519
- routeRSCServerRequest,
11520
- RSCStaticRouter,
11521
- getServerStream,
11522
- deserializeErrors2 as deserializeErrors
11554
+ deserializeErrors2 as deserializeErrors,
11555
+ getHydrationData
11523
11556
  };