react-router 7.1.5 → 7.2.0-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/development/{chunk-IR6S3I6Y.mjs → chunk-HLU4BUUT.mjs} +244 -78
  3. package/dist/development/dom-export.d.mts +2 -2
  4. package/dist/development/dom-export.d.ts +2 -2
  5. package/dist/development/dom-export.js +222 -58
  6. package/dist/development/dom-export.mjs +12 -4
  7. package/dist/{production/fog-of-war-CCAcUMgB.d.ts → development/fog-of-war-Ax4Jg2xL.d.ts} +9 -5
  8. package/dist/development/{fog-of-war-D6dP9JIt.d.mts → fog-of-war-Cyo_TZuh.d.mts} +9 -5
  9. package/dist/development/index.d.mts +10 -5
  10. package/dist/development/index.d.ts +10 -5
  11. package/dist/development/index.js +244 -78
  12. package/dist/development/index.mjs +2 -2
  13. package/dist/development/lib/types/route-module.d.mts +3 -1
  14. package/dist/development/lib/types/route-module.d.ts +3 -1
  15. package/dist/development/lib/types/route-module.js +1 -1
  16. package/dist/development/lib/types/route-module.mjs +1 -1
  17. package/dist/development/{route-data-Cq_b5feC.d.ts → route-data-DQbTMaUY.d.mts} +1 -0
  18. package/dist/{production/route-data-Cq_b5feC.d.mts → development/route-data-DQbTMaUY.d.ts} +1 -0
  19. package/dist/production/{chunk-JRAGQQ3X.mjs → chunk-IA3JXIZE.mjs} +244 -78
  20. package/dist/production/dom-export.d.mts +2 -2
  21. package/dist/production/dom-export.d.ts +2 -2
  22. package/dist/production/dom-export.js +222 -58
  23. package/dist/production/dom-export.mjs +12 -4
  24. package/dist/{development/fog-of-war-CCAcUMgB.d.ts → production/fog-of-war-Ax4Jg2xL.d.ts} +9 -5
  25. package/dist/production/{fog-of-war-D6dP9JIt.d.mts → fog-of-war-Cyo_TZuh.d.mts} +9 -5
  26. package/dist/production/index.d.mts +10 -5
  27. package/dist/production/index.d.ts +10 -5
  28. package/dist/production/index.js +244 -78
  29. package/dist/production/index.mjs +2 -2
  30. package/dist/production/lib/types/route-module.d.mts +3 -1
  31. package/dist/production/lib/types/route-module.d.ts +3 -1
  32. package/dist/production/lib/types/route-module.js +1 -1
  33. package/dist/production/lib/types/route-module.mjs +1 -1
  34. package/dist/production/{route-data-Cq_b5feC.d.ts → route-data-DQbTMaUY.d.mts} +1 -0
  35. package/dist/{development/route-data-Cq_b5feC.d.mts → production/route-data-DQbTMaUY.d.ts} +1 -0
  36. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.1.5
2
+ * react-router v7.2.0-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -2604,6 +2604,7 @@ function createRouter(init) {
2604
2604
  let localManifest = manifest;
2605
2605
  try {
2606
2606
  await patchRoutesOnNavigationImpl({
2607
+ signal,
2607
2608
  path: pathname,
2608
2609
  matches: partialMatches,
2609
2610
  patch: (routeId, children) => {
@@ -5504,14 +5505,23 @@ function getKeyedLinksForMatches(matches, routeModules, manifest) {
5504
5505
  module2?.links?.() || []
5505
5506
  ];
5506
5507
  }).flat(2);
5507
- let preloads = getCurrentPageModulePreloadHrefs(matches, manifest);
5508
+ let preloads = getModuleLinkHrefs(matches, manifest);
5508
5509
  return dedupeLinkDescriptors(descriptors, preloads);
5509
5510
  }
5511
+ function getRouteCssDescriptors(route) {
5512
+ if (!route.css) return [];
5513
+ return route.css.map((href) => ({ rel: "stylesheet", href }));
5514
+ }
5515
+ async function prefetchRouteCss(route) {
5516
+ if (!route.css) return;
5517
+ let descriptors = getRouteCssDescriptors(route);
5518
+ await Promise.all(descriptors.map(prefetchStyleLink));
5519
+ }
5510
5520
  async function prefetchStyleLinks(route, routeModule) {
5511
5521
  if (!route.css && !routeModule.links || !isPreloadSupported()) return;
5512
5522
  let descriptors = [];
5513
5523
  if (route.css) {
5514
- descriptors.push(...route.css.map((href) => ({ rel: "stylesheet", href })));
5524
+ descriptors.push(...getRouteCssDescriptors(route));
5515
5525
  }
5516
5526
  if (routeModule.links) {
5517
5527
  descriptors.push(...routeModule.links());
@@ -5527,13 +5537,15 @@ async function prefetchStyleLinks(route, routeModule) {
5527
5537
  });
5528
5538
  }
5529
5539
  }
5530
- let matchingLinks = styleLinks.filter(
5531
- (link) => (!link.media || window.matchMedia(link.media).matches) && !document.querySelector(`link[rel="stylesheet"][href="${link.href}"]`)
5532
- );
5533
- await Promise.all(matchingLinks.map(prefetchStyleLink));
5540
+ await Promise.all(styleLinks.map(prefetchStyleLink));
5534
5541
  }
