react-router 0.0.0-experimental-3b8ea09a1 → 0.0.0-experimental-7db49e8d4

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 (40) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/dist/{production/lib-C1JSsICm.d.mts → development/browser-BM9EKN98.d.mts} +80 -2
  3. package/dist/development/{chunk-7UZAQ62J.mjs → chunk-UKHDCHH6.mjs} +1200 -325
  4. package/dist/development/dom-export.d.mts +2 -2
  5. package/dist/development/dom-export.js +2 -1
  6. package/dist/development/dom-export.mjs +3 -2
  7. package/dist/development/index.d.mts +16 -5
  8. package/dist/development/index.d.ts +92 -3
  9. package/dist/development/index.js +1204 -323
  10. package/dist/development/index.mjs +13 -2
  11. package/dist/development/lib/types/internal.d.mts +1 -1
  12. package/dist/development/lib/types/internal.d.ts +1 -1
  13. package/dist/development/lib/types/internal.js +1 -1
  14. package/dist/development/lib/types/internal.mjs +1 -1
  15. package/dist/{production/register-DCE0tH5m.d.ts → development/register-B0EYMBux.d.ts} +13 -2
  16. package/dist/{production/route-data-ByAYLHuM.d.mts → development/route-data-B3YkvRuy.d.mts} +13 -2
  17. package/dist/development/rsc-export.d.mts +1803 -0
  18. package/dist/development/rsc-export.d.ts +1803 -0
  19. package/dist/development/rsc-export.js +2906 -0
  20. package/dist/development/rsc-export.mjs +2870 -0
  21. package/dist/{development/lib-C1JSsICm.d.mts → production/browser-BM9EKN98.d.mts} +80 -2
  22. package/dist/production/{chunk-YL2M5PUQ.mjs → chunk-ZA7BCDUO.mjs} +1200 -325
  23. package/dist/production/dom-export.d.mts +2 -2
  24. package/dist/production/dom-export.js +2 -1
  25. package/dist/production/dom-export.mjs +3 -2
  26. package/dist/production/index.d.mts +16 -5
  27. package/dist/production/index.d.ts +92 -3
  28. package/dist/production/index.js +1204 -323
  29. package/dist/production/index.mjs +13 -2
  30. package/dist/production/lib/types/internal.d.mts +1 -1
  31. package/dist/production/lib/types/internal.d.ts +1 -1
  32. package/dist/production/lib/types/internal.js +1 -1
  33. package/dist/production/lib/types/internal.mjs +1 -1
  34. package/dist/{development/register-DCE0tH5m.d.ts → production/register-B0EYMBux.d.ts} +13 -2
  35. package/dist/{development/route-data-ByAYLHuM.d.mts → production/route-data-B3YkvRuy.d.mts} +13 -2
  36. package/dist/production/rsc-export.d.mts +1803 -0
  37. package/dist/production/rsc-export.d.ts +1803 -0
  38. package/dist/production/rsc-export.js +2906 -0
  39. package/dist/production/rsc-export.mjs +2870 -0
  40. package/package.json +33 -2
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v0.0.0-experimental-3b8ea09a1
2
+ * react-router v0.0.0-experimental-7db49e8d4
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 location = createLocation(
48
+ let location2 = createLocation(
49
49
  entries ? getCurrentLocation().pathname : "/",
50
50
  to,
51
51
  state,
52
52
  key
53
53
  );
54
54
  warning(
55
- location.pathname.charAt(0) === "/",
55
+ location2.pathname.charAt(0) === "/",
56
56
  `relative pathnames are not supported in memory history: ${JSON.stringify(
57
57
  to
58
58
  )}`
59
59
  );
60
- return location;
60
+ return location2;
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(location, to) {
171
+ function validateHashLocation(location2, to) {
172
172
  warning(
173
- location.pathname.charAt(0) === "/",
173
+ location2.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(location, index) {
203
+ function getHistoryState(location2, index) {
204
204
  return {
205
- usr: location.state,
206
- key: location.key,
205
+ usr: location2.state,
206
+ key: location2.key,
207
207
  idx: index
208
208
  };
209
209
  }
210
210
  function createLocation(current, to, state = null, key) {
211
- let location = {
211
+ let location2 = {
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 location;
223
+ return location2;
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 location = createLocation(history.location, to, state);
281
- if (validateLocation) validateLocation(location, to);
280
+ let location2 = createLocation(history.location, to, state);
281
+ if (validateLocation) validateLocation(location2, to);
282
282
  index = getIndex() + 1;
283
- let historyState = getHistoryState(location, index);
284
- let url = history.createHref(location);
283
+ let historyState = getHistoryState(location2, index);
284
+ let url = history.createHref(location2);
285
285
  try {
286
286
  globalHistory.pushState(historyState, "", url);
287
287
  } catch (error) {
@@ -296,11 +296,11 @@ function getUrlBasedHistory(getLocation, createHref2, validateLocation, options
296
296
  }
297
297
  function replace2(to, state) {
298
298
  action = "REPLACE" /* Replace */;
299
- let location = createLocation(history.location, to, state);
300
- if (validateLocation) validateLocation(location, to);
299
+ let location2 = createLocation(history.location, to, state);
300
+ if (validateLocation) validateLocation(location2, to);
301
301
  index = getIndex();
302
- let historyState = getHistoryState(location, index);
303
- let url = history.createHref(location);
302
+ let historyState = getHistoryState(location2, index);
303
+ let url = history.createHref(location2);
304
304
  globalHistory.replaceState(historyState, "", url);
305
305
  if (v5Compat && listener) {
306
306
  listener({ action, location: history.location, delta: 0 });
@@ -419,7 +419,7 @@ function isUnsupportedLazyRouteFunctionKey(key) {
419
419
  function isIndexRoute(route) {
420
420
  return route.index === true;
421
421
  }
422
- function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [], manifest = {}) {
422
+ function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [], manifest = {}, allowInPlaceMutations = false) {
423
423
  return routes.map((route, index) => {
424
424
  let treePath = [...parentPath, String(index)];
425
425
  let id = typeof route.id === "string" ? route.id : treePath.join("-");
@@ -428,7 +428,7 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [],
428
428
  `Cannot specify children on an index route`
429
429
  );
430
430
  invariant(
431
- !manifest[id],
431
+ allowInPlaceMutations || !manifest[id],
432
432
  `Found a route id collision on id "${id}". Route id's must be globally unique within Data Router usages`
433
433
  );
434
434
  if (isIndexRoute(route)) {
@@ -452,7 +452,8 @@ function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath = [],
452
452
  route.children,
453
453
  mapRouteProperties2,
454
454
  treePath,
455
- manifest
455
+ manifest,
456
+ allowInPlaceMutations
456
457
  );
457
458
  }
458
459
  return pathOrLayoutRoute;
@@ -463,8 +464,8 @@ function matchRoutes(routes, locationArg, basename = "/") {
463
464
  return matchRoutesImpl(routes, locationArg, basename, false);
464
465
  }
465
466
  function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
466
- let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
467
- let pathname = stripBasename(location.pathname || "/", basename);
467
+ let location2 = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
468
+ let pathname = stripBasename(location2.pathname || "/", basename);
468
469
  if (pathname == null) {
469
470
  return null;
470
471
  }
@@ -1072,7 +1073,7 @@ function createRouter(init) {
1072
1073
  let pendingRevalidationDfd = null;
1073
1074
  function initialize() {
1074
1075
  unlistenHistory = init.history.listen(
1075
- ({ action: historyAction, location, delta }) => {
1076
+ ({ action: historyAction, location: location2, delta }) => {
1076
1077
  if (unblockBlockerHistoryUpdate) {
1077
1078
  unblockBlockerHistoryUpdate();
1078
1079
  unblockBlockerHistoryUpdate = void 0;
@@ -1084,7 +1085,7 @@ function createRouter(init) {
1084
1085
  );
1085
1086
  let blockerKey = shouldBlockNavigation({
1086
1087
  currentLocation: state.location,
1087
- nextLocation: location,
1088
+ nextLocation: location2,
1088
1089
  historyAction
1089
1090
  });
1090
1091
  if (blockerKey && delta != null) {
@@ -1094,13 +1095,13 @@ function createRouter(init) {
1094
1095
  init.history.go(delta * -1);
1095
1096
  updateBlocker(blockerKey, {
1096
1097
  state: "blocked",
1097
- location,
1098
+ location: location2,
1098
1099
  proceed() {
1099
1100
  updateBlocker(blockerKey, {
1100
1101
  state: "proceeding",
1101
1102
  proceed: void 0,
1102
1103
  reset: void 0,
1103
- location
1104
+ location: location2
1104
1105
  });
1105
1106
  nextHistoryUpdatePromise.then(() => init.history.go(delta));
1106
1107
  },
@@ -1112,7 +1113,7 @@ function createRouter(init) {
1112
1113
  });
1113
1114
  return;
1114
1115
  }
1115
- return startNavigation(historyAction, location);
1116
+ return startNavigation(historyAction, location2);
1116
1117
  }
1117
1118
  );
1118
1119
  if (isBrowser2) {
@@ -1145,6 +1146,19 @@ function createRouter(init) {
1145
1146
  return () => subscribers.delete(fn);
1146
1147
  }
1147
1148
  function updateState(newState, opts = {}) {
1149
+ if (newState.matches) {
1150
+ newState.matches = newState.matches.map((m) => {
1151
+ let route = manifest[m.route.id];
1152
+ let matchRoute = m.route;
1153
+ if (matchRoute.element !== route.element || matchRoute.errorElement !== route.errorElement || matchRoute.hydrateFallbackElement !== route.hydrateFallbackElement) {
1154
+ return {
1155
+ ...m,
1156
+ route
1157
+ };
1158
+ }
1159
+ return m;
1160
+ });
1161
+ }
1148
1162
  state = {
1149
1163
  ...state,
1150
1164
  ...newState
@@ -1175,8 +1189,8 @@ function createRouter(init) {
1175
1189
  unmountedFetchers.forEach((key) => deleteFetcher(key));
1176
1190
  mountedFetchers.forEach((key) => state.fetchers.delete(key));
1177
1191
  }
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;
1192
+ function completeNavigation(location2, newState, { flushSync: flushSync2 } = {}) {
1193
+ let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && location2.state?._isRedirect !== true;
1180
1194
  let actionData;
1181
1195
  if (newState.actionData) {
1182
1196
  if (Object.keys(newState.actionData).length > 0) {
@@ -1200,7 +1214,7 @@ function createRouter(init) {
1200
1214
  blockers = new Map(blockers);
1201
1215
  blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER));
1202
1216
  }
1203
- let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && location.state?._isRedirect !== true;
1217
+ let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && location2.state?._isRedirect !== true;
1204
1218
  if (inFlightDataRoutes) {
1205
1219
  dataRoutes = inFlightDataRoutes;
1206
1220
  inFlightDataRoutes = void 0;
@@ -1208,35 +1222,35 @@ function createRouter(init) {
1208
1222
  if (isUninterruptedRevalidation) {
1209
1223
  } else if (pendingAction === "POP" /* Pop */) {
1210
1224
  } else if (pendingAction === "PUSH" /* Push */) {
1211
- init.history.push(location, location.state);
1225
+ init.history.push(location2, location2.state);
1212
1226
  } else if (pendingAction === "REPLACE" /* Replace */) {
1213
- init.history.replace(location, location.state);
1227
+ init.history.replace(location2, location2.state);
1214
1228
  }
1215
1229
  let viewTransitionOpts;
1216
1230
  if (pendingAction === "POP" /* Pop */) {
1217
1231
  let priorPaths = appliedViewTransitions.get(state.location.pathname);
1218
- if (priorPaths && priorPaths.has(location.pathname)) {
1232
+ if (priorPaths && priorPaths.has(location2.pathname)) {
1219
1233
  viewTransitionOpts = {
1220
1234
  currentLocation: state.location,
1221
- nextLocation: location
1235
+ nextLocation: location2
1222
1236
  };
1223
- } else if (appliedViewTransitions.has(location.pathname)) {
1237
+ } else if (appliedViewTransitions.has(location2.pathname)) {
1224
1238
  viewTransitionOpts = {
1225
- currentLocation: location,
1239
+ currentLocation: location2,
1226
1240
  nextLocation: state.location
1227
1241
  };
1228
1242
  }
1229
1243
  } else if (pendingViewTransitionEnabled) {
1230
1244
  let toPaths = appliedViewTransitions.get(state.location.pathname);
1231
1245
  if (toPaths) {
1232
- toPaths.add(location.pathname);
1246
+ toPaths.add(location2.pathname);
1233
1247
  } else {
1234
- toPaths = /* @__PURE__ */ new Set([location.pathname]);
1248
+ toPaths = /* @__PURE__ */ new Set([location2.pathname]);
1235
1249
  appliedViewTransitions.set(state.location.pathname, toPaths);
1236
1250
  }
1237
1251
  viewTransitionOpts = {
1238
1252
  currentLocation: state.location,
1239
- nextLocation: location
1253
+ nextLocation: location2
1240
1254
  };
1241
1255
  }
1242
1256
  updateState(
@@ -1246,12 +1260,12 @@ function createRouter(init) {
1246
1260
  actionData,
1247
1261
  loaderData,
1248
1262
  historyAction: pendingAction,
1249
- location,
1263
+ location: location2,
1250
1264
  initialized: true,
1251
1265
  navigation: IDLE_NAVIGATION,
1252
1266
  revalidation: "idle",
1253
1267
  restoreScrollPosition: getSavedScrollPosition(
1254
- location,
1268
+ location2,
1255
1269
  newState.matches || state.matches
1256
1270
  ),
1257
1271
  preventScrollReset,
@@ -1259,7 +1273,7 @@ function createRouter(init) {
1259
1273
  },
1260
1274
  {
1261
1275
  viewTransitionOpts,
1262
- flushSync: flushSync === true
1276
+ flushSync: flushSync2 === true
1263
1277
  }
1264
1278
  );
1265
1279
  pendingAction = "POP" /* Pop */;
@@ -1303,7 +1317,7 @@ function createRouter(init) {
1303
1317
  historyAction = "REPLACE" /* Replace */;
1304
1318
  }
1305
1319
  let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : void 0;
1306
- let flushSync = (opts && opts.flushSync) === true;
1320
+ let flushSync2 = (opts && opts.flushSync) === true;
1307
1321
  let blockerKey = shouldBlockNavigation({
1308
1322
  currentLocation,
1309
1323
  nextLocation,
@@ -1338,7 +1352,7 @@ function createRouter(init) {
1338
1352
  preventScrollReset,
1339
1353
  replace: opts && opts.replace,
1340
1354
  enableViewTransition: opts && opts.viewTransition,
1341
- flushSync
1355
+ flushSync: flushSync2
1342
1356
  });
1343
1357
  }
1344
1358
  function revalidate() {
@@ -1368,7 +1382,7 @@ function createRouter(init) {
1368
1382
  );
1369
1383
  return promise;
1370
1384
  }
1371
- async function startNavigation(historyAction, location, opts) {
1385
+ async function startNavigation(historyAction, location2, opts) {
1372
1386
  pendingNavigationController && pendingNavigationController.abort();
1373
1387
  pendingNavigationController = null;
1374
1388
  pendingAction = historyAction;
@@ -1381,22 +1395,22 @@ function createRouter(init) {
1381
1395
  let matches = opts?.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ? (
1382
1396
  // `matchRoutes()` has already been called if we're in here via `router.initialize()`
1383
1397
  state.matches
1384
- ) : matchRoutes(routesToUse, location, basename);
1385
- let flushSync = (opts && opts.flushSync) === true;
1386
- if (matches && state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
1387
- completeNavigation(location, { matches }, { flushSync });
1398
+ ) : matchRoutes(routesToUse, location2, basename);
1399
+ let flushSync2 = (opts && opts.flushSync) === true;
1400
+ if (matches && state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location2) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
1401
+ completeNavigation(location2, { matches }, { flushSync: flushSync2 });
1388
1402
  return;
1389
1403
  }
1390
- let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
1404
+ let fogOfWar = checkFogOfWar(matches, routesToUse, location2.pathname);
1391
1405
  if (fogOfWar.active && fogOfWar.matches) {
1392
1406
  matches = fogOfWar.matches;
1393
1407
  }
1394
1408
  if (!matches) {
1395
1409
  let { error, notFoundMatches, route } = handleNavigational404(
1396
- location.pathname
1410
+ location2.pathname
1397
1411
  );
1398
1412
  completeNavigation(
1399
- location,
1413
+ location2,
1400
1414
  {
1401
1415
  matches: notFoundMatches,
1402
1416
  loaderData: {},
@@ -1404,14 +1418,14 @@ function createRouter(init) {
1404
1418
  [route.id]: error
1405
1419
  }
1406
1420
  },
1407
- { flushSync }
1421
+ { flushSync: flushSync2 }
1408
1422
  );
1409
1423
  return;
1410
1424
  }
1411
1425
  pendingNavigationController = new AbortController();
1412
1426
  let request = createClientSideRequest(
1413
1427
  init.history,
1414
- location,
1428
+ location2,
1415
1429
  pendingNavigationController.signal,
1416
1430
  opts && opts.submission
1417
1431
  );
@@ -1427,13 +1441,13 @@ function createRouter(init) {
1427
1441
  } else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
1428
1442
  let actionResult = await handleAction(
1429
1443
  request,
1430
- location,
1444
+ location2,
1431
1445
  opts.submission,
1432
1446
  matches,
1433
1447
  scopedContext,
1434
1448
  fogOfWar.active,
1435
1449
  opts && opts.initialHydration === true,
1436
- { replace: opts.replace, flushSync }
1450
+ { replace: opts.replace, flushSync: flushSync2 }
1437
1451
  );
1438
1452
  if (actionResult.shortCircuited) {
1439
1453
  return;
@@ -1442,7 +1456,7 @@ function createRouter(init) {
1442
1456
  let [routeId, result] = actionResult.pendingActionResult;
1443
1457
  if (isErrorResult(result) && isRouteErrorResponse(result.error) && result.error.status === 404) {
1444
1458
  pendingNavigationController = null;
1445
- completeNavigation(location, {
1459
+ completeNavigation(location2, {
1446
1460
  matches: actionResult.matches,
1447
1461
  loaderData: {},
1448
1462
  errors: {
@@ -1454,8 +1468,8 @@ function createRouter(init) {
1454
1468
  }
1455
1469
  matches = actionResult.matches || matches;
1456
1470
  pendingActionResult = actionResult.pendingActionResult;
1457
- loadingNavigation = getLoadingNavigation(location, opts.submission);
1458
- flushSync = false;
1471
+ loadingNavigation = getLoadingNavigation(location2, opts.submission);
1472
+ flushSync2 = false;
1459
1473
  fogOfWar.active = false;
1460
1474
  request = createClientSideRequest(
1461
1475
  init.history,
@@ -1470,7 +1484,7 @@ function createRouter(init) {
1470
1484
  errors
1471
1485
  } = await handleLoaders(
1472
1486
  request,
1473
- location,
1487
+ location2,
1474
1488
  matches,
1475
1489
  scopedContext,
1476
1490
  fogOfWar.active,
@@ -1479,28 +1493,28 @@ function createRouter(init) {
1479
1493
  opts && opts.fetcherSubmission,
1480
1494
  opts && opts.replace,
1481
1495
  opts && opts.initialHydration === true,
1482
- flushSync,
1496
+ flushSync2,
1483
1497
  pendingActionResult
1484
1498
  );
1485
1499
  if (shortCircuited) {
1486
1500
  return;
1487
1501
  }
1488
1502
  pendingNavigationController = null;
1489
- completeNavigation(location, {
1503
+ completeNavigation(location2, {
1490
1504
  matches: updatedMatches || matches,
1491
1505
  ...getActionDataForCommit(pendingActionResult),
1492
1506
  loaderData,
1493
1507
  errors
1494
1508
  });
1495
1509
  }
1496
- async function handleAction(request, location, submission, matches, scopedContext, isFogOfWar, initialHydration, opts = {}) {
1510
+ async function handleAction(request, location2, submission, matches, scopedContext, isFogOfWar, initialHydration, opts = {}) {
1497
1511
  interruptActiveLoads();
1498
- let navigation = getSubmittingNavigation(location, submission);
1512
+ let navigation = getSubmittingNavigation(location2, submission);
1499
1513
  updateState({ navigation }, { flushSync: opts.flushSync === true });
1500
1514
  if (isFogOfWar) {
1501
1515
  let discoverResult = await discoverRoutes(
1502
1516
  matches,
1503
- location.pathname,
1517
+ location2.pathname,
1504
1518
  request.signal
1505
1519
  );
1506
1520
  if (discoverResult.type === "aborted") {
@@ -1519,7 +1533,7 @@ function createRouter(init) {
1519
1533
  };
1520
1534
  } else if (!discoverResult.matches) {
1521
1535
  let { notFoundMatches, error, route } = handleNavigational404(
1522
- location.pathname
1536
+ location2.pathname
1523
1537
  );
1524
1538
  return {
1525
1539
  matches: notFoundMatches,
@@ -1536,13 +1550,13 @@ function createRouter(init) {
1536
1550
  }
1537
1551
  }
1538
1552
  let result;
1539
- let actionMatch = getTargetMatch(matches, location);
1553
+ let actionMatch = getTargetMatch(matches, location2);
1540
1554
  if (!actionMatch.route.action && !actionMatch.route.lazy) {
1541
1555
  result = {
1542
1556
  type: "error" /* error */,
1543
1557
  error: getInternalRouterError(405, {
1544
1558
  method: request.method,
1545
- pathname: location.pathname,
1559
+ pathname: location2.pathname,
1546
1560
  routeId: actionMatch.route.id
1547
1561
  })
1548
1562
  };
@@ -1580,12 +1594,12 @@ function createRouter(init) {
1580
1594
  if (opts && opts.replace != null) {
1581
1595
  replace2 = opts.replace;
1582
1596
  } else {
1583
- let location2 = normalizeRedirectLocation(
1597
+ let location3 = normalizeRedirectLocation(
1584
1598
  result.response.headers.get("Location"),
1585
1599
  new URL(request.url),
1586
1600
  basename
1587
1601
  );
1588
- replace2 = location2 === state.location.pathname + state.location.search;
1602
+ replace2 = location3 === state.location.pathname + state.location.search;
1589
1603
  }
1590
1604
  await startRedirectNavigation(request, result, true, {
1591
1605
  submission,
@@ -1612,8 +1626,8 @@ function createRouter(init) {
1612
1626
  pendingActionResult: [actionMatch.route.id, result]
1613
1627
  };
1614
1628
  }
1615
- async function handleLoaders(request, location, matches, scopedContext, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
1616
- let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
1629
+ async function handleLoaders(request, location2, matches, scopedContext, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync2, pendingActionResult) {
1630
+ let loadingNavigation = overrideNavigation || getLoadingNavigation(location2, submission);
1617
1631
  let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
1618
1632
  let shouldUpdateNavigationState = !isUninterruptedRevalidation && !initialHydration;
1619
1633
  if (isFogOfWar) {
@@ -1625,13 +1639,13 @@ function createRouter(init) {
1625
1639
  ...actionData !== void 0 ? { actionData } : {}
1626
1640
  },
1627
1641
  {
1628
- flushSync
1642
+ flushSync: flushSync2
1629
1643
  }
1630
1644
  );
1631
1645
  }
1632
1646
  let discoverResult = await discoverRoutes(
1633
1647
  matches,
1634
- location.pathname,
1648
+ location2.pathname,
1635
1649
  request.signal
1636
1650
  );
1637
1651
  if (discoverResult.type === "aborted") {
@@ -1647,7 +1661,7 @@ function createRouter(init) {
1647
1661
  };
1648
1662
  } else if (!discoverResult.matches) {
1649
1663
  let { error, notFoundMatches, route } = handleNavigational404(
1650
- location.pathname
1664
+ location2.pathname
1651
1665
  );
1652
1666
  return {
1653
1667
  matches: notFoundMatches,
@@ -1670,7 +1684,7 @@ function createRouter(init) {
1670
1684
  state,
1671
1685
  matches,
1672
1686
  activeSubmission,
1673
- location,
1687
+ location2,
1674
1688
  initialHydration ? [] : hydrationRouteProperties2,
1675
1689
  initialHydration === true,
1676
1690
  isRevalidationRequired,
@@ -1687,7 +1701,7 @@ function createRouter(init) {
1687
1701
  if (!init.dataStrategy && !dsMatches.some((m) => m.shouldLoad) && revalidatingFetchers.length === 0) {
1688
1702
  let updatedFetchers2 = markFetchRedirectsDone();
1689
1703
  completeNavigation(
1690
- location,
1704
+ location2,
1691
1705
  {
1692
1706
  matches,
1693
1707
  loaderData: {},
@@ -1696,7 +1710,7 @@ function createRouter(init) {
1696
1710
  ...getActionDataForCommit(pendingActionResult),
1697
1711
  ...updatedFetchers2 ? { fetchers: new Map(state.fetchers) } : {}
1698
1712
  },
1699
- { flushSync }
1713
+ { flushSync: flushSync2 }
1700
1714
  );
1701
1715
  return { shortCircuited: true };
1702
1716
  }
@@ -1712,7 +1726,7 @@ function createRouter(init) {
1712
1726
  if (revalidatingFetchers.length > 0) {
1713
1727
  updates.fetchers = getUpdatedRevalidatingFetchers(revalidatingFetchers);
1714
1728
  }
1715
- updateState(updates, { flushSync });
1729
+ updateState(updates, { flushSync: flushSync2 });
1716
1730
  }
1717
1731
  revalidatingFetchers.forEach((rf) => {
1718
1732
  abortFetcher(rf.key);
@@ -1805,7 +1819,7 @@ function createRouter(init) {
1805
1819
  }
1806
1820
  async function fetch2(key, routeId, href2, opts) {
1807
1821
  abortFetcher(key);
1808
- let flushSync = (opts && opts.flushSync) === true;
1822
+ let flushSync2 = (opts && opts.flushSync) === true;
1809
1823
  let routesToUse = inFlightDataRoutes || dataRoutes;
1810
1824
  let normalizedPath = normalizeTo(
1811
1825
  state.location,
@@ -1825,7 +1839,7 @@ function createRouter(init) {
1825
1839
  key,
1826
1840
  routeId,
1827
1841
  getInternalRouterError(404, { pathname: normalizedPath }),
1828
- { flushSync }
1842
+ { flushSync: flushSync2 }
1829
1843
  );
1830
1844
  return;
1831
1845
  }
@@ -1835,10 +1849,9 @@ function createRouter(init) {
1835
1849
  opts
1836
1850
  );
1837
1851
  if (error) {
1838
- setFetcherError(key, routeId, error, { flushSync });
1852
+ setFetcherError(key, routeId, error, { flushSync: flushSync2 });
1839
1853
  return;
1840
1854
  }
1841
- let match = getTargetMatch(matches, path);
1842
1855
  let scopedContext = new unstable_RouterContextProvider(
1843
1856
  init.unstable_getContext ? await init.unstable_getContext() : void 0
1844
1857
  );
@@ -1848,11 +1861,10 @@ function createRouter(init) {
1848
1861
  key,
1849
1862
  routeId,
1850
1863
  path,
1851
- match,
1852
1864
  matches,
1853
1865
  scopedContext,
1854
1866
  fogOfWar.active,
1855
- flushSync,
1867
+ flushSync2,
1856
1868
  preventScrollReset,
1857
1869
  submission
1858
1870
  );
@@ -1863,36 +1875,20 @@ function createRouter(init) {
1863
1875
  key,
1864
1876
  routeId,
1865
1877
  path,
1866
- match,
1867
1878
  matches,
1868
1879
  scopedContext,
1869
1880
  fogOfWar.active,
1870
- flushSync,
1881
+ flushSync2,
1871
1882
  preventScrollReset,
1872
1883
  submission
1873
1884
  );
1874
1885
  }
1875
- async function handleFetcherAction(key, routeId, path, match, requestMatches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission) {
1886
+ async function handleFetcherAction(key, routeId, path, requestMatches, scopedContext, isFogOfWar, flushSync2, preventScrollReset, submission) {
1876
1887
  interruptActiveLoads();
1877
1888
  fetchLoadMatches.delete(key);
1878
- function detectAndHandle405Error(m) {
1879
- if (!m.route.action && !m.route.lazy) {
1880
- let error = getInternalRouterError(405, {
1881
- method: submission.formMethod,
1882
- pathname: path,
1883
- routeId
1884
- });
1885
- setFetcherError(key, routeId, error, { flushSync });
1886
- return true;
1887
- }
1888
- return false;
1889
- }
1890
- if (!isFogOfWar && detectAndHandle405Error(match)) {
1891
- return;
1892
- }
1893
1889
  let existingFetcher = state.fetchers.get(key);
1894
1890
  updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), {
1895
- flushSync
1891
+ flushSync: flushSync2
1896
1892
  });
1897
1893
  let abortController = new AbortController();
1898
1894
  let fetchRequest = createClientSideRequest(
@@ -1911,24 +1907,30 @@ function createRouter(init) {
1911
1907
  if (discoverResult.type === "aborted") {
1912
1908
  return;
1913
1909
  } else if (discoverResult.type === "error") {
1914
- setFetcherError(key, routeId, discoverResult.error, { flushSync });
1910
+ setFetcherError(key, routeId, discoverResult.error, { flushSync: flushSync2 });
1915
1911
  return;
1916
1912
  } else if (!discoverResult.matches) {
1917
1913
  setFetcherError(
1918
1914
  key,
1919
1915
  routeId,
1920
1916
  getInternalRouterError(404, { pathname: path }),
1921
- { flushSync }
1917
+ { flushSync: flushSync2 }
1922
1918
  );
1923
1919
  return;
1924
1920
  } else {
1925
1921
  requestMatches = discoverResult.matches;
1926
- match = getTargetMatch(requestMatches, path);
1927
- if (detectAndHandle405Error(match)) {
1928
- return;
1929
- }
1930
1922
  }
1931
1923
  }
1924
+ let match = getTargetMatch(requestMatches, path);
1925
+ if (!match.route.action && !match.route.lazy) {
1926
+ let error = getInternalRouterError(405, {
1927
+ method: submission.formMethod,
1928
+ pathname: path,
1929
+ routeId
1930
+ });
1931
+ setFetcherError(key, routeId, error, { flushSync: flushSync2 });
1932
+ return;
1933
+ }
1932
1934
  fetchControllers.set(key, abortController);
1933
1935
  let originatingLoadId = incrementingLoadId;
1934
1936
  let fetchMatches = getTargetedDataStrategyMatches(
@@ -2103,7 +2105,7 @@ function createRouter(init) {
2103
2105
  isRevalidationRequired = false;
2104
2106
  }
2105
2107
  }
2106
- async function handleFetcherLoader(key, routeId, path, match, matches, scopedContext, isFogOfWar, flushSync, preventScrollReset, submission) {
2108
+ async function handleFetcherLoader(key, routeId, path, matches, scopedContext, isFogOfWar, flushSync2, preventScrollReset, submission) {
2107
2109
  let existingFetcher = state.fetchers.get(key);
2108
2110
  updateFetcherState(
2109
2111
  key,
@@ -2111,7 +2113,7 @@ function createRouter(init) {
2111
2113
  submission,
2112
2114
  existingFetcher ? existingFetcher.data : void 0
2113
2115
  ),
2114
- { flushSync }
2116
+ { flushSync: flushSync2 }
2115
2117
  );
2116
2118
  let abortController = new AbortController();
2117
2119
  let fetchRequest = createClientSideRequest(
@@ -2129,21 +2131,21 @@ function createRouter(init) {
2129
2131
  if (discoverResult.type === "aborted") {
2130
2132
  return;
2131
2133
  } else if (discoverResult.type === "error") {
2132
- setFetcherError(key, routeId, discoverResult.error, { flushSync });
2134
+ setFetcherError(key, routeId, discoverResult.error, { flushSync: flushSync2 });
2133
2135
  return;
2134
2136
  } else if (!discoverResult.matches) {
2135
2137
  setFetcherError(
2136
2138
  key,
2137
2139
  routeId,
2138
2140
  getInternalRouterError(404, { pathname: path }),
2139
- { flushSync }
2141
+ { flushSync: flushSync2 }
2140
2142
  );
2141
2143
  return;
2142
2144
  } else {
2143
2145
  matches = discoverResult.matches;
2144
- match = getTargetMatch(matches, path);
2145
2146
  }
2146
2147
  }
2148
+ let match = getTargetMatch(matches, path);
2147
2149
  fetchControllers.set(key, abortController);
2148
2150
  let originatingLoadId = incrementingLoadId;
2149
2151
  let dsMatches = getTargetedDataStrategyMatches(
@@ -2199,31 +2201,31 @@ function createRouter(init) {
2199
2201
  if (redirect2.response.headers.has("X-Remix-Revalidate")) {
2200
2202
  isRevalidationRequired = true;
2201
2203
  }
2202
- let location = redirect2.response.headers.get("Location");
2203
- invariant(location, "Expected a Location header on the redirect Response");
2204
- location = normalizeRedirectLocation(
2205
- location,
2204
+ let location2 = redirect2.response.headers.get("Location");
2205
+ invariant(location2, "Expected a Location header on the redirect Response");
2206
+ location2 = normalizeRedirectLocation(
2207
+ location2,
2206
2208
  new URL(request.url),
2207
2209
  basename
2208
2210
  );
2209
- let redirectLocation = createLocation(state.location, location, {
2211
+ let redirectLocation = createLocation(state.location, location2, {
2210
2212
  _isRedirect: true
2211
2213
  });
2212
2214
  if (isBrowser2) {
2213
2215
  let isDocumentReload = false;
2214
2216
  if (redirect2.response.headers.has("X-Remix-Reload-Document")) {
2215
2217
  isDocumentReload = true;
2216
- } else if (ABSOLUTE_URL_REGEX.test(location)) {
2217
- const url = createBrowserURLImpl(location, true);
2218
+ } else if (ABSOLUTE_URL_REGEX.test(location2)) {
2219
+ const url = createBrowserURLImpl(location2, true);
2218
2220
  isDocumentReload = // Hard reload if it's an absolute URL to a new origin
2219
2221
  url.origin !== routerWindow.location.origin || // Hard reload if it's an absolute URL that does not match our basename
2220
2222
  stripBasename(url.pathname, basename) == null;
2221
2223
  }
2222
2224
  if (isDocumentReload) {
2223
2225
  if (replace2) {
2224
- routerWindow.location.replace(location);
2226
+ routerWindow.location.replace(location2);
2225
2227
  } else {
2226
- routerWindow.location.assign(location);
2228
+ routerWindow.location.assign(location2);
2227
2229
  }
2228
2230
  return;
2229
2231
  }
@@ -2239,7 +2241,7 @@ function createRouter(init) {
2239
2241
  await startNavigation(redirectNavigationType, redirectLocation, {
2240
2242
  submission: {
2241
2243
  ...activeSubmission,
2242
- formAction: location
2244
+ formAction: location2
2243
2245
  },
2244
2246
  // Preserve these flags across redirects
2245
2247
  preventScrollReset: preventScrollReset || pendingPreventScrollReset,
@@ -2513,25 +2515,25 @@ function createRouter(init) {
2513
2515
  getScrollRestorationKey2 = null;
2514
2516
  };
2515
2517
  }
2516
- function getScrollKey(location, matches) {
2518
+ function getScrollKey(location2, matches) {
2517
2519
  if (getScrollRestorationKey2) {
2518
2520
  let key = getScrollRestorationKey2(
2519
- location,
2521
+ location2,
2520
2522
  matches.map((m) => convertRouteMatchToUiMatch(m, state.loaderData))
2521
2523
  );
2522
- return key || location.key;
2524
+ return key || location2.key;
2523
2525
  }
2524
- return location.key;
2526
+ return location2.key;
2525
2527
  }
2526
- function saveScrollPosition(location, matches) {
2528
+ function saveScrollPosition(location2, matches) {
2527
2529
  if (savedScrollPositions2 && getScrollPosition) {
2528
- let key = getScrollKey(location, matches);
2530
+ let key = getScrollKey(location2, matches);
2529
2531
  savedScrollPositions2[key] = getScrollPosition();
2530
2532
  }
2531
2533
  }
2532
- function getSavedScrollPosition(location, matches) {
2534
+ function getSavedScrollPosition(location2, matches) {
2533
2535
  if (savedScrollPositions2) {
2534
- let key = getScrollKey(location, matches);
2536
+ let key = getScrollKey(location2, matches);
2535
2537
  let y = savedScrollPositions2[key];
2536
2538
  if (typeof y === "number") {
2537
2539
  return y;
@@ -2585,7 +2587,8 @@ function createRouter(init) {
2585
2587
  children,
2586
2588
  routesToUse,
2587
2589
  localManifest,
2588
- mapRouteProperties2
2590
+ mapRouteProperties2,
2591
+ false
2589
2592
  );
2590
2593
  }
2591
2594
  });
@@ -2626,7 +2629,7 @@ function createRouter(init) {
2626
2629
  manifest
2627
2630
  );
2628
2631
  }
2629
- function patchRoutes(routeId, children) {
2632
+ function patchRoutes(routeId, children, unstable_allowElementMutations = false) {
2630
2633
  let isNonHMR = inFlightDataRoutes == null;
2631
2634
  let routesToUse = inFlightDataRoutes || dataRoutes;
2632
2635
  patchRoutesImpl(
@@ -2634,7 +2637,8 @@ function createRouter(init) {
2634
2637
  children,
2635
2638
  routesToUse,
2636
2639
  manifest,
2637
- mapRouteProperties2
2640
+ mapRouteProperties2,
2641
+ unstable_allowElementMutations
2638
2642
  );
2639
2643
  if (isNonHMR) {
2640
2644
  dataRoutes = [...dataRoutes];
@@ -2676,7 +2680,10 @@ function createRouter(init) {
2676
2680
  _internalFetchControllers: fetchControllers,
2677
2681
  // TODO: Remove setRoutes, it's temporary to avoid dealing with
2678
2682
  // updating the tree while validating the update algorithm.
2679
- _internalSetRoutes
2683
+ _internalSetRoutes,
2684
+ _internalSetStateDoNotUseOrYouWillBreakYourApp(newState) {
2685
+ updateState(newState);
2686
+ }
2680
2687
  };
2681
2688
  return router;
2682
2689
  }
@@ -2700,19 +2707,26 @@ function createStaticHandler(routes, opts) {
2700
2707
  skipLoaderErrorBubbling,
2701
2708
  skipRevalidation,
2702
2709
  dataStrategy,
2710
+ unstable_stream: stream,
2703
2711
  unstable_respond: respond
2704
2712
  } = {}) {
2705
2713
  let url = new URL(request.url);
2706
2714
  let method = request.method;
2707
- let location = createLocation("", createPath(url), null, "default");
2708
- let matches = matchRoutes(dataRoutes, location, basename);
2715
+ let location2 = createLocation("", createPath(url), null, "default");
2716
+ let matches = matchRoutes(dataRoutes, location2, basename);
2709
2717
  requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
2718
+ let respondOrStreamStaticContext = (ctx) => {
2719
+ return stream ? stream(
2720
+ requestContext,
2721
+ () => Promise.resolve(ctx)
2722
+ ) : respond ? respond(ctx) : void 0;
2723
+ };
2710
2724
  if (!isValidMethod(method) && method !== "HEAD") {
2711
2725
  let error = getInternalRouterError(405, { method });
2712
2726
  let { matches: methodNotAllowedMatches, route } = getShortCircuitMatches(dataRoutes);
2713
2727
  let staticContext = {
2714
2728
  basename,
2715
- location,
2729
+ location: location2,
2716
2730
  matches: methodNotAllowedMatches,
2717
2731
  loaderData: {},
2718
2732
  actionData: null,
@@ -2723,13 +2737,13 @@ function createStaticHandler(routes, opts) {
2723
2737
  loaderHeaders: {},
2724
2738
  actionHeaders: {}
2725
2739
  };
2726
- return respond ? respond(staticContext) : staticContext;
2740
+ return respondOrStreamStaticContext(staticContext) || staticContext;
2727
2741
  } else if (!matches) {
2728
- let error = getInternalRouterError(404, { pathname: location.pathname });
2742
+ let error = getInternalRouterError(404, { pathname: location2.pathname });
2729
2743
  let { matches: notFoundMatches, route } = getShortCircuitMatches(dataRoutes);
2730
2744
  let staticContext = {
2731
2745
  basename,
2732
- location,
2746
+ location: location2,
2733
2747
  matches: notFoundMatches,
2734
2748
  loaderData: {},
2735
2749
  actionData: null,
@@ -2740,9 +2754,9 @@ function createStaticHandler(routes, opts) {
2740
2754
  loaderHeaders: {},
2741
2755
  actionHeaders: {}
2742
2756
  };
2743
- return respond ? respond(staticContext) : staticContext;
2757
+ return respondOrStreamStaticContext(staticContext) || staticContext;
2744
2758
  }
2745
- if (respond && matches.some(
2759
+ if (stream || respond && matches.some(
2746
2760
  (m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
2747
2761
  )) {
2748
2762
  invariant(
@@ -2767,9 +2781,30 @@ function createStaticHandler(routes, opts) {
2767
2781
  },
2768
2782
  true,
2769
2783
  async () => {
2784
+ if (stream) {
2785
+ let res2 = await stream(
2786
+ requestContext,
2787
+ async (revalidationRequest) => {
2788
+ let result3 = await queryImpl(
2789
+ revalidationRequest,
2790
+ location2,
2791
+ matches,
2792
+ requestContext,
2793
+ dataStrategy || null,
2794
+ skipLoaderErrorBubbling === true,
2795
+ null,
2796
+ filterMatchesToLoad || null,
2797
+ skipRevalidation === true
2798
+ );
2799
+ return isResponse(result3) ? result3 : { location: location2, basename, ...result3 };
2800
+ }
2801
+ );
2802
+ return res2;
2803
+ }
2804
+ invariant(respond, "Expected respond to be defined");
2770
2805
  let result2 = await queryImpl(
2771
2806
  request,
2772
- location,
2807
+ location2,
2773
2808
  matches,
2774
2809
  requestContext,
2775
2810
  dataStrategy || null,
@@ -2781,7 +2816,7 @@ function createStaticHandler(routes, opts) {
2781
2816
  if (isResponse(result2)) {
2782
2817
  return result2;
2783
2818
  }
2784
- renderedStaticContext = { location, basename, ...result2 };
2819
+ renderedStaticContext = { location: location2, basename, ...result2 };
2785
2820
  let res = await respond(renderedStaticContext);
2786
2821
  return res;
2787
2822
  },
@@ -2793,14 +2828,13 @@ function createStaticHandler(routes, opts) {
2793
2828
  if (routeId in renderedStaticContext.loaderData) {
2794
2829
  renderedStaticContext.loaderData[routeId] = void 0;
2795
2830
  }
2796
- return respond(
2797
- getStaticContextFromError(
2798
- dataRoutes,
2799
- renderedStaticContext,
2800
- error,
2801
- skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
2802
- )
2831
+ let staticContext = getStaticContextFromError(
2832
+ dataRoutes,
2833
+ renderedStaticContext,
2834
+ error,
2835
+ skipLoaderErrorBubbling ? routeId : findNearestBoundary(matches, routeId).route.id
2803
2836
  );
2837
+ return respondOrStreamStaticContext(staticContext) || staticContext;
2804
2838
  } else {
2805
2839
  let boundaryRouteId = skipLoaderErrorBubbling ? routeId : findNearestBoundary(
2806
2840
  matches,
@@ -2808,9 +2842,9 @@ function createStaticHandler(routes, opts) {
2808
2842
  (m) => m.route.id === routeId || m.route.loader
2809
2843
  )?.route.id || routeId
2810
2844
  ).route.id;
2811
- return respond({
2845
+ let staticContext = {
2812
2846
  matches,
2813
- location,
2847
+ location: location2,
2814
2848
  basename,
2815
2849
  loaderData: {},
2816
2850
  actionData: null,
@@ -2820,7 +2854,8 @@ function createStaticHandler(routes, opts) {
2820
2854
  statusCode: isRouteErrorResponse(error) ? error.status : 500,
2821
2855
  actionHeaders: {},
2822
2856
  loaderHeaders: {}
2823
- });
2857
+ };
2858
+ return respondOrStreamStaticContext(staticContext) || staticContext;
2824
2859
  }
2825
2860
  }
2826
2861
  );
@@ -2835,7 +2870,7 @@ function createStaticHandler(routes, opts) {
2835
2870
  }
2836
2871
  let result = await queryImpl(
2837
2872
  request,
2838
- location,
2873
+ location2,
2839
2874
  matches,
2840
2875
  requestContext,
2841
2876
  dataStrategy || null,
@@ -2847,7 +2882,7 @@ function createStaticHandler(routes, opts) {
2847
2882
  if (isResponse(result)) {
2848
2883
  return result;
2849
2884
  }
2850
- return { location, basename, ...result };
2885
+ return { location: location2, basename, ...result };
2851
2886
  }
2852
2887
  async function queryRoute(request, {
2853
2888
  routeId,
@@ -2857,22 +2892,22 @@ function createStaticHandler(routes, opts) {
2857
2892
  } = {}) {
2858
2893
  let url = new URL(request.url);
2859
2894
  let method = request.method;
2860
- let location = createLocation("", createPath(url), null, "default");
2861
- let matches = matchRoutes(dataRoutes, location, basename);
2895
+ let location2 = createLocation("", createPath(url), null, "default");
2896
+ let matches = matchRoutes(dataRoutes, location2, basename);
2862
2897
  requestContext = requestContext != null ? requestContext : new unstable_RouterContextProvider();
2863
2898
  if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") {
2864
2899
  throw getInternalRouterError(405, { method });
2865
2900
  } else if (!matches) {
2866
- throw getInternalRouterError(404, { pathname: location.pathname });
2901
+ throw getInternalRouterError(404, { pathname: location2.pathname });
2867
2902
  }
2868
- let match = routeId ? matches.find((m) => m.route.id === routeId) : getTargetMatch(matches, location);
2903
+ let match = routeId ? matches.find((m) => m.route.id === routeId) : getTargetMatch(matches, location2);
2869
2904
  if (routeId && !match) {
2870
2905
  throw getInternalRouterError(403, {
2871
- pathname: location.pathname,
2906
+ pathname: location2.pathname,
2872
2907
  routeId
2873
2908
  });
2874
2909
  } else if (!match) {
2875
- throw getInternalRouterError(404, { pathname: location.pathname });
2910
+ throw getInternalRouterError(404, { pathname: location2.pathname });
2876
2911
  }
2877
2912
  if (respond && matches.some(
2878
2913
  (m) => m.route.unstable_middleware || typeof m.route.lazy === "object" && m.route.lazy.unstable_middleware
@@ -2895,7 +2930,7 @@ function createStaticHandler(routes, opts) {
2895
2930
  async () => {
2896
2931
  let result2 = await queryImpl(
2897
2932
  request,
2898
- location,
2933
+ location2,
2899
2934
  matches,
2900
2935
  requestContext,
2901
2936
  dataStrategy || null,
@@ -2928,7 +2963,7 @@ function createStaticHandler(routes, opts) {
2928
2963
  }
2929
2964
  let result = await queryImpl(
2930
2965
  request,
2931
- location,
2966
+ location2,
2932
2967
  matches,
2933
2968
  requestContext,
2934
2969
  dataStrategy || null,
@@ -2952,7 +2987,7 @@ function createStaticHandler(routes, opts) {
2952
2987
  }
2953
2988
  return void 0;
2954
2989
  }
2955
- async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
2990
+ async function queryImpl(request, location2, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, filterMatchesToLoad, skipRevalidation) {
2956
2991
  invariant(
2957
2992
  request.signal,
2958
2993
  "query()/queryRoute() requests must contain an AbortController signal"
@@ -2962,7 +2997,7 @@ function createStaticHandler(routes, opts) {
2962
2997
  let result2 = await submit(
2963
2998
  request,
2964
2999
  matches,
2965
- routeMatch || getTargetMatch(matches, location),
3000
+ routeMatch || getTargetMatch(matches, location2),
2966
3001
  requestContext,
2967
3002
  dataStrategy,
2968
3003
  skipLoaderErrorBubbling,
@@ -3278,7 +3313,7 @@ function throwStaticHandlerAbortedError(request, isRouteRequest) {
3278
3313
  function isSubmissionNavigation(opts) {
3279
3314
  return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== void 0);
3280
3315
  }
3281
- function normalizeTo(location, matches, basename, to, fromRouteId, relative) {
3316
+ function normalizeTo(location2, matches, basename, to, fromRouteId, relative) {
3282
3317
  let contextualMatches;
3283
3318
  let activeRouteMatch;
3284
3319
  if (fromRouteId) {
@@ -3297,12 +3332,12 @@ function normalizeTo(location, matches, basename, to, fromRouteId, relative) {
3297
3332
  let path = resolveTo(
3298
3333
  to ? to : ".",
3299
3334
  getResolveToMatches(contextualMatches),
3300
- stripBasename(location.pathname, basename) || location.pathname,
3335
+ stripBasename(location2.pathname, basename) || location2.pathname,
3301
3336
  relative === "path"
3302
3337
  );
3303
3338
  if (to == null) {
3304
- path.search = location.search;
3305
- path.hash = location.hash;
3339
+ path.search = location2.search;
3340
+ path.hash = location2.hash;
3306
3341
  }
3307
3342
  if ((to == null || to === "" || to === ".") && activeRouteMatch) {
3308
3343
  let nakedIndex = hasNakedIndexQuery(path.search);
@@ -3429,10 +3464,10 @@ function normalizeNavigateOptions(isFetcher, path, opts) {
3429
3464
  parsedPath.search = `?${searchParams}`;
3430
3465
  return { path: createPath(parsedPath), submission };
3431
3466
  }
3432
- function getMatchesToLoad(request, scopedContext, mapRouteProperties2, manifest, history, state, matches, submission, location, lazyRoutePropertiesToSkip, initialHydration, isRevalidationRequired, cancelledFetcherLoads, fetchersQueuedForDeletion, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, hasPatchRoutesOnNavigation, pendingActionResult) {
3467
+ function getMatchesToLoad(request, scopedContext, mapRouteProperties2, manifest, history, state, matches, submission, location2, lazyRoutePropertiesToSkip, initialHydration, isRevalidationRequired, cancelledFetcherLoads, fetchersQueuedForDeletion, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, hasPatchRoutesOnNavigation, pendingActionResult) {
3433
3468
  let actionResult = pendingActionResult ? isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : pendingActionResult[1].data : void 0;
3434
3469
  let currentUrl = history.createURL(state.location);
3435
- let nextUrl = history.createURL(location);
3470
+ let nextUrl = history.createURL(location2);
3436
3471
  let maxIdx;
3437
3472
  if (initialHydration && state.errors) {
3438
3473
  let boundaryId = Object.keys(state.errors)[0];
@@ -3635,7 +3670,7 @@ function shouldRevalidateLoader(loaderMatch, arg) {
3635
3670
  }
3636
3671
  return arg.defaultShouldRevalidate;
3637
3672
  }
3638
- function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties2) {
3673
+ function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties2, allowElementMutations) {
3639
3674
  let childrenToPatch;
3640
3675
  if (routeId) {
3641
3676
  let route = manifest[routeId];
@@ -3650,18 +3685,47 @@ function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRoutePrope
3650
3685
  } else {
3651
3686
  childrenToPatch = routesToUse;
3652
3687
  }
3653
- let uniqueChildren = children.filter(
3654
- (newRoute) => !childrenToPatch.some(
3655
- (existingRoute) => isSameRoute(newRoute, existingRoute)
3656
- )
3657
- );
3658
- let newRoutes = convertRoutesToDataRoutes(
3659
- uniqueChildren,
3660
- mapRouteProperties2,
3661
- [routeId || "_", "patch", String(childrenToPatch?.length || "0")],
3662
- manifest
3663
- );
3664
- childrenToPatch.push(...newRoutes);
3688
+ let uniqueChildren = [];
3689
+ let existingChildren = [];
3690
+ children.forEach((newRoute) => {
3691
+ let existingRoute = childrenToPatch.find(
3692
+ (existingRoute2) => isSameRoute(newRoute, existingRoute2)
3693
+ );
3694
+ if (existingRoute) {
3695
+ existingChildren.push({ existingRoute, newRoute });
3696
+ } else {
3697
+ uniqueChildren.push(newRoute);
3698
+ }
3699
+ });
3700
+ if (uniqueChildren.length > 0) {
3701
+ let newRoutes = convertRoutesToDataRoutes(
3702
+ uniqueChildren,
3703
+ mapRouteProperties2,
3704
+ [routeId || "_", "patch", String(childrenToPatch?.length || "0")],
3705
+ manifest
3706
+ );
3707
+ childrenToPatch.push(...newRoutes);
3708
+ }
3709
+ if (allowElementMutations && existingChildren.length > 0) {
3710
+ for (let i = 0; i < existingChildren.length; i++) {
3711
+ let { existingRoute, newRoute } = existingChildren[i];
3712
+ let existingRouteTyped = existingRoute;
3713
+ let [newRouteTyped] = convertRoutesToDataRoutes(
3714
+ [newRoute],
3715
+ mapRouteProperties2,
3716
+ [],
3717
+ // Doesn't matter for mutated routes since they already have an id
3718
+ {},
3719
+ // Don't touch the manifest here since we're updating in place
3720
+ true
3721
+ );
3722
+ Object.assign(existingRouteTyped, {
3723
+ element: newRouteTyped.element ? newRouteTyped.element : existingRouteTyped.element,
3724
+ errorElement: newRouteTyped.errorElement ? newRouteTyped.errorElement : existingRouteTyped.errorElement,
3725
+ hydrateFallbackElement: newRouteTyped.hydrateFallbackElement ? newRouteTyped.hydrateFallbackElement : existingRouteTyped.hydrateFallbackElement
3726
+ });
3727
+ }
3728
+ }
3665
3729
  }
3666
3730
  function isSameRoute(newRoute, existingRoute) {
3667
3731
  if ("id" in newRoute && "id" in existingRoute && newRoute.id === existingRoute.id) {
@@ -4010,7 +4074,7 @@ function getDataStrategyMatch(mapRouteProperties2, manifest, request, match, laz
4010
4074
  return shouldRevalidateLoader(match, unstable_shouldRevalidateArgs);
4011
4075
  },
4012
4076
  resolve(handlerOverride) {
4013
- if (isUsingNewApi || shouldLoad || handlerOverride && request.method === "GET" && (match.route.lazy || match.route.loader)) {
4077
+ if (isUsingNewApi || shouldLoad || handlerOverride && !isMutationMethod(request.method) && (match.route.lazy || match.route.loader)) {
4014
4078
  return callLoaderOrAction({
4015
4079
  request,
4016
4080
  match,
@@ -4270,39 +4334,39 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
4270
4334
  return { type: "data" /* data */, data: result };
4271
4335
  }
4272
4336
  function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename) {
4273
- let location = response.headers.get("Location");
4337
+ let location2 = response.headers.get("Location");
4274
4338
  invariant(
4275
- location,
4339
+ location2,
4276
4340
  "Redirects returned/thrown from loaders/actions must have a Location header"
4277
4341
  );
4278
- if (!ABSOLUTE_URL_REGEX.test(location)) {
4342
+ if (!ABSOLUTE_URL_REGEX.test(location2)) {
4279
4343
  let trimmedMatches = matches.slice(
4280
4344
  0,
4281
4345
  matches.findIndex((m) => m.route.id === routeId) + 1
4282
4346
  );
4283
- location = normalizeTo(
4347
+ location2 = normalizeTo(
4284
4348
  new URL(request.url),
4285
4349
  trimmedMatches,
4286
4350
  basename,
4287
- location
4351
+ location2
4288
4352
  );
4289
- response.headers.set("Location", location);
4353
+ response.headers.set("Location", location2);
4290
4354
  }
4291
4355
  return response;
4292
4356
  }
4293
- function normalizeRedirectLocation(location, currentUrl, basename) {
4294
- if (ABSOLUTE_URL_REGEX.test(location)) {
4295
- let normalizedLocation = location;
4357
+ function normalizeRedirectLocation(location2, currentUrl, basename) {
4358
+ if (ABSOLUTE_URL_REGEX.test(location2)) {
4359
+ let normalizedLocation = location2;
4296
4360
  let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
4297
4361
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4298
4362
  if (url.origin === currentUrl.origin && isSameBasename) {
4299
4363
  return url.pathname + url.search + url.hash;
4300
4364
  }
4301
4365
  }
4302
- return location;
4366
+ return location2;
4303
4367
  }
4304
- function createClientSideRequest(history, location, signal, submission) {
4305
- let url = history.createURL(stripHashFromPath(location)).toString();
4368
+ function createClientSideRequest(history, location2, signal, submission) {
4369
+ let url = history.createURL(stripHashFromPath(location2)).toString();
4306
4370
  let init = { signal };
4307
4371
  if (submission && isMutationMethod(submission.formMethod)) {
4308
4372
  let { formMethod, formEncType } = submission;
@@ -4574,8 +4638,8 @@ function isMutationMethod(method) {
4574
4638
  function hasNakedIndexQuery(search) {
4575
4639
  return new URLSearchParams(search).getAll("index").some((v) => v === "");
4576
4640
  }
4577
- function getTargetMatch(matches, location) {
4578
- let search = typeof location === "string" ? parsePath(location).search : location.search;
4641
+ function getTargetMatch(matches, location2) {
4642
+ let search = typeof location2 === "string" ? parsePath(location2).search : location2.search;
4579
4643
  if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
4580
4644
  return matches[matches.length - 1];
4581
4645
  }
@@ -4616,11 +4680,11 @@ function getSubmissionFromNavigation(navigation) {
4616
4680
  };
4617
4681
  }
4618
4682
  }
4619
- function getLoadingNavigation(location, submission) {
4683
+ function getLoadingNavigation(location2, submission) {
4620
4684
  if (submission) {
4621
4685
  let navigation = {
4622
4686
  state: "loading",
4623
- location,
4687
+ location: location2,
4624
4688
  formMethod: submission.formMethod,
4625
4689
  formAction: submission.formAction,
4626
4690
  formEncType: submission.formEncType,
@@ -4632,7 +4696,7 @@ function getLoadingNavigation(location, submission) {
4632
4696
  } else {
4633
4697
  let navigation = {
4634
4698
  state: "loading",
4635
- location,
4699
+ location: location2,
4636
4700
  formMethod: void 0,
4637
4701
  formAction: void 0,
4638
4702
  formEncType: void 0,
@@ -4643,10 +4707,10 @@ function getLoadingNavigation(location, submission) {
4643
4707
  return navigation;
4644
4708
  }
4645
4709
  }
4646
- function getSubmittingNavigation(location, submission) {
4710
+ function getSubmittingNavigation(location2, submission) {
4647
4711
  let navigation = {
4648
4712
  state: "submitting",
4649
- location,
4713
+ location: location2,
4650
4714
  formMethod: submission.formMethod,
4651
4715
  formAction: submission.formAction,
4652
4716
  formEncType: submission.formEncType,
@@ -4972,18 +5036,18 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
4972
5036
  );
4973
5037
  }
4974
5038
  let locationFromContext = useLocation();
4975
- let location;
5039
+ let location2;
4976
5040
  if (locationArg) {
4977
5041
  let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
4978
5042
  invariant(
4979
5043
  parentPathnameBase === "/" || parsedLocationArg.pathname?.startsWith(parentPathnameBase),
4980
5044
  `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.`
4981
5045
  );
4982
- location = parsedLocationArg;
5046
+ location2 = parsedLocationArg;
4983
5047
  } else {
4984
- location = locationFromContext;
5048
+ location2 = locationFromContext;
4985
5049
  }
4986
- let pathname = location.pathname || "/";
5050
+ let pathname = location2.pathname || "/";
4987
5051
  let remainingPathname = pathname;
4988
5052
  if (parentPathnameBase !== "/") {
4989
5053
  let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
@@ -4994,11 +5058,11 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
4994
5058
  if (ENABLE_DEV_WARNINGS) {
4995
5059
  warning(
4996
5060
  parentRoute || matches != null,
4997
- `No routes matched location "${location.pathname}${location.search}${location.hash}" `
5061
+ `No routes matched location "${location2.pathname}${location2.search}${location2.hash}" `
4998
5062
  );
4999
5063
  warning(
5000
5064
  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,
5001
- `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.`
5065
+ `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.`
5002
5066
  );
5003
5067
  }
5004
5068
  let renderedMatches = _renderMatches(
@@ -5032,7 +5096,7 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
5032
5096
  hash: "",
5033
5097
  state: null,
5034
5098
  key: "default",
5035
- ...location
5099
+ ...location2
5036
5100
  },
5037
5101
  navigationType: "POP" /* Pop */
5038
5102
  }
@@ -5200,6 +5264,7 @@ function _renderMatches(matches, parentMatches = [], dataRouterState = null, fut
5200
5264
  } else {
5201
5265
  children = outlet;
5202
5266
  }
5267
+ children = /* @__PURE__ */ React2.createElement(RedirectBoundary, null, children);
5203
5268
  return /* @__PURE__ */ React2.createElement(
5204
5269
  RenderedRoute,
5205
5270
  {
@@ -5226,6 +5291,19 @@ function _renderMatches(matches, parentMatches = [], dataRouterState = null, fut
5226
5291
  ) : getChildren();
5227
5292
  }, null);
5228
5293
  }
5294
+ var RedirectBoundary = class extends React2.Component {
5295
+ // If the error is Symbol.for("react-router.redirect"), keep rendering children.
5296
+ // If it's anything else, re-throw to bubble it up.
5297
+ static getDerivedStateFromError(error) {
5298
+ if (error === Symbol.for("react-router.redirect")) {
5299
+ return null;
5300
+ }
5301
+ throw error;
5302
+ }
5303
+ render() {
5304
+ return this.props.children;
5305
+ }
5306
+ };
5229
5307
  function getDataRouterConsoleError(hookName) {
5230
5308
  return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
5231
5309
  }
@@ -5494,7 +5572,7 @@ function RouterProvider({
5494
5572
  let [interruption, setInterruption] = React3.useState();
5495
5573
  let fetcherData = React3.useRef(/* @__PURE__ */ new Map());
5496
5574
  let setState = React3.useCallback(
5497
- (newState, { deletedFetchers, flushSync, viewTransitionOpts }) => {
5575
+ (newState, { deletedFetchers, flushSync: flushSync2, viewTransitionOpts }) => {
5498
5576
  newState.fetchers.forEach((fetcher, key) => {
5499
5577
  if (fetcher.data !== void 0) {
5500
5578
  fetcherData.current.set(key, fetcher.data);
@@ -5502,7 +5580,7 @@ function RouterProvider({
5502
5580
  });
5503
5581
  deletedFetchers.forEach((key) => fetcherData.current.delete(key));
5504
5582
  warnOnce(
5505
- flushSync === false || reactDomFlushSyncImpl != null,
5583
+ flushSync2 === false || reactDomFlushSyncImpl != null,
5506
5584
  'You provided the `flushSync` option to a router update, but you are not using the `<RouterProvider>` from `react-router/dom` so `ReactDOM.flushSync()` is unavailable. Please update your app to `import { RouterProvider } from "react-router/dom"` and ensure you have `react-dom` installed as a dependency to use the `flushSync` option.'
5507
5585
  );
5508
5586
  let isViewTransitionAvailable = router.window != null && router.window.document != null && typeof router.window.document.startViewTransition === "function";
@@ -5511,14 +5589,14 @@ function RouterProvider({
5511
5589
  "You provided the `viewTransition` option to a router update, but you do not appear to be running in a DOM environment as `window.startViewTransition` is not available."
5512
5590
  );
5513
5591
  if (!viewTransitionOpts || !isViewTransitionAvailable) {
5514
- if (reactDomFlushSyncImpl && flushSync) {
5592
+ if (reactDomFlushSyncImpl && flushSync2) {
5515
5593
  reactDomFlushSyncImpl(() => setStateImpl(newState));
5516
5594
  } else {
5517
5595
  React3.startTransition(() => setStateImpl(newState));
5518
5596
  }
5519
5597
  return;
5520
5598
  }
5521
- if (reactDomFlushSyncImpl && flushSync) {
5599
+ if (reactDomFlushSyncImpl && flushSync2) {
5522
5600
  reactDomFlushSyncImpl(() => {
5523
5601
  if (transition) {
5524
5602
  renderDfd && renderDfd.resolve();
@@ -5794,9 +5872,9 @@ function Router({
5794
5872
  }
5795
5873
  function Routes({
5796
5874
  children,
5797
- location
5875
+ location: location2
5798
5876
  }) {
5799
- return useRoutes(createRoutesFromChildren(children), location);
5877
+ return useRoutes(createRoutesFromChildren(children), location2);
5800
5878
  }
5801
5879
  function Await({
5802
5880
  children,
@@ -6220,7 +6298,7 @@ async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
6220
6298
  )
6221
6299
  );
6222
6300
  }
6223
- function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
6301
+ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location2, mode) {
6224
6302
  let isNew = (match, index) => {
6225
6303
  if (!currentMatches[index]) return true;
6226
6304
  return match.route.id !== currentMatches[index].route.id;
@@ -6250,7 +6328,7 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
6250
6328
  if (match.route.shouldRevalidate) {
6251
6329
  let routeChoice = match.route.shouldRevalidate({
6252
6330
  currentUrl: new URL(
6253
- location.pathname + location.search + location.hash,
6331
+ location2.pathname + location2.search + location2.hash,
6254
6332
  window.origin
6255
6333
  ),
6256
6334
  currentParams: currentMatches[0]?.params || {},
@@ -6880,7 +6958,7 @@ async function decodeDeferred(reader) {
6880
6958
  }
6881
6959
  function encode(input, options) {
6882
6960
  const { plugins, postPlugins, signal } = options ?? {};
6883
- const encoder2 = {
6961
+ const encoder3 = {
6884
6962
  deferred: {},
6885
6963
  index: 0,
6886
6964
  indices: /* @__PURE__ */ new Map(),
@@ -6893,7 +6971,7 @@ function encode(input, options) {
6893
6971
  let lastSentIndex = 0;
6894
6972
  const readable = new ReadableStream({
6895
6973
  async start(controller) {
6896
- const id = flatten.call(encoder2, input);
6974
+ const id = flatten.call(encoder3, input);
6897
6975
  if (Array.isArray(id)) {
6898
6976
  throw new Error("This should never happen");
6899
6977
  }
@@ -6902,13 +6980,13 @@ function encode(input, options) {
6902
6980
  `));
6903
6981
  } else {
6904
6982
  controller.enqueue(
6905
- textEncoder.encode(`[${encoder2.stringified.join(",")}]
6983
+ textEncoder.encode(`[${encoder3.stringified.join(",")}]
6906
6984
  `)
6907
6985
  );
6908
- lastSentIndex = encoder2.stringified.length - 1;
6986
+ lastSentIndex = encoder3.stringified.length - 1;
6909
6987
  }
6910
6988
  const seenPromises = /* @__PURE__ */ new WeakSet();
6911
- if (Object.keys(encoder2.deferred).length) {
6989
+ if (Object.keys(encoder3.deferred).length) {
6912
6990
  let raceDone;
6913
6991
  const racePromise = new Promise((resolve, reject) => {
6914
6992
  raceDone = resolve;
@@ -6923,19 +7001,19 @@ function encode(input, options) {
6923
7001
  }
6924
7002
  }
6925
7003
  });
6926
- while (Object.keys(encoder2.deferred).length > 0) {
7004
+ while (Object.keys(encoder3.deferred).length > 0) {
6927
7005
  for (const [deferredId, deferred] of Object.entries(
6928
- encoder2.deferred
7006
+ encoder3.deferred
6929
7007
  )) {
6930
7008
  if (seenPromises.has(deferred)) continue;
6931
7009
  seenPromises.add(
6932
7010
  // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
6933
- encoder2.deferred[Number(deferredId)] = Promise.race([
7011
+ encoder3.deferred[Number(deferredId)] = Promise.race([
6934
7012
  racePromise,
6935
7013
  deferred
6936
7014
  ]).then(
6937
7015
  (resolved) => {
6938
- const id2 = flatten.call(encoder2, resolved);
7016
+ const id2 = flatten.call(encoder3, resolved);
6939
7017
  if (Array.isArray(id2)) {
6940
7018
  controller.enqueue(
6941
7019
  textEncoder.encode(
@@ -6943,7 +7021,7 @@ function encode(input, options) {
6943
7021
  `
6944
7022
  )
6945
7023
  );
6946
- encoder2.index++;
7024
+ encoder3.index++;
6947
7025
  lastSentIndex++;
6948
7026
  } else if (id2 < 0) {
6949
7027
  controller.enqueue(
@@ -6953,21 +7031,21 @@ function encode(input, options) {
6953
7031
  )
6954
7032
  );
6955
7033
  } else {
6956
- const values = encoder2.stringified.slice(lastSentIndex + 1).join(",");
7034
+ const values = encoder3.stringified.slice(lastSentIndex + 1).join(",");
6957
7035
  controller.enqueue(
6958
7036
  textEncoder.encode(
6959
7037
  `${TYPE_PROMISE}${deferredId}:[${values}]
6960
7038
  `
6961
7039
  )
6962
7040
  );
6963
- lastSentIndex = encoder2.stringified.length - 1;
7041
+ lastSentIndex = encoder3.stringified.length - 1;
6964
7042
  }
6965
7043
  },
6966
7044
  (reason) => {
6967
7045
  if (!reason || typeof reason !== "object" || !(reason instanceof Error)) {
6968
7046
  reason = new Error("An unknown error occurred");
6969
7047
  }
6970
- const id2 = flatten.call(encoder2, reason);
7048
+ const id2 = flatten.call(encoder3, reason);
6971
7049
  if (Array.isArray(id2)) {
6972
7050
  controller.enqueue(
6973
7051
  textEncoder.encode(
@@ -6975,7 +7053,7 @@ function encode(input, options) {
6975
7053
  `
6976
7054
  )
6977
7055
  );
6978
- encoder2.index++;
7056
+ encoder3.index++;
6979
7057
  lastSentIndex++;
6980
7058
  } else if (id2 < 0) {
6981
7059
  controller.enqueue(
@@ -6983,26 +7061,26 @@ function encode(input, options) {
6983
7061
  `)
6984
7062
  );
6985
7063
  } else {
6986
- const values = encoder2.stringified.slice(lastSentIndex + 1).join(",");
7064
+ const values = encoder3.stringified.slice(lastSentIndex + 1).join(",");
6987
7065
  controller.enqueue(
6988
7066
  textEncoder.encode(
6989
7067
  `${TYPE_ERROR}${deferredId}:[${values}]
6990
7068
  `
6991
7069
  )
6992
7070
  );
6993
- lastSentIndex = encoder2.stringified.length - 1;
7071
+ lastSentIndex = encoder3.stringified.length - 1;
6994
7072
  }
6995
7073
  }
6996
7074
  ).finally(() => {
6997
- delete encoder2.deferred[Number(deferredId)];
7075
+ delete encoder3.deferred[Number(deferredId)];
6998
7076
  })
6999
7077
  );
7000
7078
  }
7001
- await Promise.race(Object.values(encoder2.deferred));
7079
+ await Promise.race(Object.values(encoder3.deferred));
7002
7080
  }
7003
7081
  raceDone();
7004
7082
  }
7005
- await Promise.all(Object.values(encoder2.deferred));
7083
+ await Promise.all(Object.values(encoder3.deferred));
7006
7084
  controller.close();
7007
7085
  }
7008
7086
  });
@@ -7121,7 +7199,7 @@ function getTurboStreamSingleFetchDataStrategy(getRouter, manifest, routeModules
7121
7199
  );
7122
7200
  return async (args) => args.unstable_runClientMiddleware(dataStrategy);
7123
7201
  }
7124
- function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode, ssr, basename) {
7202
+ function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode, ssr, basename, shouldAllowOptOut = () => true) {
7125
7203
  return async (args) => {
7126
7204
  let { request, matches, fetcherKey } = args;
7127
7205
  let router = getRouter();
@@ -7144,7 +7222,8 @@ function getSingleFetchDataStrategyImpl(getRouter, getRouteInfo, fetchAndDecode,
7144
7222
  getRouteInfo,
7145
7223
  fetchAndDecode,
7146
7224
  ssr,
7147
- basename
7225
+ basename,
7226
+ shouldAllowOptOut
7148
7227
  );
7149
7228
  };
7150
7229
  }
@@ -7196,7 +7275,7 @@ async function nonSsrStrategy(args, getRouteInfo, fetchAndDecode, basename) {
7196
7275
  );
7197
7276
  return results;
7198
7277
  }
7199
- async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, fetchAndDecode, ssr, basename) {
7278
+ async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, fetchAndDecode, ssr, basename, shouldAllowOptOut = () => true) {
7200
7279
  let routesParams = /* @__PURE__ */ new Set();
7201
7280
  let foundOptOutRoute = false;
7202
7281
  let routeDfds = args.matches.map(() => createDeferred2());
@@ -7216,7 +7295,7 @@ async function singleFetchLoaderNavigationStrategy(args, router, getRouteInfo, f
7216
7295
  hasShouldRevalidate === true);
7217
7296
  return;
7218
7297
  }
7219
- if (hasClientLoader) {
7298
+ if (shouldAllowOptOut(m) && hasClientLoader) {
7220
7299
  if (hasLoader) {
7221
7300
  foundOptOutRoute = true;
7222
7301
  }
@@ -7319,7 +7398,7 @@ function stripIndexParam(url) {
7319
7398
  }
7320
7399
  return url;
7321
7400
  }
7322
- function singleFetchUrl(reqUrl, basename) {
7401
+ function singleFetchUrl(reqUrl, basename, extension) {
7323
7402
  let url = typeof reqUrl === "string" ? new URL(
7324
7403
  reqUrl,
7325
7404
  // This can be called during the SSR flow via PrefetchPageLinksImpl so
@@ -7327,17 +7406,17 @@ function singleFetchUrl(reqUrl, basename) {
7327
7406
  typeof window === "undefined" ? "server://singlefetch/" : window.location.origin
7328
7407
  ) : reqUrl;
7329
7408
  if (url.pathname === "/") {
7330
- url.pathname = "_root.data";
7409
+ url.pathname = `_root.${extension}`;
7331
7410
  } else if (basename && stripBasename(url.pathname, basename) === "/") {
7332
- url.pathname = `${basename.replace(/\/$/, "")}/_root.data`;
7411
+ url.pathname = `${basename.replace(/\/$/, "")}/_root.${extension}`;
7333
7412
  } else {
7334
- url.pathname = `${url.pathname.replace(/\/$/, "")}.data`;
7413
+ url.pathname = `${url.pathname.replace(/\/$/, "")}.${extension}`;
7335
7414
  }
7336
7415
  return url;
7337
7416
  }
7338
7417
  async function fetchAndDecodeViaTurboStream(args, basename, targetRoutes) {
7339
7418
  let { request } = args;
7340
- let url = singleFetchUrl(request.url, basename);
7419
+ let url = singleFetchUrl(request.url, basename, "data");
7341
7420
  if (request.method === "GET") {
7342
7421
  url = stripIndexParam(url);
7343
7422
  if (targetRoutes) {
@@ -7434,13 +7513,13 @@ function decodeViaTurboStream(body, global2) {
7434
7513
  function unwrapSingleFetchResult(result, routeId) {
7435
7514
  if ("redirect" in result) {
7436
7515
  let {
7437
- redirect: location,
7516
+ redirect: location2,
7438
7517
  revalidate,
7439
7518
  reload,
7440
7519
  replace: replace2,
7441
7520
  status
7442
7521
  } = result.redirect;
7443
- throw redirect(location, {
7522
+ throw redirect(location2, {
7444
7523
  status,
7445
7524
  headers: {
7446
7525
  // Three R's of redirecting (lol Veep)
@@ -8371,7 +8450,7 @@ function PrefetchPageLinksImpl({
8371
8450
  matches: nextMatches,
8372
8451
  ...linkProps
8373
8452
  }) {
8374
- let location = useLocation();
8453
+ let location2 = useLocation();
8375
8454
  let { manifest, routeModules } = useFrameworkContext();
8376
8455
  let { basename } = useDataRouterContext2();
8377
8456
  let { loaderData, matches } = useDataRouterStateContext();
@@ -8381,10 +8460,10 @@ function PrefetchPageLinksImpl({
8381
8460
  nextMatches,
8382
8461
  matches,
8383
8462
  manifest,
8384
- location,
8463
+ location2,
8385
8464
  "data"
8386
8465
  ),
8387
- [page, nextMatches, matches, manifest, location]
8466
+ [page, nextMatches, matches, manifest, location2]
8388
8467
  );
8389
8468
  let newMatchesForAssets = React9.useMemo(
8390
8469
  () => getNewMatchesForLinks(
@@ -8392,13 +8471,13 @@ function PrefetchPageLinksImpl({
8392
8471
  nextMatches,
8393
8472
  matches,
8394
8473
  manifest,
8395
- location,
8474
+ location2,
8396
8475
  "assets"
8397
8476
  ),
8398
- [page, nextMatches, matches, manifest, location]
8477
+ [page, nextMatches, matches, manifest, location2]
8399
8478
  );
8400
8479
  let dataHrefs = React9.useMemo(() => {
8401
- if (page === location.pathname + location.search + location.hash) {
8480
+ if (page === location2.pathname + location2.search + location2.hash) {
8402
8481
  return [];
8403
8482
  }
8404
8483
  let routesParams = /* @__PURE__ */ new Set();
@@ -8419,7 +8498,7 @@ function PrefetchPageLinksImpl({
8419
8498
  if (routesParams.size === 0) {
8420
8499
  return [];
8421
8500
  }
8422
- let url = singleFetchUrl(page, basename);
8501
+ let url = singleFetchUrl(page, basename, "data");
8423
8502
  if (foundOptOutRoute && routesParams.size > 0) {
8424
8503
  url.searchParams.set(
8425
8504
  "_routes",
@@ -8430,7 +8509,7 @@ function PrefetchPageLinksImpl({
8430
8509
  }, [
8431
8510
  basename,
8432
8511
  loaderData,
8433
- location,
8512
+ location2,
8434
8513
  manifest,
8435
8514
  newMatchesForData,
8436
8515
  nextMatches,
@@ -8455,7 +8534,7 @@ function Meta() {
8455
8534
  matches: routerMatches,
8456
8535
  loaderData
8457
8536
  } = useDataRouterStateContext();
8458
- let location = useLocation();
8537
+ let location2 = useLocation();
8459
8538
  let _matches = getActiveMatches(routerMatches, errors, isSpaMode);
8460
8539
  let error = null;
8461
8540
  if (errors) {
@@ -8485,7 +8564,7 @@ function Meta() {
8485
8564
  routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
8486
8565
  data: data2,
8487
8566
  params,
8488
- location,
8567
+ location: location2,
8489
8568
  matches,
8490
8569
  error
8491
8570
  }) : Array.isArray(routeModule.meta) ? [...routeModule.meta] : routeModule.meta;
@@ -8717,7 +8796,7 @@ function mergeRefs(...refs) {
8717
8796
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
8718
8797
  try {
8719
8798
  if (isBrowser) {
8720
- window.__reactRouterVersion = "0.0.0-experimental-3b8ea09a1";
8799
+ window.__reactRouterVersion = "0.0.0-experimental-7db49e8d4";
8721
8800
  }
8722
8801
  } catch (e) {
8723
8802
  }
@@ -8975,14 +9054,14 @@ var NavLink = React10.forwardRef(
8975
9054
  ...rest
8976
9055
  }, ref) {
8977
9056
  let path = useResolvedPath(to, { relative: rest.relative });
8978
- let location = useLocation();
9057
+ let location2 = useLocation();
8979
9058
  let routerState = React10.useContext(DataRouterStateContext);
8980
9059
  let { navigator, basename } = React10.useContext(NavigationContext);
8981
9060
  let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
8982
9061
  // eslint-disable-next-line react-hooks/rules-of-hooks
8983
9062
  useViewTransitionState(path) && viewTransition === true;
8984
9063
  let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
8985
- let locationPathname = location.pathname;
9064
+ let locationPathname = location2.pathname;
8986
9065
  let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
8987
9066
  if (!caseSensitive) {
8988
9067
  locationPathname = locationPathname.toLowerCase();
@@ -9087,19 +9166,19 @@ function ScrollRestoration({
9087
9166
  }) {
9088
9167
  let remixContext = React10.useContext(FrameworkContext);
9089
9168
  let { basename } = React10.useContext(NavigationContext);
9090
- let location = useLocation();
9169
+ let location2 = useLocation();
9091
9170
  let matches = useMatches();
9092
9171
  useScrollRestoration({ getKey, storageKey });
9093
9172
  let ssrKey = React10.useMemo(
9094
9173
  () => {
9095
9174
  if (!remixContext || !getKey) return null;
9096
9175
  let userKey = getScrollRestorationKey(
9097
- location,
9176
+ location2,
9098
9177
  matches,
9099
9178
  basename,
9100
9179
  getKey
9101
9180
  );
9102
- return userKey !== location.key ? userKey : null;
9181
+ return userKey !== location2.key ? userKey : null;
9103
9182
  },
9104
9183
  // Nah, we only need this the first time for the SSR render
9105
9184
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -9160,13 +9239,13 @@ function useLinkClickHandler(to, {
9160
9239
  viewTransition
9161
9240
  } = {}) {
9162
9241
  let navigate = useNavigate();
9163
- let location = useLocation();
9242
+ let location2 = useLocation();
9164
9243
  let path = useResolvedPath(to, { relative });
9165
9244
  return React10.useCallback(
9166
9245
  (event) => {
9167
9246
  if (shouldProcessLinkClick(event, target)) {
9168
9247
  event.preventDefault();
9169
- let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
9248
+ let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location2) === createPath(path);
9170
9249
  navigate(to, {
9171
9250
  replace: replace2,
9172
9251
  state,
@@ -9177,7 +9256,7 @@ function useLinkClickHandler(to, {
9177
9256
  }
9178
9257
  },
9179
9258
  [
9180
- location,
9259
+ location2,
9181
9260
  navigate,
9182
9261
  path,
9183
9262
  replaceProp,
@@ -9197,18 +9276,18 @@ function useSearchParams(defaultInit) {
9197
9276
  );
9198
9277
  let defaultSearchParamsRef = React10.useRef(createSearchParams(defaultInit));
9199
9278
  let hasSetSearchParamsRef = React10.useRef(false);
9200
- let location = useLocation();
9279
+ let location2 = useLocation();
9201
9280
  let searchParams = React10.useMemo(
9202
9281
  () => (
9203
9282
  // Only merge in the defaults if we haven't yet called setSearchParams.
9204
9283
  // Once we call that we want those to take precedence, otherwise you can't
9205
9284
  // remove a param with setSearchParams({}) if it has an initial value
9206
9285
  getSearchParamsForLocation(
9207
- location.search,
9286
+ location2.search,
9208
9287
  hasSetSearchParamsRef.current ? null : defaultSearchParamsRef.current
9209
9288
  )
9210
9289
  ),
9211
- [location.search]
9290
+ [location2.search]
9212
9291
  );
9213
9292
  let navigate = useNavigate();
9214
9293
  let setSearchParams = React10.useCallback(
@@ -9269,9 +9348,9 @@ function useFormAction(action, { relative } = {}) {
9269
9348
  invariant(routeContext, "useFormAction must be used inside a RouteContext");
9270
9349
  let [match] = routeContext.matches.slice(-1);
9271
9350
  let path = { ...useResolvedPath(action ? action : ".", { relative }) };
9272
- let location = useLocation();
9351
+ let location2 = useLocation();
9273
9352
  if (action == null) {
9274
- path.search = location.search;
9353
+ path.search = location2.search;
9275
9354
  let params = new URLSearchParams(path.search);
9276
9355
  let indexValues = params.getAll("index");
9277
9356
  let hasNakedIndexParam = indexValues.some((v) => v === "");
@@ -9363,23 +9442,23 @@ function useFetchers() {
9363
9442
  }
9364
9443
  var SCROLL_RESTORATION_STORAGE_KEY = "react-router-scroll-positions";
9365
9444
  var savedScrollPositions = {};
9366
- function getScrollRestorationKey(location, matches, basename, getKey) {
9445
+ function getScrollRestorationKey(location2, matches, basename, getKey) {
9367
9446
  let key = null;
9368
9447
  if (getKey) {
9369
9448
  if (basename !== "/") {
9370
9449
  key = getKey(
9371
9450
  {
9372
- ...location,
9373
- pathname: stripBasename(location.pathname, basename) || location.pathname
9451
+ ...location2,
9452
+ pathname: stripBasename(location2.pathname, basename) || location2.pathname
9374
9453
  },
9375
9454
  matches
9376
9455
  );
9377
9456
  } else {
9378
- key = getKey(location, matches);
9457
+ key = getKey(location2, matches);
9379
9458
  }
9380
9459
  }
9381
9460
  if (key == null) {
9382
- key = location.key;
9461
+ key = location2.key;
9383
9462
  }
9384
9463
  return key;
9385
9464
  }
@@ -9392,7 +9471,7 @@ function useScrollRestoration({
9392
9471
  "useScrollRestoration" /* UseScrollRestoration */
9393
9472
  );
9394
9473
  let { basename } = React10.useContext(NavigationContext);
9395
- let location = useLocation();
9474
+ let location2 = useLocation();
9396
9475
  let matches = useMatches();
9397
9476
  let navigation = useNavigation();
9398
9477
  React10.useEffect(() => {
@@ -9404,7 +9483,7 @@ function useScrollRestoration({
9404
9483
  usePageHide(
9405
9484
  React10.useCallback(() => {
9406
9485
  if (navigation.state === "idle") {
9407
- let key = getScrollRestorationKey(location, matches, basename, getKey);
9486
+ let key = getScrollRestorationKey(location2, matches, basename, getKey);
9408
9487
  savedScrollPositions[key] = window.scrollY;
9409
9488
  }
9410
9489
  try {
@@ -9419,7 +9498,7 @@ function useScrollRestoration({
9419
9498
  );
9420
9499
  }
9421
9500
  window.history.scrollRestoration = "auto";
9422
- }, [navigation.state, getKey, basename, location, matches, storageKey])
9501
+ }, [navigation.state, getKey, basename, location2, matches, storageKey])
9423
9502
  );
9424
9503
  if (typeof document !== "undefined") {
9425
9504
  React10.useLayoutEffect(() => {
@@ -9437,7 +9516,7 @@ function useScrollRestoration({
9437
9516
  let disableScrollRestoration = router?.enableScrollRestoration(
9438
9517
  savedScrollPositions,
9439
9518
  () => window.scrollY,
9440
- getKey ? (location2, matches2) => getScrollRestorationKey(location2, matches2, basename, getKey) : void 0
9519
+ getKey ? (location3, matches2) => getScrollRestorationKey(location3, matches2, basename, getKey) : void 0
9441
9520
  );
9442
9521
  return () => disableScrollRestoration && disableScrollRestoration();
9443
9522
  }, [router, basename, getKey]);
@@ -9449,9 +9528,9 @@ function useScrollRestoration({
9449
9528
  window.scrollTo(0, restoreScrollPosition);
9450
9529
  return;
9451
9530
  }
9452
- if (location.hash) {
9531
+ if (location2.hash) {
9453
9532
  let el = document.getElementById(
9454
- decodeURIComponent(location.hash.slice(1))
9533
+ decodeURIComponent(location2.hash.slice(1))
9455
9534
  );
9456
9535
  if (el) {
9457
9536
  el.scrollIntoView();
@@ -9462,7 +9541,7 @@ function useScrollRestoration({
9462
9541
  return;
9463
9542
  }
9464
9543
  window.scrollTo(0, 0);
9465
- }, [location, restoreScrollPosition, preventScrollReset]);
9544
+ }, [location2, restoreScrollPosition, preventScrollReset]);
9466
9545
  }
9467
9546
  }
9468
9547
  function useBeforeUnload(callback, options) {
@@ -9535,7 +9614,7 @@ function StaticRouter({
9535
9614
  locationProp = parsePath(locationProp);
9536
9615
  }
9537
9616
  let action = "POP" /* Pop */;
9538
- let location = {
9617
+ let location2 = {
9539
9618
  pathname: locationProp.pathname || "/",
9540
9619
  search: locationProp.search || "",
9541
9620
  hash: locationProp.hash || "",
@@ -9548,7 +9627,7 @@ function StaticRouter({
9548
9627
  {
9549
9628
  basename,
9550
9629
  children,
9551
- location,
9630
+ location: location2,
9552
9631
  navigationType: action,
9553
9632
  navigator: staticNavigator,
9554
9633
  static: true
@@ -9767,6 +9846,9 @@ function createStaticRouter(routes, context, opts = {}) {
9767
9846
  _internalFetchControllers: /* @__PURE__ */ new Map(),
9768
9847
  _internalSetRoutes() {
9769
9848
  throw msg("_internalSetRoutes");
9849
+ },
9850
+ _internalSetStateDoNotUseOrYouWillBreakYourApp() {
9851
+ throw msg("_internalSetStateDoNotUseOrYouWillBreakYourApp");
9770
9852
  }
9771
9853
  };
9772
9854
  }
@@ -10428,7 +10510,7 @@ function createServerHandoffString(serverHandoff) {
10428
10510
 
10429
10511
  // lib/server-runtime/headers.ts
10430
10512
  import { splitCookiesString } from "set-cookie-parser";
10431
- function getDocumentHeaders(build, context) {
10513
+ function getDocumentHeaders(context, build) {
10432
10514
  return getDocumentHeadersImpl(context, (m) => {
10433
10515
  let route = build.routes[m.route.id];
10434
10516
  invariant3(route, `Route with id "${m.route.id}" not found in build`);
@@ -10505,7 +10587,7 @@ var SERVER_NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([
10505
10587
  async function singleFetchAction(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
10506
10588
  try {
10507
10589
  let respond2 = function(context) {
10508
- let headers = getDocumentHeaders(build, context);
10590
+ let headers = getDocumentHeaders(context, build);
10509
10591
  if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
10510
10592
  return generateSingleFetchResponse(request, build, serverMode, {
10511
10593
  result: getSingleFetchRedirect(
@@ -10580,7 +10662,7 @@ async function singleFetchAction(build, serverMode, staticHandler, request, hand
10580
10662
  async function singleFetchLoaders(build, serverMode, staticHandler, request, handlerUrl, loadContext, handleError) {
10581
10663
  try {
10582
10664
  let respond2 = function(context) {
10583
- let headers = getDocumentHeaders(build, context);
10665
+ let headers = getDocumentHeaders(context, build);
10584
10666
  if (isRedirectStatusCode(context.statusCode) && headers.has("Location")) {
10585
10667
  return generateSingleFetchResponse(request, build, serverMode, {
10586
10668
  result: {
@@ -11047,7 +11129,7 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
11047
11129
  if (isResponse(context)) {
11048
11130
  return context;
11049
11131
  }
11050
- let headers = getDocumentHeaders(build, context);
11132
+ let headers = getDocumentHeaders(context, build);
11051
11133
  if (SERVER_NO_BODY_STATUS_CODES.has(context.statusCode)) {
11052
11134
  return new Response(null, { status: context.statusCode, headers });
11053
11135
  }
@@ -11388,6 +11470,820 @@ function href(path, ...args) {
11388
11470
  }).filter((segment) => segment !== void 0).join("/");
11389
11471
  }
11390
11472
 
11473
+ // lib/rsc/browser.tsx
11474
+ import * as React14 from "react";
11475
+ import * as ReactDOM from "react-dom";
11476
+
11477
+ // lib/dom/ssr/hydration.tsx
11478
+ function getHydrationData(state, routes, getRouteInfo, location2, basename, isSpaMode) {
11479
+ let hydrationData = {
11480
+ ...state,
11481
+ loaderData: { ...state.loaderData }
11482
+ };
11483
+ let initialMatches = matchRoutes(routes, location2, basename);
11484
+ if (initialMatches) {
11485
+ for (let match of initialMatches) {
11486
+ let routeId = match.route.id;
11487
+ let routeInfo = getRouteInfo(routeId);
11488
+ if (shouldHydrateRouteLoader(
11489
+ routeId,
11490
+ routeInfo.clientLoader,
11491
+ routeInfo.hasLoader,
11492
+ isSpaMode
11493
+ ) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) {
11494
+ delete hydrationData.loaderData[routeId];
11495
+ } else if (!routeInfo.hasLoader) {
11496
+ hydrationData.loaderData[routeId] = null;
11497
+ }
11498
+ }
11499
+ }
11500
+ return hydrationData;
11501
+ }
11502
+
11503
+ // lib/rsc/browser.tsx
11504
+ function createCallServer({
11505
+ decode: decode2,
11506
+ encodeAction
11507
+ }) {
11508
+ let landedActionId = 0;
11509
+ return async (id, args) => {
11510
+ let actionId = window.__routerActionID = (window.__routerActionID ?? (window.__routerActionID = 0)) + 1;
11511
+ const response = await fetch(location.href, {
11512
+ body: await encodeAction(args),
11513
+ method: "POST",
11514
+ headers: {
11515
+ Accept: "text/x-component",
11516
+ "rsc-action-id": id
11517
+ }
11518
+ });
11519
+ if (!response.body) {
11520
+ throw new Error("No response body");
11521
+ }
11522
+ const payload = await decode2(response.body);
11523
+ if (payload.type === "redirect") {
11524
+ if (payload.reload) {
11525
+ window.location.href = payload.location;
11526
+ return;
11527
+ }
11528
+ let reject;
11529
+ const promise = new Promise((resolve, rejectFn) => {
11530
+ reject = rejectFn;
11531
+ });
11532
+ const unsubscribe = window.__router.subscribe(({ navigation }) => {
11533
+ if (navigation.state === "idle") {
11534
+ unsubscribe();
11535
+ reject(Symbol.for("react-router.redirect"));
11536
+ }
11537
+ });
11538
+ window.__router.navigate(payload.location, {
11539
+ replace: payload.replace
11540
+ });
11541
+ return promise;
11542
+ }
11543
+ if (payload.type !== "action") {
11544
+ throw new Error("Unexpected payload type");
11545
+ }
11546
+ if (payload.rerender) {
11547
+ (async () => {
11548
+ const rerender = await payload.rerender;
11549
+ if (!rerender) return;
11550
+ if (landedActionId < actionId && window.__routerActionID <= actionId) {
11551
+ landedActionId = actionId;
11552
+ if (rerender.type === "redirect") {
11553
+ if (rerender.reload) {
11554
+ window.location.href = rerender.location;
11555
+ return;
11556
+ }
11557
+ window.__router.navigate(rerender.location, {
11558
+ replace: rerender.replace
11559
+ });
11560
+ return;
11561
+ }
11562
+ let lastMatch;
11563
+ for (const match of rerender.matches) {
11564
+ window.__router.patchRoutes(
11565
+ lastMatch?.id ?? null,
11566
+ [createRouteFromServerManifest(match)],
11567
+ true
11568
+ );
11569
+ lastMatch = match;
11570
+ }
11571
+ window.__router._internalSetStateDoNotUseOrYouWillBreakYourApp({});
11572
+ React14.startTransition(() => {
11573
+ window.__router._internalSetStateDoNotUseOrYouWillBreakYourApp({
11574
+ loaderData: Object.assign(
11575
+ {},
11576
+ window.__router.state.loaderData,
11577
+ rerender.loaderData
11578
+ ),
11579
+ errors: rerender.errors ? Object.assign(
11580
+ {},
11581
+ window.__router.state.errors,
11582
+ rerender.errors
11583
+ ) : null
11584
+ });
11585
+ });
11586
+ }
11587
+ })();
11588
+ }
11589
+ return payload.actionResult;
11590
+ };
11591
+ }
11592
+ function createRouterFromPayload({
11593
+ decode: decode2,
11594
+ payload
11595
+ }) {
11596
+ if (window.__router) return window.__router;
11597
+ if (payload.type !== "render") throw new Error("Invalid payload type");
11598
+ let patches = /* @__PURE__ */ new Map();
11599
+ payload.patches?.forEach((patch) => {
11600
+ invariant(patch.parentId, "Invalid patch parentId");
11601
+ if (!patches.has(patch.parentId)) {
11602
+ patches.set(patch.parentId, []);
11603
+ }
11604
+ patches.get(patch.parentId)?.push(patch);
11605
+ });
11606
+ let routes = payload.matches.reduceRight((previous, match) => {
11607
+ const route = createRouteFromServerManifest(
11608
+ match,
11609
+ payload
11610
+ );
11611
+ if (previous.length > 0) {
11612
+ route.children = previous;
11613
+ let childrenToPatch = patches.get(match.id);
11614
+ if (childrenToPatch) {
11615
+ route.children.push(
11616
+ ...childrenToPatch.map((r) => createRouteFromServerManifest(r))
11617
+ );
11618
+ }
11619
+ }
11620
+ return [route];
11621
+ }, []);
11622
+ window.__router = createRouter({
11623
+ routes,
11624
+ basename: payload.basename,
11625
+ history: createBrowserHistory(),
11626
+ hydrationData: getHydrationData(
11627
+ {
11628
+ loaderData: payload.loaderData,
11629
+ actionData: payload.actionData,
11630
+ errors: payload.errors
11631
+ },
11632
+ routes,
11633
+ (routeId) => {
11634
+ let match = payload.matches.find((m) => m.id === routeId);
11635
+ invariant(match, "Route not found in payload");
11636
+ return {
11637
+ clientLoader: match.clientLoader,
11638
+ hasLoader: match.hasLoader,
11639
+ hasHydrateFallback: match.hydrateFallbackElement != null
11640
+ };
11641
+ },
11642
+ payload.location,
11643
+ void 0,
11644
+ false
11645
+ ),
11646
+ async patchRoutesOnNavigation({ path, signal }) {
11647
+ if (discoveredPaths2.has(path)) {
11648
+ return;
11649
+ }
11650
+ await fetchAndApplyManifestPatches2([path], decode2, signal);
11651
+ },
11652
+ // FIXME: Pass `build.ssr` and `build.basename` into this function
11653
+ dataStrategy: getRSCSingleFetchDataStrategy(
11654
+ () => window.__router,
11655
+ true,
11656
+ void 0,
11657
+ decode2
11658
+ )
11659
+ });
11660
+ if (window.__router.state.initialized) {
11661
+ window.__routerInitialized = true;
11662
+ window.__router.initialize();
11663
+ } else {
11664
+ window.__routerInitialized = false;
11665
+ }
11666
+ let lastLoaderData = void 0;
11667
+ window.__router.subscribe(({ loaderData, actionData }) => {
11668
+ if (lastLoaderData !== loaderData) {
11669
+ window.__routerActionID = (window.__routerActionID ?? (window.__routerActionID = 0)) + 1;
11670
+ }
11671
+ });
11672
+ return window.__router;
11673
+ }
11674
+ var renderedRoutesContext = unstable_createContext();
11675
+ function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, decode2) {
11676
+ let dataStrategy = getSingleFetchDataStrategyImpl(
11677
+ getRouter,
11678
+ (match) => {
11679
+ let M = match;
11680
+ return {
11681
+ hasLoader: M.route.hasLoader,
11682
+ hasClientLoader: M.route.hasClientLoader,
11683
+ hasAction: M.route.hasAction,
11684
+ hasClientAction: M.route.hasClientAction,
11685
+ hasShouldRevalidate: M.route.hasShouldRevalidate
11686
+ };
11687
+ },
11688
+ // pass map into fetchAndDecode so it can add payloads
11689
+ getFetchAndDecodeViaRSC(decode2),
11690
+ ssr,
11691
+ basename,
11692
+ // If we don't have an element, we need to hit the server loader flow
11693
+ // regardless of whether the client loader calls `serverLoader` or not,
11694
+ // otherwise we'll have nothing to render.
11695
+ // TODO: Do we need to account for API routes? Do we need a
11696
+ // `match.hasComponent` flag?
11697
+ (match) => match.route.element != null
11698
+ );
11699
+ return async (args) => args.unstable_runClientMiddleware(async () => {
11700
+ let context = args.context;
11701
+ context.set(renderedRoutesContext, []);
11702
+ let results = await dataStrategy(args);
11703
+ const renderedRoutesById = /* @__PURE__ */ new Map();
11704
+ for (const route of context.get(renderedRoutesContext)) {
11705
+ if (!renderedRoutesById.has(route.id)) {
11706
+ renderedRoutesById.set(route.id, []);
11707
+ }
11708
+ renderedRoutesById.get(route.id).push(route);
11709
+ }
11710
+ for (const match of args.matches) {
11711
+ const renderedRoutes = renderedRoutesById.get(match.route.id);
11712
+ if (renderedRoutes) {
11713
+ for (const rendered of renderedRoutes) {
11714
+ window.__router.patchRoutes(
11715
+ rendered.parentId ?? null,
11716
+ [createRouteFromServerManifest(rendered)],
11717
+ true
11718
+ );
11719
+ }
11720
+ }
11721
+ }
11722
+ return results;
11723
+ });
11724
+ }
11725
+ function getFetchAndDecodeViaRSC(decode2) {
11726
+ return async (args, basename, targetRoutes) => {
11727
+ let { request, context } = args;
11728
+ let url = singleFetchUrl(request.url, basename, "rsc");
11729
+ if (request.method === "GET") {
11730
+ url = stripIndexParam(url);
11731
+ if (targetRoutes) {
11732
+ url.searchParams.set("_routes", targetRoutes.join(","));
11733
+ }
11734
+ }
11735
+ let res = await fetch(url, await createRequestInit(request));
11736
+ if (res.status === 404 && !res.headers.has("X-Remix-Response")) {
11737
+ throw new ErrorResponseImpl(404, "Not Found", true);
11738
+ }
11739
+ invariant(res.body, "No response body to decode");
11740
+ try {
11741
+ const payload = await decode2(res.body);
11742
+ if (payload.type === "redirect") {
11743
+ return {
11744
+ status: res.status,
11745
+ data: {
11746
+ redirect: {
11747
+ redirect: payload.location,
11748
+ reload: false,
11749
+ replace: payload.replace,
11750
+ revalidate: false,
11751
+ status: payload.status
11752
+ }
11753
+ }
11754
+ };
11755
+ }
11756
+ if (payload.type !== "render") {
11757
+ throw new Error("Unexpected payload type");
11758
+ }
11759
+ context.get(renderedRoutesContext).push(...payload.matches);
11760
+ let results = { routes: {} };
11761
+ const dataKey = isMutationMethod(request.method) ? "actionData" : "loaderData";
11762
+ for (let [routeId, data2] of Object.entries(payload[dataKey] || {})) {
11763
+ results.routes[routeId] = { data: data2 };
11764
+ }
11765
+ if (payload.errors) {
11766
+ for (let [routeId, error] of Object.entries(payload.errors)) {
11767
+ results.routes[routeId] = { error };
11768
+ }
11769
+ }
11770
+ return { status: res.status, data: results };
11771
+ } catch (e) {
11772
+ throw new Error("Unable to decode RSC response");
11773
+ }
11774
+ };
11775
+ }
11776
+ function RSCHydratedRouter({
11777
+ decode: decode2,
11778
+ payload,
11779
+ routeDiscovery = "eager"
11780
+ }) {
11781
+ if (payload.type !== "render") throw new Error("Invalid payload type");
11782
+ let router = React14.useMemo(
11783
+ () => createRouterFromPayload({ decode: decode2, payload }),
11784
+ // eslint-disable-next-line react-hooks/exhaustive-deps
11785
+ []
11786
+ );
11787
+ React14.useLayoutEffect(() => {
11788
+ if (!window.__routerInitialized) {
11789
+ window.__routerInitialized = true;
11790
+ window.__router.initialize();
11791
+ }
11792
+ }, []);
11793
+ React14.useEffect(() => {
11794
+ if (routeDiscovery === "lazy" || // @ts-expect-error - TS doesn't know about this yet
11795
+ window.navigator?.connection?.saveData === true) {
11796
+ return;
11797
+ }
11798
+ function registerElement(el) {
11799
+ let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
11800
+ if (!path) {
11801
+ return;
11802
+ }
11803
+ let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
11804
+ if (!discoveredPaths2.has(pathname)) {
11805
+ nextPaths2.add(pathname);
11806
+ }
11807
+ }
11808
+ async function fetchPatches() {
11809
+ document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
11810
+ let paths = Array.from(nextPaths2.keys()).filter((path) => {
11811
+ if (discoveredPaths2.has(path)) {
11812
+ nextPaths2.delete(path);
11813
+ return false;
11814
+ }
11815
+ return true;
11816
+ });
11817
+ if (paths.length === 0) {
11818
+ return;
11819
+ }
11820
+ try {
11821
+ await fetchAndApplyManifestPatches2(paths, decode2);
11822
+ } catch (e) {
11823
+ console.error("Failed to fetch manifest patches", e);
11824
+ }
11825
+ }
11826
+ let debouncedFetchPatches = debounce2(fetchPatches, 100);
11827
+ fetchPatches();
11828
+ let observer = new MutationObserver(() => debouncedFetchPatches());
11829
+ observer.observe(document.documentElement, {
11830
+ subtree: true,
11831
+ childList: true,
11832
+ attributes: true,
11833
+ attributeFilter: ["data-discover", "href", "action"]
11834
+ });
11835
+ }, [routeDiscovery, decode2]);
11836
+ const frameworkContext = {
11837
+ future: {
11838
+ // These flags have no runtime impact so can always be false. If we add
11839
+ // flags that drive runtime behavior they'll need to be proxied through.
11840
+ unstable_middleware: false,
11841
+ unstable_subResourceIntegrity: false
11842
+ },
11843
+ isSpaMode: true,
11844
+ ssr: true,
11845
+ criticalCss: "",
11846
+ manifest: {
11847
+ routes: {},
11848
+ version: "1",
11849
+ url: "",
11850
+ entry: {
11851
+ module: "",
11852
+ imports: []
11853
+ }
11854
+ },
11855
+ routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
11856
+ routeModules: {}
11857
+ };
11858
+ return /* @__PURE__ */ React14.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React14.createElement(RouterProvider, { router, flushSync: ReactDOM.flushSync }));
11859
+ }
11860
+ function createRouteFromServerManifest(match, payload) {
11861
+ let hasInitialData = payload && match.id in payload.loaderData;
11862
+ let initialData = payload?.loaderData[match.id];
11863
+ let hasInitialError = payload?.errors && match.id in payload.errors;
11864
+ let initialError = payload?.errors?.[match.id];
11865
+ let isHydrationRequest = match.clientLoader?.hydrate === true || !match.hasLoader || // If we don't have an element, we need to hit the server loader flow
11866
+ // regardless of whether the client loader calls `serverLoader` or not,
11867
+ // otherwise we'll have nothing to render.
11868
+ // TODO: Do we need to account for API routes? Do we need a
11869
+ // `match.hasComponent` flag?
11870
+ !match.element;
11871
+ let dataRoute = {
11872
+ id: match.id,
11873
+ element: match.element,
11874
+ errorElement: match.errorElement,
11875
+ handle: match.handle,
11876
+ hasErrorBoundary: match.hasErrorBoundary,
11877
+ hydrateFallbackElement: match.hydrateFallbackElement,
11878
+ index: match.index,
11879
+ loader: match.clientLoader ? async (args, singleFetch) => {
11880
+ try {
11881
+ let result = await match.clientLoader({
11882
+ ...args,
11883
+ serverLoader: () => {
11884
+ preventInvalidServerHandlerCall2(
11885
+ "loader",
11886
+ match.id,
11887
+ match.hasLoader
11888
+ );
11889
+ if (isHydrationRequest) {
11890
+ if (hasInitialData) {
11891
+ return initialData;
11892
+ }
11893
+ if (hasInitialError) {
11894
+ throw initialError;
11895
+ }
11896
+ }
11897
+ return callSingleFetch(singleFetch);
11898
+ }
11899
+ });
11900
+ return result;
11901
+ } finally {
11902
+ isHydrationRequest = false;
11903
+ }
11904
+ } : (
11905
+ // We always make the call in this RSC world since even if we don't
11906
+ // have a `loader` we may need to get the `element` implementation
11907
+ (_, singleFetch) => callSingleFetch(singleFetch)
11908
+ ),
11909
+ action: match.clientAction ? (args, singleFetch) => match.clientAction({
11910
+ ...args,
11911
+ serverAction: async () => {
11912
+ preventInvalidServerHandlerCall2(
11913
+ "loader",
11914
+ match.id,
11915
+ match.hasLoader
11916
+ );
11917
+ return await callSingleFetch(singleFetch);
11918
+ }
11919
+ }) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : void 0,
11920
+ path: match.path,
11921
+ shouldRevalidate: match.shouldRevalidate,
11922
+ // We always have a "loader" in this RSC world since even if we don't
11923
+ // have a `loader` we may need to get the `element` implementation
11924
+ hasLoader: true,
11925
+ hasClientLoader: match.clientLoader != null,
11926
+ hasAction: match.hasAction,
11927
+ hasClientAction: match.clientAction != null,
11928
+ hasShouldRevalidate: match.shouldRevalidate != null
11929
+ };
11930
+ if (typeof dataRoute.loader === "function") {
11931
+ dataRoute.loader.hydrate = shouldHydrateRouteLoader(
11932
+ match.id,
11933
+ match.clientLoader,
11934
+ match.hasLoader,
11935
+ false
11936
+ );
11937
+ }
11938
+ return dataRoute;
11939
+ }
11940
+ function callSingleFetch(singleFetch) {
11941
+ invariant(typeof singleFetch === "function", "Invalid singleFetch parameter");
11942
+ return singleFetch();
11943
+ }
11944
+ function preventInvalidServerHandlerCall2(type, routeId, hasHandler) {
11945
+ if (!hasHandler) {
11946
+ let fn = type === "action" ? "serverAction()" : "serverLoader()";
11947
+ let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${routeId}")`;
11948
+ console.error(msg);
11949
+ throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
11950
+ }
11951
+ }
11952
+ var nextPaths2 = /* @__PURE__ */ new Set();
11953
+ var discoveredPathsMaxSize2 = 1e3;
11954
+ var discoveredPaths2 = /* @__PURE__ */ new Set();
11955
+ var URL_LIMIT2 = 7680;
11956
+ async function fetchAndApplyManifestPatches2(paths, decode2, signal) {
11957
+ let basename = (window.__router.basename ?? "").replace(/^\/|\/$/g, "");
11958
+ let url = new URL(`${basename}/.manifest`, window.location.origin);
11959
+ paths.sort().forEach((path) => url.searchParams.append("p", path));
11960
+ if (url.toString().length > URL_LIMIT2) {
11961
+ nextPaths2.clear();
11962
+ return;
11963
+ }
11964
+ let response = await fetch(url, { signal });
11965
+ if (!response.body || response.status < 200 || response.status >= 300) {
11966
+ throw new Error("Unable to fetch new route matches from the server");
11967
+ }
11968
+ let payload = await decode2(response.body);
11969
+ if (payload.type !== "manifest") {
11970
+ throw new Error("Failed to patch routes");
11971
+ }
11972
+ paths.forEach((p) => addToFifoQueue2(p, discoveredPaths2));
11973
+ payload.patches.forEach((p) => {
11974
+ window.__router.patchRoutes(p.parentId ?? null, [
11975
+ createRouteFromServerManifest(p)
11976
+ ]);
11977
+ });
11978
+ }
11979
+ function addToFifoQueue2(path, queue) {
11980
+ if (queue.size >= discoveredPathsMaxSize2) {
11981
+ let first = queue.values().next().value;
11982
+ queue.delete(first);
11983
+ }
11984
+ queue.add(path);
11985
+ }
11986
+ function debounce2(callback, wait) {
11987
+ let timeoutId;
11988
+ return (...args) => {
11989
+ window.clearTimeout(timeoutId);
11990
+ timeoutId = window.setTimeout(() => callback(...args), wait);
11991
+ };
11992
+ }
11993
+
11994
+ // lib/rsc/server.ssr.tsx
11995
+ import * as React15 from "react";
11996
+
11997
+ // lib/rsc/html-stream/server.ts
11998
+ var encoder2 = new TextEncoder();
11999
+ var trailer = "</body></html>";
12000
+ function injectRSCPayload(rscStream) {
12001
+ let decoder = new TextDecoder();
12002
+ let resolveFlightDataPromise;
12003
+ let flightDataPromise = new Promise(
12004
+ (resolve) => resolveFlightDataPromise = resolve
12005
+ );
12006
+ let startedRSC = false;
12007
+ let buffered = [];
12008
+ let timeout = null;
12009
+ function flushBufferedChunks(controller) {
12010
+ for (let chunk of buffered) {
12011
+ let buf = decoder.decode(chunk, { stream: true });
12012
+ if (buf.endsWith(trailer)) {
12013
+ buf = buf.slice(0, -trailer.length);
12014
+ }
12015
+ controller.enqueue(encoder2.encode(buf));
12016
+ }
12017
+ buffered.length = 0;
12018
+ timeout = null;
12019
+ }
12020
+ return new TransformStream({
12021
+ transform(chunk, controller) {
12022
+ buffered.push(chunk);
12023
+ if (timeout) {
12024
+ return;
12025
+ }
12026
+ timeout = setTimeout(async () => {
12027
+ flushBufferedChunks(controller);
12028
+ if (!startedRSC) {
12029
+ startedRSC = true;
12030
+ writeRSCStream(rscStream, controller).catch((err) => controller.error(err)).then(resolveFlightDataPromise);
12031
+ }
12032
+ }, 0);
12033
+ },
12034
+ async flush(controller) {
12035
+ await flightDataPromise;
12036
+ if (timeout) {
12037
+ clearTimeout(timeout);
12038
+ flushBufferedChunks(controller);
12039
+ }
12040
+ controller.enqueue(encoder2.encode("</body></html>"));
12041
+ }
12042
+ });
12043
+ }
12044
+ async function writeRSCStream(rscStream, controller) {
12045
+ let decoder = new TextDecoder("utf-8", { fatal: true });
12046
+ const reader = rscStream.getReader();
12047
+ try {
12048
+ let read;
12049
+ while ((read = await reader.read()) && !read.done) {
12050
+ const chunk = read.value;
12051
+ try {
12052
+ writeChunk(
12053
+ JSON.stringify(decoder.decode(chunk, { stream: true })),
12054
+ controller
12055
+ );
12056
+ } catch (err) {
12057
+ let base64 = JSON.stringify(btoa(String.fromCodePoint(...chunk)));
12058
+ writeChunk(
12059
+ `Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`,
12060
+ controller
12061
+ );
12062
+ }
12063
+ }
12064
+ } finally {
12065
+ reader.releaseLock();
12066
+ }
12067
+ let remaining = decoder.decode();
12068
+ if (remaining.length) {
12069
+ writeChunk(JSON.stringify(remaining), controller);
12070
+ }
12071
+ }
12072
+ function writeChunk(chunk, controller) {
12073
+ controller.enqueue(
12074
+ encoder2.encode(
12075
+ `<script>${escapeScript(
12076
+ `(self.__FLIGHT_DATA||=[]).push(${chunk})`
12077
+ )}</script>`
12078
+ )
12079
+ );
12080
+ }
12081
+ function escapeScript(script) {
12082
+ return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
12083
+ }
12084
+
12085
+ // lib/rsc/server.ssr.tsx
12086
+ async function routeRSCServerRequest({
12087
+ request,
12088
+ callServer,
12089
+ decode: decode2,
12090
+ renderHTML,
12091
+ hydrate: hydrate2 = true
12092
+ }) {
12093
+ const url = new URL(request.url);
12094
+ let serverRequest = request;
12095
+ const isDataRequest = isReactServerRequest(url);
12096
+ const respondWithRSCPayload = isDataRequest || isManifestRequest(url) || request.headers.has("rsc-action-id");
12097
+ if (isDataRequest) {
12098
+ const serverURL = new URL(request.url);
12099
+ serverURL.pathname = serverURL.pathname.replace(/(_root)?\.rsc$/, "");
12100
+ let headers = new Headers(request.headers);
12101
+ headers.set("X-React-Router-Data-Request", "true");
12102
+ serverRequest = new Request(serverURL, {
12103
+ body: request.body,
12104
+ duplex: request.body ? "half" : void 0,
12105
+ headers,
12106
+ method: request.method,
12107
+ signal: request.signal
12108
+ });
12109
+ }
12110
+ const serverResponse = await callServer(serverRequest);
12111
+ if (respondWithRSCPayload) {
12112
+ return serverResponse;
12113
+ }
12114
+ if (!serverResponse.body) {
12115
+ throw new Error("Missing body in server response");
12116
+ }
12117
+ let serverResponseB = null;
12118
+ if (hydrate2) {
12119
+ serverResponseB = serverResponse.clone();
12120
+ }
12121
+ const body = serverResponse.body;
12122
+ let payloadPromise;
12123
+ const getPayload = async () => {
12124
+ if (payloadPromise) return payloadPromise;
12125
+ payloadPromise = decode2(body);
12126
+ return payloadPromise;
12127
+ };
12128
+ try {
12129
+ const html = await renderHTML(getPayload);
12130
+ const headers = new Headers(serverResponse.headers);
12131
+ headers.set("Content-Type", "text/html");
12132
+ if (!hydrate2) {
12133
+ return new Response(html, {
12134
+ status: serverResponse.status,
12135
+ headers
12136
+ });
12137
+ }
12138
+ if (!serverResponseB?.body) {
12139
+ throw new Error("Failed to clone server response");
12140
+ }
12141
+ const body2 = html.pipeThrough(injectRSCPayload(serverResponseB.body));
12142
+ return new Response(body2, {
12143
+ status: serverResponse.status,
12144
+ headers
12145
+ });
12146
+ } catch (reason) {
12147
+ if (reason instanceof Response) {
12148
+ return reason;
12149
+ }
12150
+ throw reason;
12151
+ }
12152
+ }
12153
+ function RSCStaticRouter({
12154
+ getPayload
12155
+ }) {
12156
+ const payload = React15.use(getPayload());
12157
+ if (payload.type === "redirect") {
12158
+ throw new Response(null, {
12159
+ status: payload.status,
12160
+ headers: {
12161
+ Location: payload.location
12162
+ }
12163
+ });
12164
+ }
12165
+ if (payload.type !== "render") return null;
12166
+ const context = {
12167
+ actionData: payload.actionData,
12168
+ actionHeaders: {},
12169
+ basename: payload.basename,
12170
+ errors: payload.errors,
12171
+ loaderData: payload.loaderData,
12172
+ loaderHeaders: {},
12173
+ location: payload.location,
12174
+ statusCode: 200,
12175
+ matches: payload.matches.map((match) => ({
12176
+ params: match.params,
12177
+ pathname: match.pathname,
12178
+ pathnameBase: match.pathnameBase,
12179
+ route: {
12180
+ id: match.id,
12181
+ action: match.hasAction || !!match.clientAction,
12182
+ handle: match.handle,
12183
+ hasErrorBoundary: match.hasErrorBoundary,
12184
+ loader: match.hasLoader || !!match.clientLoader,
12185
+ index: match.index,
12186
+ path: match.path,
12187
+ shouldRevalidate: match.shouldRevalidate
12188
+ }
12189
+ }))
12190
+ };
12191
+ const router = createStaticRouter(
12192
+ payload.matches.reduceRight((previous, match) => {
12193
+ const route = {
12194
+ id: match.id,
12195
+ action: match.hasAction || !!match.clientAction,
12196
+ element: match.element,
12197
+ errorElement: match.errorElement,
12198
+ handle: match.handle,
12199
+ hasErrorBoundary: !!match.errorElement,
12200
+ hydrateFallbackElement: match.hydrateFallbackElement,
12201
+ index: match.index,
12202
+ loader: match.hasLoader || !!match.clientLoader,
12203
+ path: match.path,
12204
+ shouldRevalidate: match.shouldRevalidate
12205
+ };
12206
+ if (previous.length > 0) {
12207
+ route.children = previous;
12208
+ }
12209
+ return [route];
12210
+ }, []),
12211
+ context
12212
+ );
12213
+ const frameworkContext = {
12214
+ future: {
12215
+ // These flags have no runtime impact so can always be false. If we add
12216
+ // flags that drive runtime behavior they'll need to be proxied through.
12217
+ unstable_middleware: false,
12218
+ unstable_subResourceIntegrity: false
12219
+ },
12220
+ isSpaMode: false,
12221
+ ssr: true,
12222
+ criticalCss: "",
12223
+ manifest: {
12224
+ routes: {},
12225
+ version: "1",
12226
+ url: "",
12227
+ entry: {
12228
+ module: "",
12229
+ imports: []
12230
+ }
12231
+ },
12232
+ routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
12233
+ routeModules: {}
12234
+ };
12235
+ return /* @__PURE__ */ React15.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React15.createElement(
12236
+ StaticRouterProvider,
12237
+ {
12238
+ context,
12239
+ router,
12240
+ hydrate: false,
12241
+ nonce: payload.nonce
12242
+ }
12243
+ ));
12244
+ }
12245
+ function isReactServerRequest(url) {
12246
+ return url.pathname.endsWith(".rsc");
12247
+ }
12248
+ function isManifestRequest(url) {
12249
+ return url.pathname.endsWith(".manifest");
12250
+ }
12251
+
12252
+ // lib/rsc/html-stream/browser.ts
12253
+ function getServerStream() {
12254
+ let encoder3 = new TextEncoder();
12255
+ let streamController = null;
12256
+ let rscStream = new ReadableStream({
12257
+ start(controller) {
12258
+ if (typeof window === "undefined") {
12259
+ return;
12260
+ }
12261
+ let handleChunk = (chunk) => {
12262
+ if (typeof chunk === "string") {
12263
+ controller.enqueue(encoder3.encode(chunk));
12264
+ } else {
12265
+ controller.enqueue(chunk);
12266
+ }
12267
+ };
12268
+ window.__FLIGHT_DATA || (window.__FLIGHT_DATA = []);
12269
+ window.__FLIGHT_DATA.forEach(handleChunk);
12270
+ window.__FLIGHT_DATA.push = (chunk) => {
12271
+ handleChunk(chunk);
12272
+ return 0;
12273
+ };
12274
+ streamController = controller;
12275
+ }
12276
+ });
12277
+ if (typeof document !== "undefined" && document.readyState === "loading") {
12278
+ document.addEventListener("DOMContentLoaded", () => {
12279
+ streamController?.close();
12280
+ });
12281
+ } else {
12282
+ streamController?.close();
12283
+ }
12284
+ return rscStream;
12285
+ }
12286
+
11391
12287
  // lib/dom/ssr/errors.ts
11392
12288
  function deserializeErrors2(errors) {
11393
12289
  if (!errors) return null;
@@ -11425,32 +12321,6 @@ function deserializeErrors2(errors) {
11425
12321
  return serialized;
11426
12322
  }
11427
12323
 
11428
- // lib/dom/ssr/hydration.tsx
11429
- function getHydrationData(state, routes, getRouteInfo, location, basename, isSpaMode) {
11430
- let hydrationData = {
11431
- ...state,
11432
- loaderData: { ...state.loaderData }
11433
- };
11434
- let initialMatches = matchRoutes(routes, location, basename);
11435
- if (initialMatches) {
11436
- for (let match of initialMatches) {
11437
- let routeId = match.route.id;
11438
- let routeInfo = getRouteInfo(routeId);
11439
- if (shouldHydrateRouteLoader(
11440
- routeId,
11441
- routeInfo.clientLoader,
11442
- routeInfo.hasLoader,
11443
- isSpaMode
11444
- ) && (routeInfo.hasHydrateFallback || !routeInfo.hasLoader)) {
11445
- delete hydrationData.loaderData[routeId];
11446
- } else if (!routeInfo.hasLoader) {
11447
- hydrationData.loaderData[routeId] = null;
11448
- }
11449
- }
11450
- }
11451
- return hydrationData;
11452
- }
11453
-
11454
12324
  export {
11455
12325
  Action,
11456
12326
  createBrowserHistory,
@@ -11569,6 +12439,11 @@ export {
11569
12439
  createCookieSessionStorage,
11570
12440
  createMemorySessionStorage,
11571
12441
  href,
11572
- deserializeErrors2 as deserializeErrors,
11573
- getHydrationData
12442
+ getHydrationData,
12443
+ createCallServer,
12444
+ RSCHydratedRouter,
12445
+ routeRSCServerRequest,
12446
+ RSCStaticRouter,
12447
+ getServerStream,
12448
+ deserializeErrors2 as deserializeErrors
11574
12449
  };