react-router 7.1.3 → 7.1.4

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 +23 -1
  2. package/dist/development/{chunk-SYFQ2XB5.mjs → chunk-W3FMU5Y5.mjs} +52 -47
  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 +35 -36
  6. package/dist/development/dom-export.mjs +2 -2
  7. package/dist/{production/fog-of-war-Ckdfl79L.d.ts → development/fog-of-war-CCAcUMgB.d.ts} +1 -1
  8. package/dist/development/{fog-of-war-Ckdfl79L.d.ts → fog-of-war-D6dP9JIt.d.mts} +1 -1
  9. package/dist/development/index.d.mts +5 -41
  10. package/dist/development/index.d.ts +5 -41
  11. package/dist/development/index.js +52 -47
  12. package/dist/development/index.mjs +2 -2
  13. package/dist/development/lib/types/route-module.d.mts +1 -1
  14. package/dist/development/lib/types/route-module.d.ts +1 -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-Cw8htKcF.d.ts → route-data-Cq_b5feC.d.mts} +27 -1
  18. package/dist/{production/route-data-Cw8htKcF.d.mts → development/route-data-Cq_b5feC.d.ts} +27 -1
  19. package/dist/production/{chunk-OKQ6KMOJ.mjs → chunk-FIUQORTV.mjs} +52 -47
  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 +35 -36
  23. package/dist/production/dom-export.mjs +2 -2
  24. package/dist/{development/fog-of-war-ClXvjZ4E.d.mts → production/fog-of-war-CCAcUMgB.d.ts} +1 -1
  25. package/dist/production/{fog-of-war-ClXvjZ4E.d.mts → fog-of-war-D6dP9JIt.d.mts} +1 -1
  26. package/dist/production/index.d.mts +5 -41
  27. package/dist/production/index.d.ts +5 -41
  28. package/dist/production/index.js +52 -47
  29. package/dist/production/index.mjs +2 -2
  30. package/dist/production/lib/types/route-module.d.mts +1 -1
  31. package/dist/production/lib/types/route-module.d.ts +1 -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-Cw8htKcF.d.ts → route-data-Cq_b5feC.d.mts} +27 -1
  35. package/dist/{development/route-data-Cw8htKcF.d.mts → production/route-data-Cq_b5feC.d.ts} +27 -1
  36. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.1.3