5535
5542
  async function prefetchStyleLink(descriptor) {
5536
5543
  return new Promise((resolve) => {
5544
+ if (descriptor.media && !window.matchMedia(descriptor.media).matches || document.querySelector(
5545
+ `link[rel="stylesheet"][href="${descriptor.href}"]`
5546
+ )) {
5547
+ return resolve();
5548
+ }
5537
5549
  let link = document.createElement("link");
5538
5550
  Object.assign(link, descriptor);
5539
5551
  function removeLink() {
@@ -5628,25 +5640,21 @@ function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, loca
5628
5640
  }
5629
5641
  return [];
5630
5642
  }
5631
- function getModuleLinkHrefs(matches, manifestPatch) {
5632
- return dedupeHrefs(
5633
- matches.map((match) => {
5634
- let route = manifestPatch.routes[match.route.id];
5635
- if (!route) return [];
5636
- let hrefs = [route.module];
5637
- if (route.imports) {
5638
- hrefs = hrefs.concat(route.imports);
5639
- }
5640
- return hrefs;
5641
- }).flat(1)
5642
- );
5643
- }
5644
- function getCurrentPageModulePreloadHrefs(matches, manifest) {
5643
+ function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
5645
5644
  return dedupeHrefs(
5646
5645
  matches.map((match) => {
5647
5646
  let route = manifest.routes[match.route.id];
5648
5647
  if (!route) return [];
5649
5648
  let hrefs = [route.module];
5649
+ if (route.clientActionModule) {
5650
+ hrefs = hrefs.concat(route.clientActionModule);
5651
+ }
5652
+ if (route.clientLoaderModule) {
5653
+ hrefs = hrefs.concat(route.clientLoaderModule);
5654
+ }
5655
+ if (includeHydrateFallback && route.hydrateFallbackModule) {
5656
+ hrefs = hrefs.concat(route.hydrateFallbackModule);
5657
+ }
5650
5658
  if (route.imports) {
5651
5659
  hrefs = hrefs.concat(route.imports);
5652
5660
  }
@@ -5801,17 +5809,31 @@ function StreamTransfer({
5801
5809
  )));
5802
5810
  }
5803
5811
  }
5804
- function getSingleFetchDataStrategy(manifest, routeModules, getRouter) {
5812
+ function getSingleFetchDataStrategy(manifest, routeModules, ssr, getRouter) {
5805
5813
  return async ({ request, matches, fetcherKey }) => {
5806
5814
  if (request.method !== "GET") {
5807
5815
  return singleFetchActionStrategy(request, matches);
5808
5816
  }
5817
+ if (!ssr) {
5818
+ let foundLoaderBelowRoot = matches.some(
5819
+ (m) => m.route.id !== "root" && manifest.routes[m.route.id]?.hasLoader
5820
+ );
5821
+ if (!foundLoaderBelowRoot) {
5822
+ let matchesToLoad = matches.filter((m) => m.shouldLoad);
5823
+ let results = await Promise.all(matchesToLoad.map((m) => m.resolve()));
5824
+ return results.reduce(
5825
+ (acc, result, i) => Object.assign(acc, { [matchesToLoad[i].route.id]: result }),
5826
+ {}
5827
+ );
5828
+ }
5829
+ }
5809
5830
  if (fetcherKey) {
5810
5831
  return singleFetchLoaderFetcherStrategy(request, matches);
5811
5832
  }
5812
5833
  return singleFetchLoaderNavigationStrategy(
5813
5834
  manifest,
5814
5835
  routeModules,
5836
+ ssr,
5815
5837
  getRouter(),
5816
5838
  request,
5817
5839
  matches
@@ -5845,7 +5867,7 @@ async function singleFetchActionStrategy(request, matches) {
5845
5867
  }
5846
5868
  };
5847
5869
  }
5848
- async function singleFetchLoaderNavigationStrategy(manifest, routeModules, router, request, matches) {
5870
+ async function singleFetchLoaderNavigationStrategy(manifest, routeModules, ssr, router, request, matches) {
5849
5871
  let routesParams = /* @__PURE__ */ new Set();
5850
5872
  let foundOptOutRoute = false;
5851
5873
  let routeDfds = matches.map(() => createDeferred2());
@@ -5911,7 +5933,7 @@ async function singleFetchLoaderNavigationStrategy(manifest, routeModules, route
5911
5933
  singleFetchDfd.resolve({});
5912
5934
  } else {
5913
5935
  try {
5914
- if (foundOptOutRoute && routesParams.size > 0) {
5936
+ if (ssr && foundOptOutRoute && routesParams.size > 0) {
5915
5937
  url.searchParams.set(
5916
5938
  "_routes",
5917
5939
  matches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(",")
@@ -6279,11 +6301,12 @@ function createServerRoutes(manifest, routeModules, future, isSpaMode, parentId
6279
6301
  return dataRoute;
6280
6302
  });
6281
6303
  }
6282
- function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation, manifest, routeModulesCache, initialState, future, isSpaMode) {
6304
+ function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation, manifest, routeModulesCache, initialState, ssr, isSpaMode) {
6283
6305
  return createClientRoutes(
6284
6306
  manifest,
6285
6307
  routeModulesCache,
6286
6308
  initialState,
6309
+ ssr,
6287
6310
  isSpaMode,
6288
6311
  "",
6289
6312
  groupRoutesByParentId(manifest),
@@ -6292,14 +6315,14 @@ function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation, manifest
6292
6315
  }
6293
6316
  function preventInvalidServerHandlerCall(type, route, isSpaMode) {
6294
6317
  if (isSpaMode) {
6295
- let fn2 = type === "action" ? "serverAction()" : "serverLoader()";
6296
- let msg2 = `You cannot call ${fn2} in SPA Mode (routeId: "${route.id}")`;
6297
- console.error(msg2);
6298
- throw new ErrorResponseImpl(400, "Bad Request", new Error(msg2), true);
6318
+ let fn = type === "action" ? "serverAction()" : "serverLoader()";
6319
+ let msg = `You cannot call ${fn} in SPA Mode (routeId: "${route.id}")`;
6320
+ console.error(msg);
6321
+ throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
6299
6322
  }
6300
- let fn = type === "action" ? "serverAction()" : "serverLoader()";
6301
- let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${route.id}")`;
6302
6323
  if (type === "loader" && !route.hasLoader || type === "action" && !route.hasAction) {
6324
+ let fn = type === "action" ? "serverAction()" : "serverLoader()";
6325
+ let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${route.id}")`;
6303
6326
  console.error(msg);
6304
6327
  throw new ErrorResponseImpl(400, "Bad Request", new Error(msg), true);
6305
6328
  }
@@ -6310,7 +6333,7 @@ function noActionDefinedError(type, routeId) {
6310
6333
  console.error(msg);
6311
6334
  throw new ErrorResponseImpl(405, "Method Not Allowed", new Error(msg), true);
6312
6335
  }
6313
- function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode, parentId = "", routesByParentId = groupRoutesByParentId(manifest), needsRevalidation) {
6336
+ function createClientRoutes(manifest, routeModulesCache, initialState, ssr, isSpaMode, parentId = "", routesByParentId = groupRoutesByParentId(manifest), needsRevalidation) {
6314
6337
  return (routesByParentId[parentId] || []).map((route) => {
6315
6338
  let routeModule = routeModulesCache[route.id];
6316
6339
  function fetchServerHandler(singleFetch) {
@@ -6330,6 +6353,21 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6330
6353
  }
6331
6354
  return fetchServerHandler(singleFetch);
6332
6355
  }
6356
+ function prefetchModule(modulePath) {
6357
+ import(
6358
+ /* @vite-ignore */
6359
+ /* webpackIgnore: true */
6360
+ modulePath
6361
+ );
6362
+ }
6363
+ function prefetchRouteModuleChunks(route2) {
6364
+ if (route2.clientActionModule) {
6365
+ prefetchModule(route2.clientActionModule);
6366
+ }
6367
+ if (route2.clientLoaderModule) {
6368
+ prefetchModule(route2.clientLoaderModule);
6369
+ }
6370
+ }
6333
6371
  async function prefetchStylesAndCallHandler(handler) {
6334
6372
  let cachedModule = routeModulesCache[route.id];
6335
6373
  let linkPrefetchPromise = cachedModule ? prefetchStyleLinks(route, cachedModule) : Promise.resolve();
@@ -6351,7 +6389,8 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6351
6389
  handle: routeModule.handle,
6352
6390
  shouldRevalidate: getShouldRevalidateFunction(
6353
6391
  routeModule,
6354
- route.id,
6392
+ route,
6393
+ ssr,
6355
6394
  needsRevalidation
6356
6395
  )
6357
6396
  });
@@ -6368,7 +6407,6 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6368
6407
  "No `routeModule` available for critical-route loader"
6369
6408
  );
6370
6409
  if (!routeModule.clientLoader) {
6371
- if (isSpaMode) return null;
6372
6410
  return fetchServerLoader(singleFetch);
6373
6411
  }
6374
6412
  return routeModule.clientLoader({
@@ -6423,9 +6461,24 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6423
6461
  } else {
6424
6462
  if (!route.hasClientLoader) {
6425
6463
  dataRoute.loader = ({ request }, singleFetch) => prefetchStylesAndCallHandler(() => {
6426
- if (isSpaMode) return Promise.resolve(null);
6427
6464
  return fetchServerLoader(singleFetch);
6428
6465
  });
6466
+ } else if (route.clientLoaderModule) {
6467
+ dataRoute.loader = async (args, singleFetch) => {
6468
+ invariant2(route.clientLoaderModule);
6469
+ let { clientLoader } = await import(
6470
+ /* @vite-ignore */
6471
+ /* webpackIgnore: true */
6472
+ route.clientLoaderModule
6473
+ );
6474
+ return clientLoader({
6475
+ ...args,
6476
+ async serverLoader() {
6477
+ preventInvalidServerHandlerCall("loader", route, isSpaMode);
6478
+ return fetchServerLoader(singleFetch);
6479
+ }
6480
+ });
6481
+ };
6429
6482
  }
6430
6483
  if (!route.hasClientAction) {
6431
6484
  dataRoute.action = ({ request }, singleFetch) => prefetchStylesAndCallHandler(() => {
@@ -6434,12 +6487,34 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6434
6487
  }
6435
6488
  return fetchServerAction(singleFetch);
6436
6489
  });
6490
+ } else if (route.clientActionModule) {
6491
+ dataRoute.action = async (args, singleFetch) => {
6492
+ invariant2(route.clientActionModule);
6493
+ prefetchRouteModuleChunks(route);
6494
+ let { clientAction } = await import(
6495
+ /* @vite-ignore */
6496
+ /* webpackIgnore: true */
6497
+ route.clientActionModule
6498
+ );
6499
+ return clientAction({
6500
+ ...args,
6501
+ async serverAction() {
6502
+ preventInvalidServerHandlerCall("action", route, isSpaMode);
6503
+ return fetchServerAction(singleFetch);
6504
+ }
6505
+ });
6506
+ };
6437
6507
  }
6438
6508
  dataRoute.lazy = async () => {
6439
- let mod = await loadRouteModuleWithBlockingLinks(
6509
+ if (route.clientLoaderModule || route.clientActionModule) {
6510
+ await new Promise((resolve) => setTimeout(resolve, 0));
6511
+ }
6512
+ let modPromise = loadRouteModuleWithBlockingLinks(
6440
6513
  route,
6441
6514
  routeModulesCache
6442
6515
  );
6516
+ prefetchRouteModuleChunks(route);
6517
+ let mod = await modPromise;
6443
6518
  let lazyRoute = { ...mod };
6444
6519
  if (mod.clientLoader) {
6445
6520
  let clientLoader = mod.clientLoader;
@@ -6467,7 +6542,8 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6467
6542
  hasErrorBoundary: lazyRoute.hasErrorBoundary,
6468
6543
  shouldRevalidate: getShouldRevalidateFunction(
6469
6544
  lazyRoute,
6470
- route.id,
6545
+ route,
6546
+ ssr,
6471
6547
  needsRevalidation
6472
6548
  ),
6473
6549
  handle: lazyRoute.handle,
@@ -6482,6 +6558,7 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6482
6558
  manifest,
6483
6559
  routeModulesCache,
6484
6560
  initialState,
6561
+ ssr,
6485
6562
  isSpaMode,
6486
6563
  route.id,
6487
6564
  routesByParentId,
@@ -6491,15 +6568,18 @@ function createClientRoutes(manifest, routeModulesCache, initialState, isSpaMode
6491
6568
  return dataRoute;
6492
6569
  });
6493
6570
  }
6494
- function getShouldRevalidateFunction(route, routeId, needsRevalidation) {
6571
+ function getShouldRevalidateFunction(route, manifestRoute, ssr, needsRevalidation) {
6495
6572
  if (needsRevalidation) {
6496
6573
  return wrapShouldRevalidateForHdr(
6497
- routeId,
6574
+ manifestRoute.id,
6498
6575
  route.shouldRevalidate,
6499
6576
  needsRevalidation
6500
6577
  );
6501
6578
  }
6502
- if (route.shouldRevalidate) {
6579
+ if (!ssr && manifestRoute.id === "root" && manifestRoute.hasLoader && !manifestRoute.hasClientLoader) {
6580
+ return () => false;
6581
+ }
6582
+ if (ssr && route.shouldRevalidate) {
6503
6583
  let fn = route.shouldRevalidate;
6504
6584
  return (opts) => fn({ ...opts, defaultShouldRevalidate: true });
6505
6585
  }
@@ -6516,8 +6596,13 @@ function wrapShouldRevalidateForHdr(routeId, routeShouldRevalidate, needsRevalid
6516
6596
  };
6517
6597
  }
6518
6598
  async function loadRouteModuleWithBlockingLinks(route, routeModules) {
6519
- let routeModule = await loadRouteModule(route, routeModules);
6520
- await prefetchStyleLinks(route, routeModule);
6599
+ let routeModulePromise = loadRouteModule(route, routeModules);
6600
+ let prefetchRouteCssPromise = prefetchRouteCss(route);
6601
+ let routeModule = await routeModulePromise;
6602
+ await Promise.all([
6603
+ prefetchRouteCssPromise,
6604
+ prefetchStyleLinks(route, routeModule)
6605
+ ]);
6521
6606
  return {
6522
6607
  Component: getRouteModuleComponent(routeModule),
6523
6608
  ErrorBoundary: routeModule.ErrorBoundary,
@@ -6545,8 +6630,8 @@ var nextPaths = /* @__PURE__ */ new Set();
6545
6630
  var discoveredPathsMaxSize = 1e3;
6546
6631
  var discoveredPaths = /* @__PURE__ */ new Set();
6547
6632
  var URL_LIMIT = 7680;
6548
- function isFogOfWarEnabled(isSpaMode) {
6549
- return !isSpaMode;
6633
+ function isFogOfWarEnabled(ssr) {
6634
+ return ssr === true;
6550
6635
  }
6551
6636
  function getPartialManifest(manifest, router) {
6552
6637
  let routeIds = new Set(router.state.matches.map((m) => m.route.id));
@@ -6572,11 +6657,11 @@ function getPartialManifest(manifest, router) {
6572
6657
  routes: initialRoutes
6573
6658
  };
6574
6659
  }
6575
- function getPatchRoutesOnNavigationFunction(manifest, routeModules, isSpaMode, basename) {
6576
- if (!isFogOfWarEnabled(isSpaMode)) {
6660
+ function getPatchRoutesOnNavigationFunction(manifest, routeModules, ssr, isSpaMode, basename) {
6661
+ if (!isFogOfWarEnabled(ssr)) {
6577
6662
  return void 0;
6578
6663
  }
6579
- return async ({ path, patch }) => {
6664
+ return async ({ path, patch, signal }) => {
6580
6665
  if (discoveredPaths.has(path)) {
6581
6666
  return;
6582
6667
  }
@@ -6584,15 +6669,17 @@ function getPatchRoutesOnNavigationFunction(manifest, routeModules, isSpaMode, b
6584
6669
  [path],
6585
6670
  manifest,
6586
6671
  routeModules,
6672
+ ssr,
6587
6673
  isSpaMode,
6588
6674
  basename,
6589
- patch
6675
+ patch,
6676
+ signal
6590
6677
  );
6591
6678
  };
6592
6679
  }
6593
- function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
6680
+ function useFogOFWarDiscovery(router, manifest, routeModules, ssr, isSpaMode) {
6594
6681
  React8.useEffect(() => {
6595
- if (!isFogOfWarEnabled(isSpaMode) || navigator.connection?.saveData === true) {
6682
+ if (!isFogOfWarEnabled(ssr) || navigator.connection?.saveData === true) {
6596
6683
  return;
6597
6684
  }
6598
6685
  function registerElement(el) {
@@ -6622,6 +6709,7 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
6622
6709
  lazyPaths,
6623
6710
  manifest,
6624
6711
  routeModules,
6712
+ ssr,
6625
6713
  isSpaMode,
6626
6714
  router.basename,
6627
6715
  router.patchRoutes
@@ -6640,9 +6728,9 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
6640
6728
  attributeFilter: ["data-discover", "href", "action"]
6641
6729
  });
6642
6730
  return () => observer.disconnect();
6643
- }, [isSpaMode, manifest, routeModules, router]);
6731
+ }, [ssr, isSpaMode, manifest, routeModules, router]);
6644
6732
  }
6645
- async function fetchAndApplyManifestPatches(paths, manifest, routeModules, isSpaMode, basename, patchRoutes) {
6733
+ async function fetchAndApplyManifestPatches(paths, manifest, routeModules, ssr, isSpaMode, basename, patchRoutes, signal) {
6646
6734
  let manifestPath = `${basename != null ? basename : "/"}/__manifest`.replace(
6647
6735
  /\/+/g,
6648
6736
  "/"
@@ -6654,13 +6742,19 @@ async function fetchAndApplyManifestPatches(paths, manifest, routeModules, isSpa
6654
6742
  nextPaths.clear();
6655
6743
  return;
6656
6744
  }
6657
- let res = await fetch(url);
6658
- if (!res.ok) {
6659
- throw new Error(`${res.status} ${res.statusText}`);
6660
- } else if (res.status >= 400) {
6661
- throw new Error(await res.text());
6745
+ let serverPatches;
6746
+ try {
6747
+ let res = await fetch(url, { signal });
6748
+ if (!res.ok) {
6749
+ throw new Error(`${res.status} ${res.statusText}`);
6750
+ } else if (res.status >= 400) {
6751
+ throw new Error(await res.text());
6752
+ }
6753
+ serverPatches = await res.json();
6754
+ } catch (e) {
6755
+ if (signal?.aborted) return;
6756
+ throw e;
6662
6757
  }
6663
- let serverPatches = await res.json();
6664
6758
  let knownRoutes = new Set(Object.keys(manifest.routes));
6665
6759
  let patches = Object.values(serverPatches).reduce((acc, route) => {
6666
6760
  if (route && !knownRoutes.has(route.id)) {
@@ -6679,7 +6773,7 @@ async function fetchAndApplyManifestPatches(paths, manifest, routeModules, isSpa
6679
6773
  parentIds.forEach(
6680
6774
  (parentId) => patchRoutes(
6681
6775
  parentId || null,
6682
- createClientRoutes(patches, routeModules, null, isSpaMode, parentId)
6776
+ createClientRoutes(patches, routeModules, null, ssr, isSpaMode, parentId)
6683
6777
  )
6684
6778
  );
6685
6779
  }
@@ -7028,10 +7122,10 @@ function isValidMetaTag(tagName) {
7028
7122
  }
7029
7123
  var isHydrated = false;
7030
7124
  function Scripts(props) {
7031
- let { manifest, serverHandoffString, isSpaMode, renderMeta } = useFrameworkContext();
7125
+ let { manifest, serverHandoffString, isSpaMode, ssr, renderMeta } = useFrameworkContext();
7032
7126
  let { router, static: isStatic, staticContext } = useDataRouterContext2();
7033
7127
  let { matches: routerMatches } = useDataRouterStateContext();
7034
- let enableFogOfWar = isFogOfWarEnabled(isSpaMode);
7128
+ let enableFogOfWar = isFogOfWarEnabled(ssr);
7035
7129
  if (renderMeta) {
7036
7130
  renderMeta.didRenderScripts = true;
7037
7131
  }
@@ -7043,11 +7137,44 @@ function Scripts(props) {
7043
7137
  let streamScript = "window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());";
7044
7138
  let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};${streamScript}` : " ";
7045
7139
  let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
7046
- ${matches.map(
7047
- (match, index) => `import * as route${index} from ${JSON.stringify(
7048
- manifest.routes[match.route.id].module
7049
- )};`
7050
- ).join("\n")}
7140
+ ${matches.map((match, routeIndex) => {
7141
+ let routeVarName = `route${routeIndex}`;
7142
+ let manifestEntry = manifest.routes[match.route.id];
7143
+ invariant2(manifestEntry, `Route ${match.route.id} not found in manifest`);
7144
+ let {
7145
+ clientActionModule,
7146
+ clientLoaderModule,
7147
+ hydrateFallbackModule,
7148
+ module: module2
7149
+ } = manifestEntry;
7150
+ let chunks = [
7151
+ ...clientActionModule ? [
7152
+ {
7153
+ module: clientActionModule,
7154
+ varName: `${routeVarName}_clientAction`
7155
+ }
7156
+ ] : [],
7157
+ ...clientLoaderModule ? [
7158
+ {
7159
+ module: clientLoaderModule,
7160
+ varName: `${routeVarName}_clientLoader`
7161
+ }
7162
+ ] : [],
7163
+ ...hydrateFallbackModule ? [
7164
+ {
7165
+ module: hydrateFallbackModule,
7166
+ varName: `${routeVarName}_HydrateFallback`
7167
+ }
7168
+ ] : [],
7169
+ { module: module2, varName: `${routeVarName}_main` }
7170
+ ];
7171
+ if (chunks.length === 1) {
7172
+ return `import * as ${routeVarName} from ${JSON.stringify(module2)};`;
7173
+ }
7174
+ let chunkImportsSnippet = chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n");
7175
+ let mergedChunksSnippet = `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`;
7176
+ return [chunkImportsSnippet, mergedChunksSnippet].join("\n");
7177
+ }).join("\n")}
7051
7178
  ${enableFogOfWar ? (
7052
7179
  // Inline a minimal manifest with the SSR matches
7053
7180
  `window.__reactRouterManifest = ${JSON.stringify(
@@ -7078,11 +7205,11 @@ import(${JSON.stringify(manifest.entry.module)});`;
7078
7205
  }
7079
7206
  ));
7080
7207
  }, []);
7081
- let routePreloads = matches.map((match) => {
7082
- let route = manifest.routes[match.route.id];
7083
- return route ? (route.imports || []).concat([route.module]) : [];
7084
- }).flat(1);
7085
- let preloads = isHydrated ? [] : manifest.entry.imports.concat(routePreloads);
7208
+ let preloads = isHydrated ? [] : manifest.entry.imports.concat(
7209
+ getModuleLinkHrefs(matches, manifest, {
7210
+ includeHydrateFallback: true
7211
+ })
7212
+ );
7086
7213
  return isHydrated ? null : /* @__PURE__ */ React9.createElement(React9.Fragment, null, !enableFogOfWar ? /* @__PURE__ */ React9.createElement(
7087
7214
  "link",
7088
7215
  {
@@ -7126,7 +7253,7 @@ function mergeRefs(...refs) {
7126
7253
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
7127
7254
  try {
7128
7255
  if (isBrowser) {
7129
- window.__reactRouterVersion = "7.1.5";
7256
+ window.__reactRouterVersion = "7.2.0-pre.0";
7130
7257
  }
7131
7258
  } catch (e) {
7132
7259
  }
@@ -8238,6 +8365,7 @@ function ServerRouter({
8238
8365
  criticalCss,
8239
8366
  serverHandoffString,
8240
8367
  future: context.future,
8368
+ ssr: context.ssr,
8241
8369
  isSpaMode: context.isSpaMode,
8242
8370
  serializeError: context.serializeError,
8243
8371
  renderMeta: context.renderMeta
@@ -8284,6 +8412,7 @@ function createRoutesStub(routes, context = {}) {
8284
8412
  version: ""
8285
8413
  },
8286
8414
  routeModules: {},
8415
+ ssr: false,
8287
8416
  isSpaMode: false
8288
8417
  };
8289
8418
  let patched = processRoutes(
@@ -8335,8 +8464,11 @@ function processRoutes(routes, context, manifest, routeModules, parentId) {
8335
8464
  hasClientAction: false,
8336
8465
  hasClientLoader: false,
8337
8466
  hasErrorBoundary: route.ErrorBoundary != null,
8338
- module: "build/stub-path-to-module.js"
8339
- // any need for this?
8467
+ // any need for these?
8468
+ module: "build/stub-path-to-module.js",
8469
+ clientActionModule: void 0,
8470
+ clientLoaderModule: void 0,
8471
+ hydrateFallbackModule: void 0
8340
8472
  };
8341
8473
  manifest.routes[newRoute.id] = entryRoute;
8342
8474
  routeModules[route.id] = {
@@ -9126,6 +9258,10 @@ var createRequestHandler = (build, mode) => {
9126
9258
  errorHandler = derived.errorHandler;
9127
9259
  }
9128
9260
  let url = new URL(request.url);
9261
+ let normalizedPath = url.pathname.replace(/\.data$/, "").replace(/^\/_root$/, "/");
9262
+ if (normalizedPath !== "/" && normalizedPath.endsWith("/")) {
9263
+ normalizedPath = normalizedPath.slice(0, -1);
9264
+ }
9129
9265
  let params = {};
9130
9266
  let handleError = (error) => {
9131
9267
  if (mode === "development" /* Development */) {
@@ -9137,6 +9273,32 @@ var createRequestHandler = (build, mode) => {
9137
9273
  request
9138
9274
  });
9139
9275
  };
9276
+ if (!_build.ssr) {
9277
+ if (_build.prerender.length === 0) {
9278
+ request.headers.set("X-React-Router-SPA-Mode", "yes");
9279
+ } else if (!_build.prerender.includes(normalizedPath) && !_build.prerender.includes(normalizedPath + "/")) {
9280
+ if (url.pathname.endsWith(".data")) {
9281
+ errorHandler(
9282
+ new ErrorResponseImpl(
9283
+ 404,
9284
+ "Not Found",
9285
+ `Refusing to SSR the path \`${normalizedPath}\` because \`ssr:false\` is set and the path is not included in the \`prerender\` config, so in production the path will be a 404.`
9286
+ ),
9287
+ {
9288
+ context: loadContext,
9289
+ params,
9290
+ request
9291
+ }
9292
+ );
9293
+ return new Response("Not Found", {
9294
+ status: 404,
9295
+ statusText: "Not Found"
9296
+ });
9297
+ } else {
9298
+ request.headers.set("X-React-Router-SPA-Mode", "yes");
9299
+ }
9300
+ }
9301
+ }
9140
9302
  let manifestUrl = `${_build.basename ?? "/"}/__manifest`.replace(
9141
9303
  /\/+/g,
9142
9304
  "/"
@@ -9157,7 +9319,7 @@ var createRequestHandler = (build, mode) => {
9157
9319
  let response;
9158
9320
  if (url.pathname.endsWith(".data")) {
9159
9321
  let handlerUrl = new URL(request.url);
9160
- handlerUrl.pathname = handlerUrl.pathname.replace(/\.data$/, "").replace(/^\/_root$/, "/");
9322
+ handlerUrl.pathname = normalizedPath;
9161
9323
  let singleFetchMatches = matchServerRoutes(
9162
9324
  routes,
9163
9325
  handlerUrl.pathname,
@@ -9297,6 +9459,7 @@ async function handleSingleFetchRequest(serverMode, build, staticHandler, reques
9297
9459
  );
9298
9460
  }
9299
9461
  async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, criticalCss) {
9462
+ let isSpaMode = request.headers.has("X-React-Router-SPA-Mode");
9300
9463
  let context;
9301
9464
  try {
9302
9465
  context = await staticHandler.query(request, {
@@ -9335,7 +9498,8 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
9335
9498
  basename: build.basename,
9336
9499
  criticalCss,
9337
9500
  future: build.future,
9338
- isSpaMode: build.isSpaMode
9501
+ ssr: build.ssr,
9502
+ isSpaMode
9339
9503
  }),
9340
9504
  serverHandoffStream: encodeViaTurboStream(
9341
9505
  state,
@@ -9345,7 +9509,8 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
9345
9509
  ),
9346
9510
  renderMeta: {},
9347
9511
  future: build.future,
9348
- isSpaMode: build.isSpaMode,
9512
+ ssr: build.ssr,
9513
+ isSpaMode,
9349
9514
  serializeError: (err) => serializeError(err, serverMode)
9350
9515
  };
9351
9516
  let handleDocumentRequestFunction = build.entry.module.default;
@@ -9390,7 +9555,8 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
9390
9555
  serverHandoffString: createServerHandoffString({
9391
9556
  basename: build.basename,
9392
9557
  future: build.future,
9393
- isSpaMode: build.isSpaMode
9558
+ ssr: build.ssr,
9559
+ isSpaMode
9394
9560
  }),
9395
9561
  serverHandoffStream: encodeViaTurboStream(
9396
9562
  state2,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.1.5
2
+ * react-router v7.2.0-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -120,7 +120,7 @@ import {
120
120
  useSearchParams,
121
121
  useSubmit,
122
122
  useViewTransitionState
123
- } from "./chunk-IR6S3I6Y.mjs";
123
+ } from "./chunk-HLU4BUUT.mjs";
124
124
  export {
125
125
  Await,
126
126
  BrowserRouter,
@@ -1,4 +1,4 @@
1
- import { ay as LinkDescriptor, av as MetaDescriptor, aM as ServerDataFrom, aN as ClientDataFrom, aO as Func, aP as Equal, aQ as Pretty } from '../../route-data-Cq_b5feC.mjs';
1
+ import { ay as LinkDescriptor, av as MetaDescriptor, aM as ServerDataFrom, aN as ClientDataFrom, aO as Func, aP as Equal, aQ as Pretty } from '../../route-data-DQbTMaUY.mjs';
2
2
  import { A as AppLoadContext } from '../../data-CQbyyGzl.mjs';
3
3
  import 'react';
4
4
 
@@ -86,6 +86,8 @@ type CreateClientActionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & {
86
86
  };
87
87
  type CreateHydrateFallbackProps<T extends RouteInfo> = {
88
88
  params: T["params"];
89
+ loaderData?: T["loaderData"];
90
+ actionData?: T["actionData"];
89
91
  };
90
92
  type Match<T extends RouteInfo> = Pretty<Pick<T, "id" | "params"> & {
91
93
  pathname: string;