2
+ * react-router v7.1.4
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1064,6 +1064,7 @@ function createRouter(init) {
1064
1064
  let getScrollPosition = null;
1065
1065
  let initialScrollRestored = init.hydrationData != null;
1066
1066
  let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
1067
+ let initialMatchesIsFOW = false;
1067
1068
  let initialErrors = null;
1068
1069
  if (initialMatches == null && !patchRoutesOnNavigationImpl) {
1069
1070
  let error = getInternalRouterError(404, {
@@ -1093,6 +1094,7 @@ function createRouter(init) {
1093
1094
  init.history.location.pathname
1094
1095
  );
1095
1096
  if (fogOfWar.active && fogOfWar.matches) {
1097
+ initialMatchesIsFOW = true;
1096
1098
  initialMatches = fogOfWar.matches;
1097
1099
  }
1098
1100
  } else if (initialMatches.some((m) => m.route.lazy)) {
@@ -1458,7 +1460,10 @@ function createRouter(init) {
1458
1460
  pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
1459
1461
  let routesToUse = inFlightDataRoutes || dataRoutes;
1460
1462
  let loadingNavigation = opts && opts.overrideNavigation;
1461
- let matches = matchRoutes(routesToUse, location, basename);
1463
+ let matches = opts?.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ? (
1464
+ // `matchRoutes()` has already been called if we're in here via `router.initialize()`
1465
+ state.matches
1466
+ ) : matchRoutes(routesToUse, location, basename);
1462
1467
  let flushSync = (opts && opts.flushSync) === true;
1463
1468
  let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
1464
1469
  if (fogOfWar.active && fogOfWar.matches) {
@@ -3642,14 +3647,20 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
3642
3647
  return {
3643
3648
  type: "error" /* error */,
3644
3649
  error: result.data,
3645
- statusCode: result.init?.status
3650
+ statusCode: result.init?.status,
3651
+ headers: result.init?.headers ? new Headers(result.init.headers) : void 0
3646
3652
  };
3647
3653
  }
3648
- result = new ErrorResponseImpl(
3649
- result.init?.status || 500,
3650
- void 0,
3651
- result.data
3652
- );
3654
+ return {
3655
+ type: "error" /* error */,
3656
+ error: new ErrorResponseImpl(
3657
+ result.init?.status || 500,
3658
+ void 0,
3659
+ result.data
3660
+ ),
3661
+ statusCode: isRouteErrorResponse(result) ? result.status : void 0,
3662
+ headers: result.init?.headers ? new Headers(result.init.headers) : void 0
3663
+ };
3653
3664
  }
3654
3665
  return {
3655
3666
  type: "error" /* error */,
@@ -4350,7 +4361,7 @@ function useRoutesImpl(routes, locationArg, dataRouterState, future) {
4350
4361
  // router loaded. We can help them understand how to avoid that.
4351
4362
  `useRoutes() may be used only in the context of a <Router> component.`
4352
4363
  );
4353
- let { navigator: navigator2 } = React2.useContext(NavigationContext);
4364
+ let { navigator: navigator2, static: isStatic } = React2.useContext(NavigationContext);
4354
4365
  let { matches: parentMatches } = React2.useContext(RouteContext);
4355
4366
  let routeMatch = parentMatches[parentMatches.length - 1];
4356
4367
  let parentParams = routeMatch ? routeMatch.params : {};
@@ -4386,7 +4397,7 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
4386
4397
  let segments = pathname.replace(/^\//, "").split("/");
4387
4398
  remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
4388
4399
  }
4389
- let matches = matchRoutes(routes, { pathname: remainingPathname });
4400
+ let matches = !isStatic && dataRouterState && dataRouterState.matches && dataRouterState.matches.length > 0 ? dataRouterState.matches : matchRoutes(routes, { pathname: remainingPathname });
4390
4401
  if (ENABLE_DEV_WARNINGS) {
4391
4402
  warning(
4392
4403
  parentRoute || matches != null,
@@ -5966,6 +5977,14 @@ async function fetchAndDecode(url, init) {
5966
5977
  if (res.status === 404 && !res.headers.has("X-Remix-Response")) {
5967
5978
  throw new ErrorResponseImpl(404, "Not Found", true);
5968
5979
  }
5980
+ const NO_BODY_STATUS_CODES2 = /* @__PURE__ */ new Set([100, 101, 204, 205]);
5981
+ if (NO_BODY_STATUS_CODES2.has(res.status)) {
5982
+ if (!init.method || init.method === "GET") {
5983
+ return { status: res.status, data: {} };
5984
+ } else {
5985
+ return { status: res.status, data: { data: void 0 } };
5986
+ }
5987
+ }
5969
5988
  invariant2(res.body, "No response body to decode");
5970
5989
  try {
5971
5990
  let decoded = await decodeViaTurboStream(res.body, window);
@@ -6581,12 +6600,13 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
6581
6600
  if (!path) {
6582
6601
  return;
6583
6602
  }
6584
- let url = new URL(path, window.location.origin);
6585
- if (!discoveredPaths.has(url.pathname)) {
6586
- nextPaths.add(url.pathname);
6603
+ let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
6604
+ if (!discoveredPaths.has(pathname)) {
6605
+ nextPaths.add(pathname);
6587
6606
  }
6588
6607
  }
6589
6608
  async function fetchPatches() {
6609
+ document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
6590
6610
  let lazyPaths = Array.from(nextPaths.keys()).filter((path) => {
6591
6611
  if (discoveredPaths.has(path)) {
6592
6612
  nextPaths.delete(path);
@@ -6610,30 +6630,9 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
6610
6630
  console.error("Failed to fetch manifest patches", e);
6611
6631
  }
6612
6632
  }
6613
- document.body.querySelectorAll("a[data-discover], form[data-discover]").forEach((el) => registerElement(el));
6614
- fetchPatches();
6615
6633
  let debouncedFetchPatches = debounce(fetchPatches, 100);
6616
- function isElement(node) {
6617
- return node.nodeType === Node.ELEMENT_NODE;
6618
- }
6619
- let observer = new MutationObserver((records) => {
6620
- let elements = /* @__PURE__ */ new Set();
6621
- records.forEach((r) => {
6622
- [r.target, ...r.addedNodes].forEach((node) => {
6623
- if (!isElement(node)) return;
6624
- if (node.tagName === "A" && node.getAttribute("data-discover")) {
6625
- elements.add(node);
6626
- } else if (node.tagName === "FORM" && node.getAttribute("data-discover")) {
6627
- elements.add(node);
6628
- }
6629
- if (node.tagName !== "A") {
6630
- node.querySelectorAll("a[data-discover], form[data-discover]").forEach((el) => elements.add(el));
6631
- }
6632
- });
6633
- });
6634
- elements.forEach((el) => registerElement(el));
6635
- debouncedFetchPatches();
6636
- });
6634
+ fetchPatches();
6635
+ let observer = new MutationObserver(() => debouncedFetchPatches());
6637
6636
  observer.observe(document.documentElement, {
6638
6637
  subtree: true,
6639
6638
  childList: true,
@@ -7127,7 +7126,7 @@ function mergeRefs(...refs) {
7127
7126
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
7128
7127
  try {
7129
7128
  if (isBrowser) {
7130
- window.__reactRouterVersion = "7.1.3";
7129
+ window.__reactRouterVersion = "7.1.4";
7131
7130
  }
7132
7131
  } catch (e) {
7133
7132
  }
@@ -8847,8 +8846,11 @@ function prependCookies(parentHeaders, childHeaders) {
8847
8846
  let parentSetCookieString = parentHeaders.get("Set-Cookie");
8848
8847
  if (parentSetCookieString) {
8849
8848
  let cookies = (0, import_set_cookie_parser.splitCookiesString)(parentSetCookieString);
8849
+ let childCookies = new Set(childHeaders.getSetCookie());
8850
8850
  cookies.forEach((cookie) => {
8851
- childHeaders.append("Set-Cookie", cookie);
8851
+ if (!childCookies.has(cookie)) {
8852
+ childHeaders.append("Set-Cookie", cookie);
8853
+ }
8852
8854
  });
8853
8855
  }
8854
8856
  }
@@ -9078,6 +9080,7 @@ function encodeViaTurboStream(data2, requestSignal, streamTimeout, serverMode) {
9078
9080
  }
9079
9081
 
9080
9082
  // lib/server-runtime/server.ts
9083
+ var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205, 304]);
9081
9084
  function derive(build, mode) {
9082
9085
  let routes = createRoutes(build.routes);
9083
9086
  let dataRoutes = createStaticHandlerDataRoutes(build.routes, build.future);
@@ -9276,8 +9279,8 @@ async function handleSingleFetchRequest(serverMode, build, staticHandler, reques
9276
9279
  );
9277
9280
  let resultHeaders = new Headers(headers);
9278
9281
  resultHeaders.set("X-Remix-Response", "yes");
9279
- if (status === 304) {
9280
- return new Response(null, { status: 304, headers: resultHeaders });
9282
+ if (NO_BODY_STATUS_CODES.has(status)) {
9283
+ return new Response(null, { status, headers: resultHeaders });
9281
9284
  }
9282
9285
  resultHeaders.set("Content-Type", "text/x-script");
9283
9286
  return new Response(
@@ -9307,8 +9310,8 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
9307
9310
  return context;
9308
9311
  }
9309
9312
  let headers = getDocumentHeaders(build, context);
9310
- if (context.statusCode === 304) {
9311
- return new Response(null, { status: 304, headers });
9313
+ if (NO_BODY_STATUS_CODES.has(context.statusCode)) {
9314
+ return new Response(null, { status: context.statusCode, headers });
9312
9315
  }
9313
9316
  if (context.errors) {
9314
9317
  Object.values(context.errors).forEach((err) => {
@@ -9417,11 +9420,13 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
9417
9420
  routeId,
9418
9421
  requestContext: loadContext
9419
9422
  });
9420
- invariant3(
9421
- isResponse(response),
9422
- "Expected a Response to be returned from resource route handler"
9423
- );
9424
- return response;
9423
+ if (isResponse(response)) {
9424
+ return response;
9425
+ }
9426
+ if (typeof response === "string") {
9427
+ return new Response(response);
9428
+ }
9429
+ return Response.json(response);
9425
9430
  } catch (error) {
9426
9431
  if (isResponse(error)) {
9427
9432
  error.headers.set("X-Remix-Catch", "yes");
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.1.3
2
+ * react-router v7.1.4
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-SYFQ2XB5.mjs";
123
+ } from "./chunk-W3FMU5Y5.mjs";
124
124
  export {
125
125
  Await,
126
126
  BrowserRouter,
@@ -1,4 +1,4 @@
1
- import { av as LinkDescriptor, as as MetaDescriptor, aJ as ServerDataFrom, aK as ClientDataFrom, aL as Func, aM as Equal, aN as Pretty } from '../../route-data-Cw8htKcF.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-Cq_b5feC.mjs';
2
2
  import { A as AppLoadContext } from '../../data-CQbyyGzl.mjs';
3
3
  import 'react';
4
4
 
@@ -1,4 +1,4 @@
1
- import { av as LinkDescriptor, as as MetaDescriptor, aJ as ServerDataFrom, aK as ClientDataFrom, aL as Func, aM as Equal, aN as Pretty } from '../../route-data-Cw8htKcF.js';
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.js';
2
2
  import { A as AppLoadContext } from '../../data-CQbyyGzl.js';
3
3
  import 'react';
4
4
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.1.3
2
+ * react-router v7.1.4
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.1.3
2
+ * react-router v7.1.4
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1355,6 +1355,9 @@ type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1355
1355
  interface RouteModules {
1356
1356
  [routeId: string]: RouteModule | undefined;
1357
1357
  }
1358
+ /**
1359
+ * The shape of a route module shipped to the client
1360
+ */
1358
1361
  interface RouteModule {
1359
1362
  clientAction?: ClientActionFunction;
1360
1363
  clientLoader?: ClientLoaderFunction;
@@ -1367,6 +1370,16 @@ interface RouteModule {
1367
1370
  meta?: MetaFunction;
1368
1371
  shouldRevalidate?: ShouldRevalidateFunction;
1369
1372
  }
1373
+ /**
1374
+ * The shape of a route module on the server
1375
+ */
1376
+ interface ServerRouteModule extends RouteModule {
1377
+ action?: ActionFunction;
1378
+ headers?: HeadersFunction | {
1379
+ [name: string]: string;
1380
+ };
1381
+ loader?: LoaderFunction;
1382
+ }
1370
1383
  /**
1371
1384
  * A function that handles data mutations for a route on the client
1372
1385
  */
@@ -1393,6 +1406,19 @@ type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
1393
1406
  * ErrorBoundary to display for this route
1394
1407
  */
1395
1408
  type ErrorBoundaryComponent = ComponentType;
1409
+ type HeadersArgs = {
1410
+ loaderHeaders: Headers;
1411
+ parentHeaders: Headers;
1412
+ actionHeaders: Headers;
1413
+ errorHeaders: Headers | undefined;
1414
+ };
1415
+ /**
1416
+ * A function that returns HTTP headers to be used for a route. These headers
1417
+ * will be merged with (and take precedence over) headers from parent routes.
1418
+ */
1419
+ interface HeadersFunction {
1420
+ (args: HeadersArgs): Headers | HeadersInit;
1421
+ }
1396
1422
  /**
1397
1423
  * `<Route HydrateFallback>` component to render on initial loads
1398
1424
  * when client loaders are present
@@ -1549,4 +1575,4 @@ type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1549
1575
  type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1550
1576
  type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1551
1577
 
1552
- export { type HTMLFormMethod as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyFunction as D, type RouterInit as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type RouterSubscriber as J, type RouterNavigateOptions as K, type LoaderFunction as L, type MetaFunction as M, type NavigateOptions as N, type RouterFetchOptions as O, type ParamParseKey as P, type DataStrategyFunctionArgs as Q, type RouteModules as R, type SerializeFrom as S, type To as T, type UIMatch as U, type DataStrategyMatch as V, type DataStrategyResult as W, DataWithResponseInit as X, type ErrorResponse as Y, type FormEncType as Z, type FormMethod as _, type Router as a, type LazyRouteFunction as a0, type PathParam as a1, type RedirectFunction as a2, type ShouldRevalidateFunction as a3, type ShouldRevalidateFunctionArgs as a4, createPath as a5, parsePath as a6, IDLE_NAVIGATION as a7, IDLE_FETCHER as a8, IDLE_BLOCKER as a9, DataRouterContext as aA, DataRouterStateContext as aB, FetchersContext as aC, LocationContext as aD, NavigationContext as aE, RouteContext as aF, ViewTransitionContext as aG, type RouteModule as aH, type History as aI, type ServerDataFrom as aJ, type ClientDataFrom as aK, type Func as aL, type Equal as aM, type Pretty as aN, data as aa, generatePath as ab, isRouteErrorResponse as ac, matchPath as ad, matchRoutes as ae, redirect as af, redirectDocument as ag, replace as ah, resolvePath as ai, type DataRouteMatch as aj, type DataRouteObject as ak, type Navigator as al, type PatchRoutesOnNavigationFunction as am, type PatchRoutesOnNavigationFunctionArgs as an, type RouteMatch as ao, type ClientActionFunctionArgs as ap, type ClientLoaderFunctionArgs as aq, type MetaArgs as ar, type MetaDescriptor as as, type PageLinkDescriptor as at, type HtmlLinkDescriptor as au, type LinkDescriptor as av, createBrowserHistory as aw, invariant as ax, createRouter as ay, ErrorResponseImpl as az, type ClientLoaderFunction as b, type LinksFunction as c, type RouteManifest as d, type LoaderFunctionArgs as e, type ActionFunctionArgs as f, type RelativeRoutingType as g, type Location as h, Action as i, type Path as j, type PathPattern as k, type PathMatch as l, type Params as m, type RouteObject as n, type Navigation as o, type RevalidationState as p, type Blocker as q, type StaticHandlerContext as r, type StaticHandler as s, type CreateStaticHandlerOptions as t, type IndexRouteObject as u, type NonIndexRouteObject as v, type RouterState as w, type GetScrollRestorationKeyFunction as x, type Fetcher as y, type NavigationStates as z };
1578
+ export { type LazyRouteFunction as $, type ActionFunctionArgs as A, type BlockerFunction as B, type CreateStaticHandlerOptions as C, type DataStrategyFunction as D, type RouterSubscriber as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type RouterNavigateOptions as J, type RouterFetchOptions as K, type LoaderFunctionArgs as L, type MetaFunction as M, type NavigateOptions as N, type DataStrategyFunctionArgs as O, type ParamParseKey as P, type DataStrategyMatch as Q, type RouteModules as R, type ServerRouteModule as S, type To as T, type UIMatch as U, type DataStrategyResult as V, DataWithResponseInit as W, type ErrorResponse as X, type FormEncType as Y, type FormMethod as Z, type HTMLFormMethod as _, type Router as a, type PathParam as a0, type RedirectFunction as a1, type ShouldRevalidateFunction as a2, type ShouldRevalidateFunctionArgs as a3, createPath as a4, parsePath as a5, IDLE_NAVIGATION as a6, IDLE_FETCHER as a7, IDLE_BLOCKER as a8, data as a9, invariant as aA, createRouter as aB, ErrorResponseImpl as aC, DataRouterContext as aD, DataRouterStateContext as aE, FetchersContext as aF, LocationContext as aG, NavigationContext as aH, RouteContext as aI, ViewTransitionContext as aJ, type RouteModule as aK, type History as aL, type ServerDataFrom as aM, type ClientDataFrom as aN, type Func as aO, type Equal as aP, type Pretty as aQ, generatePath as aa, isRouteErrorResponse as ab, matchPath as ac, matchRoutes as ad, redirect as ae, redirectDocument as af, replace as ag, resolvePath as ah, type DataRouteMatch as ai, type DataRouteObject as aj, type Navigator as ak, type PatchRoutesOnNavigationFunction as al, type PatchRoutesOnNavigationFunctionArgs as am, type RouteMatch as an, type ClientActionFunction as ao, type ClientActionFunctionArgs as ap, type ClientLoaderFunction as aq, type ClientLoaderFunctionArgs as ar, type HeadersArgs as as, type HeadersFunction as at, type MetaArgs as au, type MetaDescriptor as av, type PageLinkDescriptor as aw, type HtmlLinkDescriptor as ax, type LinkDescriptor as ay, createBrowserHistory as az, type RouteManifest as b, type RelativeRoutingType as c, type Location as d, Action as e, type Path as f, type PathPattern as g, type PathMatch as h, type Params as i, type RouteObject as j, type Navigation as k, type RevalidationState as l, type SerializeFrom as m, type Blocker as n, type StaticHandlerContext as o, type StaticHandler as p, type IndexRouteObject as q, type LoaderFunction as r, type ActionFunction as s, type LinksFunction as t, type NonIndexRouteObject as u, type RouterState as v, type GetScrollRestorationKeyFunction as w, type Fetcher as x, type NavigationStates as y, type RouterInit as z };
@@ -1355,6 +1355,9 @@ type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1355
1355
  interface RouteModules {
1356
1356
  [routeId: string]: RouteModule | undefined;
1357
1357
  }
1358
+ /**
1359
+ * The shape of a route module shipped to the client
1360
+ */
1358
1361
  interface RouteModule {
1359
1362
  clientAction?: ClientActionFunction;
1360
1363
  clientLoader?: ClientLoaderFunction;
@@ -1367,6 +1370,16 @@ interface RouteModule {
1367
1370
  meta?: MetaFunction;
1368
1371
  shouldRevalidate?: ShouldRevalidateFunction;
1369
1372
  }
1373
+ /**
1374
+ * The shape of a route module on the server
1375
+ */
1376
+ interface ServerRouteModule extends RouteModule {
1377
+ action?: ActionFunction;
1378
+ headers?: HeadersFunction | {
1379
+ [name: string]: string;
1380
+ };
1381
+ loader?: LoaderFunction;
1382
+ }
1370
1383
  /**
1371
1384
  * A function that handles data mutations for a route on the client
1372
1385
  */
@@ -1393,6 +1406,19 @@ type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
1393
1406
  * ErrorBoundary to display for this route
1394
1407
  */
1395
1408
  type ErrorBoundaryComponent = ComponentType;
1409
+ type HeadersArgs = {
1410
+ loaderHeaders: Headers;
1411
+ parentHeaders: Headers;
1412
+ actionHeaders: Headers;
1413
+ errorHeaders: Headers | undefined;
1414
+ };
1415
+ /**
1416
+ * A function that returns HTTP headers to be used for a route. These headers
1417
+ * will be merged with (and take precedence over) headers from parent routes.
1418
+ */
1419
+ interface HeadersFunction {
1420
+ (args: HeadersArgs): Headers | HeadersInit;
1421
+ }
1396
1422
  /**
1397
1423
  * `<Route HydrateFallback>` component to render on initial loads
1398
1424
  * when client loaders are present
@@ -1549,4 +1575,4 @@ type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1549
1575
  type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1550
1576
  type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1551
1577
 
1552
- export { type HTMLFormMethod as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyFunction as D, type RouterInit as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type RouterSubscriber as J, type RouterNavigateOptions as K, type LoaderFunction as L, type MetaFunction as M, type NavigateOptions as N, type RouterFetchOptions as O, type ParamParseKey as P, type DataStrategyFunctionArgs as Q, type RouteModules as R, type SerializeFrom as S, type To as T, type UIMatch as U, type DataStrategyMatch as V, type DataStrategyResult as W, DataWithResponseInit as X, type ErrorResponse as Y, type FormEncType as Z, type FormMethod as _, type Router as a, type LazyRouteFunction as a0, type PathParam as a1, type RedirectFunction as a2, type ShouldRevalidateFunction as a3, type ShouldRevalidateFunctionArgs as a4, createPath as a5, parsePath as a6, IDLE_NAVIGATION as a7, IDLE_FETCHER as a8, IDLE_BLOCKER as a9, DataRouterContext as aA, DataRouterStateContext as aB, FetchersContext as aC, LocationContext as aD, NavigationContext as aE, RouteContext as aF, ViewTransitionContext as aG, type RouteModule as aH, type History as aI, type ServerDataFrom as aJ, type ClientDataFrom as aK, type Func as aL, type Equal as aM, type Pretty as aN, data as aa, generatePath as ab, isRouteErrorResponse as ac, matchPath as ad, matchRoutes as ae, redirect as af, redirectDocument as ag, replace as ah, resolvePath as ai, type DataRouteMatch as aj, type DataRouteObject as ak, type Navigator as al, type PatchRoutesOnNavigationFunction as am, type PatchRoutesOnNavigationFunctionArgs as an, type RouteMatch as ao, type ClientActionFunctionArgs as ap, type ClientLoaderFunctionArgs as aq, type MetaArgs as ar, type MetaDescriptor as as, type PageLinkDescriptor as at, type HtmlLinkDescriptor as au, type LinkDescriptor as av, createBrowserHistory as aw, invariant as ax, createRouter as ay, ErrorResponseImpl as az, type ClientLoaderFunction as b, type LinksFunction as c, type RouteManifest as d, type LoaderFunctionArgs as e, type ActionFunctionArgs as f, type RelativeRoutingType as g, type Location as h, Action as i, type Path as j, type PathPattern as k, type PathMatch as l, type Params as m, type RouteObject as n, type Navigation as o, type RevalidationState as p, type Blocker as q, type StaticHandlerContext as r, type StaticHandler as s, type CreateStaticHandlerOptions as t, type IndexRouteObject as u, type NonIndexRouteObject as v, type RouterState as w, type GetScrollRestorationKeyFunction as x, type Fetcher as y, type NavigationStates as z };
1578
+ export { type LazyRouteFunction as $, type ActionFunctionArgs as A, type BlockerFunction as B, type CreateStaticHandlerOptions as C, type DataStrategyFunction as D, type RouterSubscriber as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type RouterNavigateOptions as J, type RouterFetchOptions as K, type LoaderFunctionArgs as L, type MetaFunction as M, type NavigateOptions as N, type DataStrategyFunctionArgs as O, type ParamParseKey as P, type DataStrategyMatch as Q, type RouteModules as R, type ServerRouteModule as S, type To as T, type UIMatch as U, type DataStrategyResult as V, DataWithResponseInit as W, type ErrorResponse as X, type FormEncType as Y, type FormMethod as Z, type HTMLFormMethod as _, type Router as a, type PathParam as a0, type RedirectFunction as a1, type ShouldRevalidateFunction as a2, type ShouldRevalidateFunctionArgs as a3, createPath as a4, parsePath as a5, IDLE_NAVIGATION as a6, IDLE_FETCHER as a7, IDLE_BLOCKER as a8, data as a9, invariant as aA, createRouter as aB, ErrorResponseImpl as aC, DataRouterContext as aD, DataRouterStateContext as aE, FetchersContext as aF, LocationContext as aG, NavigationContext as aH, RouteContext as aI, ViewTransitionContext as aJ, type RouteModule as aK, type History as aL, type ServerDataFrom as aM, type ClientDataFrom as aN, type Func as aO, type Equal as aP, type Pretty as aQ, generatePath as aa, isRouteErrorResponse as ab, matchPath as ac, matchRoutes as ad, redirect as ae, redirectDocument as af, replace as ag, resolvePath as ah, type DataRouteMatch as ai, type DataRouteObject as aj, type Navigator as ak, type PatchRoutesOnNavigationFunction as al, type PatchRoutesOnNavigationFunctionArgs as am, type RouteMatch as an, type ClientActionFunction as ao, type ClientActionFunctionArgs as ap, type ClientLoaderFunction as aq, type ClientLoaderFunctionArgs as ar, type HeadersArgs as as, type HeadersFunction as at, type MetaArgs as au, type MetaDescriptor as av, type PageLinkDescriptor as aw, type HtmlLinkDescriptor as ax, type LinkDescriptor as ay, createBrowserHistory as az, type RouteManifest as b, type RelativeRoutingType as c, type Location as d, Action as e, type Path as f, type PathPattern as g, type PathMatch as h, type Params as i, type RouteObject as j, type Navigation as k, type RevalidationState as l, type SerializeFrom as m, type Blocker as n, type StaticHandlerContext as o, type StaticHandler as p, type IndexRouteObject as q, type LoaderFunction as r, type ActionFunction as s, type LinksFunction as t, type NonIndexRouteObject as u, type RouterState as v, type GetScrollRestorationKeyFunction as w, type Fetcher as x, type NavigationStates as y, type RouterInit as z };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.1.3
2
+ * react-router v7.1.4
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -919,6 +919,7 @@ function createRouter(init) {
919
919
  let getScrollPosition = null;
920
920
  let initialScrollRestored = init.hydrationData != null;
921
921
  let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
922
+ let initialMatchesIsFOW = false;
922
923
  let initialErrors = null;
923
924
  if (initialMatches == null && !patchRoutesOnNavigationImpl) {
924
925
  let error = getInternalRouterError(404, {
@@ -948,6 +949,7 @@ function createRouter(init) {
948
949
  init.history.location.pathname
949
950
  );
950
951
  if (fogOfWar.active && fogOfWar.matches) {
952
+ initialMatchesIsFOW = true;
951
953
  initialMatches = fogOfWar.matches;
952
954
  }
953
955
  } else if (initialMatches.some((m) => m.route.lazy)) {
@@ -1313,7 +1315,10 @@ function createRouter(init) {
1313
1315
  pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
1314
1316
  let routesToUse = inFlightDataRoutes || dataRoutes;
1315
1317
  let loadingNavigation = opts && opts.overrideNavigation;
1316
- let matches = matchRoutes(routesToUse, location, basename);
1318
+ let matches = opts?.initialHydration && state.matches && state.matches.length > 0 && !initialMatchesIsFOW ? (
1319
+ // `matchRoutes()` has already been called if we're in here via `router.initialize()`
1320
+ state.matches
1321
+ ) : matchRoutes(routesToUse, location, basename);
1317
1322
  let flushSync = (opts && opts.flushSync) === true;
1318
1323
  let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
1319
1324
  if (fogOfWar.active && fogOfWar.matches) {
@@ -3497,14 +3502,20 @@ async function convertDataStrategyResultToDataResult(dataStrategyResult) {
3497
3502
  return {
3498
3503
  type: "error" /* error */,
3499
3504
  error: result.data,
3500
- statusCode: result.init?.status
3505
+ statusCode: result.init?.status,
3506
+ headers: result.init?.headers ? new Headers(result.init.headers) : void 0
3501
3507
  };
3502
3508
  }
3503
- result = new ErrorResponseImpl(
3504
- result.init?.status || 500,
3505
- void 0,
3506
- result.data
3507
- );
3509
+ return {
3510
+ type: "error" /* error */,
3511
+ error: new ErrorResponseImpl(
3512
+ result.init?.status || 500,
3513
+ void 0,
3514
+ result.data
3515
+ ),
3516
+ statusCode: isRouteErrorResponse(result) ? result.status : void 0,
3517
+ headers: result.init?.headers ? new Headers(result.init.headers) : void 0
3518
+ };
3508
3519
  }
3509
3520
  return {
3510
3521
  type: "error" /* error */,
@@ -4205,7 +4216,7 @@ function useRoutesImpl(routes, locationArg, dataRouterState, future) {
4205
4216
  // router loaded. We can help them understand how to avoid that.
4206
4217
  `useRoutes() may be used only in the context of a <Router> component.`
4207
4218
  );
4208
- let { navigator: navigator2 } = React2.useContext(NavigationContext);
4219
+ let { navigator: navigator2, static: isStatic } = React2.useContext(NavigationContext);
4209
4220
  let { matches: parentMatches } = React2.useContext(RouteContext);
4210
4221
  let routeMatch = parentMatches[parentMatches.length - 1];
4211
4222
  let parentParams = routeMatch ? routeMatch.params : {};
@@ -4241,7 +4252,7 @@ Please change the parent <Route path="${parentPath}"> to <Route path="${parentPa
4241
4252
  let segments = pathname.replace(/^\//, "").split("/");
4242
4253
  remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
4243
4254
  }
4244
- let matches = matchRoutes(routes, { pathname: remainingPathname });
4255
+ let matches = !isStatic && dataRouterState && dataRouterState.matches && dataRouterState.matches.length > 0 ? dataRouterState.matches : matchRoutes(routes, { pathname: remainingPathname });
4245
4256
  if (ENABLE_DEV_WARNINGS) {
4246
4257
  warning(
4247
4258
  parentRoute || matches != null,
@@ -5821,6 +5832,14 @@ async function fetchAndDecode(url, init) {
5821
5832
  if (res.status === 404 && !res.headers.has("X-Remix-Response")) {
5822
5833
  throw new ErrorResponseImpl(404, "Not Found", true);
5823
5834
  }
5835
+ const NO_BODY_STATUS_CODES2 = /* @__PURE__ */ new Set([100, 101, 204, 205]);
5836
+ if (NO_BODY_STATUS_CODES2.has(res.status)) {
5837
+ if (!init.method || init.method === "GET") {
5838
+ return { status: res.status, data: {} };
5839
+ } else {
5840
+ return { status: res.status, data: { data: void 0 } };
5841
+ }
5842
+ }
5824
5843
  invariant2(res.body, "No response body to decode");
5825
5844
  try {
5826
5845
  let decoded = await decodeViaTurboStream(res.body, window);
@@ -6436,12 +6455,13 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
6436
6455
  if (!path) {
6437
6456
  return;
6438
6457
  }
6439
- let url = new URL(path, window.location.origin);
6440
- if (!discoveredPaths.has(url.pathname)) {
6441
- nextPaths.add(url.pathname);
6458
+ let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
6459
+ if (!discoveredPaths.has(pathname)) {
6460
+ nextPaths.add(pathname);
6442
6461
  }
6443
6462
  }
6444
6463
  async function fetchPatches() {
6464
+ document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
6445
6465
  let lazyPaths = Array.from(nextPaths.keys()).filter((path) => {
6446
6466
  if (discoveredPaths.has(path)) {
6447
6467
  nextPaths.delete(path);
@@ -6465,30 +6485,9 @@ function useFogOFWarDiscovery(router, manifest, routeModules, isSpaMode) {
6465
6485
  console.error("Failed to fetch manifest patches", e);
6466
6486
  }
6467
6487
  }
6468
- document.body.querySelectorAll("a[data-discover], form[data-discover]").forEach((el) => registerElement(el));
6469
- fetchPatches();
6470
6488
  let debouncedFetchPatches = debounce(fetchPatches, 100);
6471
- function isElement(node) {
6472
- return node.nodeType === Node.ELEMENT_NODE;
6473
- }
6474
- let observer = new MutationObserver((records) => {
6475
- let elements = /* @__PURE__ */ new Set();
6476
- records.forEach((r) => {
6477
- [r.target, ...r.addedNodes].forEach((node) => {
6478
- if (!isElement(node)) return;
6479
- if (node.tagName === "A" && node.getAttribute("data-discover")) {
6480
- elements.add(node);
6481
- } else if (node.tagName === "FORM" && node.getAttribute("data-discover")) {
6482
- elements.add(node);
6483
- }
6484
- if (node.tagName !== "A") {
6485
- node.querySelectorAll("a[data-discover], form[data-discover]").forEach((el) => elements.add(el));
6486
- }
6487
- });
6488
- });
6489
- elements.forEach((el) => registerElement(el));
6490
- debouncedFetchPatches();
6491
- });
6489
+ fetchPatches();
6490
+ let observer = new MutationObserver(() => debouncedFetchPatches());
6492
6491
  observer.observe(document.documentElement, {
6493
6492
  subtree: true,
6494
6493
  childList: true,
@@ -6982,7 +6981,7 @@ function mergeRefs(...refs) {
6982
6981
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
6983
6982
  try {
6984
6983
  if (isBrowser) {
6985
- window.__reactRouterVersion = "7.1.3";
6984
+ window.__reactRouterVersion = "7.1.4";
6986
6985
  }
6987
6986
  } catch (e) {
6988
6987
  }
@@ -8702,8 +8701,11 @@ function prependCookies(parentHeaders, childHeaders) {
8702
8701
  let parentSetCookieString = parentHeaders.get("Set-Cookie");
8703
8702
  if (parentSetCookieString) {
8704
8703
  let cookies = splitCookiesString(parentSetCookieString);
8704
+ let childCookies = new Set(childHeaders.getSetCookie());
8705
8705
  cookies.forEach((cookie) => {
8706
- childHeaders.append("Set-Cookie", cookie);
8706
+ if (!childCookies.has(cookie)) {
8707
+ childHeaders.append("Set-Cookie", cookie);
8708
+ }
8707
8709
  });
8708
8710
  }
8709
8711
  }
@@ -8933,6 +8935,7 @@ function encodeViaTurboStream(data2, requestSignal, streamTimeout, serverMode) {
8933
8935
  }
8934
8936
 
8935
8937
  // lib/server-runtime/server.ts
8938
+ var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205, 304]);
8936
8939
  function derive(build, mode) {
8937
8940
  let routes = createRoutes(build.routes);
8938
8941
  let dataRoutes = createStaticHandlerDataRoutes(build.routes, build.future);
@@ -9131,8 +9134,8 @@ async function handleSingleFetchRequest(serverMode, build, staticHandler, reques
9131
9134
  );
9132
9135
  let resultHeaders = new Headers(headers);
9133
9136
  resultHeaders.set("X-Remix-Response", "yes");
9134
- if (status === 304) {
9135
- return new Response(null, { status: 304, headers: resultHeaders });
9137
+ if (NO_BODY_STATUS_CODES.has(status)) {
9138
+ return new Response(null, { status, headers: resultHeaders });
9136
9139
  }
9137
9140
  resultHeaders.set("Content-Type", "text/x-script");
9138
9141
  return new Response(
@@ -9162,8 +9165,8 @@ async function handleDocumentRequest(serverMode, build, staticHandler, request,
9162
9165
  return context;
9163
9166
  }
9164
9167
  let headers = getDocumentHeaders(build, context);
9165
- if (context.statusCode === 304) {
9166
- return new Response(null, { status: 304, headers });
9168
+ if (NO_BODY_STATUS_CODES.has(context.statusCode)) {
9169
+ return new Response(null, { status: context.statusCode, headers });
9167
9170
  }
9168
9171
  if (context.errors) {
9169
9172
  Object.values(context.errors).forEach((err) => {
@@ -9272,11 +9275,13 @@ async function handleResourceRequest(serverMode, staticHandler, routeId, request
9272
9275
  routeId,
9273
9276
  requestContext: loadContext
9274
9277
  });
9275
- invariant3(
9276
- isResponse(response),
9277
- "Expected a Response to be returned from resource route handler"
9278
- );
9279
- return response;
9278
+ if (isResponse(response)) {
9279
+ return response;
9280
+ }
9281
+ if (typeof response === "string") {
9282
+ return new Response(response);
9283
+ }
9284
+ return Response.json(response);
9280
9285
  } catch (error) {
9281
9286
  if (isResponse(error)) {
9282
9287
  error.headers.set("X-Remix-Catch", "yes");
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { R as RouterProviderProps$1 } from './fog-of-war-ClXvjZ4E.mjs';
3
- import './route-data-Cw8htKcF.mjs';
2
+ import { R as RouterProviderProps$1 } from './fog-of-war-D6dP9JIt.mjs';
3
+ import './route-data-Cq_b5feC.mjs';
4
4
 
5
5
  type RouterProviderProps = Omit<RouterProviderProps$1, "flushSync">;
6
6
  declare function RouterProvider(props: Omit<RouterProviderProps, "flushSync">): React.JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { R as RouterProviderProps$1 } from './fog-of-war-Ckdfl79L.js';
3
- import './route-data-Cw8htKcF.js';
2
+ import { R as RouterProviderProps$1 } from './fog-of-war-CCAcUMgB.js';
3
+ import './route-data-Cq_b5feC.js';
4
4
 
5
5
  type RouterProviderProps = Omit<RouterProviderProps$1, "flushSync">;
6
6
  declare function RouterProvider(props: Omit<RouterProviderProps, "flushSync">): React.JSX.Element;