react-router 8.5.1 → 8.5.3

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 (167) hide show
  1. package/CHANGELOG.md +79 -3
  2. package/dist/development/dom-export.js +1 -1
  3. package/dist/development/index-react-server-client.js +1 -1
  4. package/dist/development/index-react-server.d.ts +46 -39
  5. package/dist/development/index-react-server.js +104 -41
  6. package/dist/development/index.js +1 -1
  7. package/dist/development/lib/actions.js +1 -1
  8. package/dist/development/lib/await.js +1 -1
  9. package/dist/development/lib/components.d.ts +42 -38
  10. package/dist/development/lib/components.js +34 -36
  11. package/dist/development/lib/context.js +3 -2
  12. package/dist/development/lib/dom/dom.js +16 -5
  13. package/dist/development/lib/dom/lib.d.ts +2 -2
  14. package/dist/development/lib/dom/lib.js +22 -8
  15. package/dist/development/lib/dom/server.js +5 -3
  16. package/dist/development/lib/dom/ssr/components.js +4 -1
  17. package/dist/development/lib/dom/ssr/data.js +1 -1
  18. package/dist/development/lib/dom/ssr/errorBoundaries.js +2 -1
  19. package/dist/development/lib/dom/ssr/fallback.js +2 -1
  20. package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
  21. package/dist/development/lib/dom/ssr/hydration.d.ts +1 -0
  22. package/dist/development/lib/dom/ssr/hydration.js +1 -1
  23. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  24. package/dist/development/lib/dom/ssr/links.js +1 -1
  25. package/dist/development/lib/dom/ssr/markup.js +1 -1
  26. package/dist/development/lib/dom/ssr/route-discovery.js +1 -1
  27. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  28. package/dist/development/lib/dom/ssr/routes-test-stub.js +3 -1
  29. package/dist/development/lib/dom/ssr/routes.js +2 -1
  30. package/dist/development/lib/dom/ssr/server.js +1 -1
  31. package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
  32. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  33. package/dist/development/lib/dom-export/hydrated-router.d.ts +1 -1
  34. package/dist/development/lib/dom-export/hydrated-router.js +4 -2
  35. package/dist/development/lib/errors.js +1 -1
  36. package/dist/development/lib/hooks.d.ts +30 -0
  37. package/dist/development/lib/hooks.js +46 -7
  38. package/dist/development/lib/href.js +4 -4
  39. package/dist/development/lib/router/history.js +10 -4
  40. package/dist/development/lib/router/instrumentation.js +1 -1
  41. package/dist/development/lib/router/matcher-route-pattern.js +1 -1
  42. package/dist/development/lib/router/matcher-route-pattern.preload.js +1 -1
  43. package/dist/development/lib/router/matcher.js +1 -1
  44. package/dist/development/lib/router/navigation.js +17 -2
  45. package/dist/development/lib/router/router.js +26 -9
  46. package/dist/development/lib/router/url.js +1 -1
  47. package/dist/development/lib/router/utils.d.ts +8 -5
  48. package/dist/development/lib/router/utils.js +24 -9
  49. package/dist/development/lib/rsc/browser.js +27 -4
  50. package/dist/development/lib/rsc/errorBoundaries.js +3 -2
  51. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  52. package/dist/development/lib/rsc/html-stream/server.js +1 -1
  53. package/dist/development/lib/rsc/route-modules.js +1 -1
  54. package/dist/development/lib/rsc/server.rsc.d.ts +4 -1
  55. package/dist/development/lib/rsc/server.ssr.d.ts +1 -0
  56. package/dist/development/lib/rsc/server.ssr.js +5 -4
  57. package/dist/development/lib/server-runtime/cookies.js +1 -1
  58. package/dist/development/lib/server-runtime/crypto.js +1 -1
  59. package/dist/development/lib/server-runtime/data.js +1 -1
  60. package/dist/development/lib/server-runtime/dev.js +1 -1
  61. package/dist/development/lib/server-runtime/entry.js +1 -1
  62. package/dist/development/lib/server-runtime/errors.js +1 -1
  63. package/dist/development/lib/server-runtime/headers.js +1 -1
  64. package/dist/development/lib/server-runtime/invariant.js +1 -1
  65. package/dist/development/lib/server-runtime/mode.js +1 -1
  66. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  67. package/dist/development/lib/server-runtime/routes.js +1 -1
  68. package/dist/development/lib/server-runtime/server.js +9 -6
  69. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  70. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +3 -2
  71. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  72. package/dist/development/lib/server-runtime/sessions.d.ts +1 -1
  73. package/dist/development/lib/server-runtime/sessions.js +5 -3
  74. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  75. package/dist/development/lib/server-runtime/urls.js +1 -1
  76. package/dist/development/lib/server-runtime/warnings.js +1 -1
  77. package/dist/development/lib/types/internal.js +1 -1
  78. package/dist/development/lib/types/route-module-annotations.d.ts +16 -9
  79. package/dist/development/route-pattern.js +1 -1
  80. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  81. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +83 -73
  82. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  83. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  84. package/dist/production/dom-export.js +1 -1
  85. package/dist/production/index-react-server-client.js +1 -1
  86. package/dist/production/index-react-server.d.ts +46 -39
  87. package/dist/production/index-react-server.js +104 -41
  88. package/dist/production/index.js +1 -1
  89. package/dist/production/lib/actions.js +1 -1
  90. package/dist/production/lib/await.js +1 -1
  91. package/dist/production/lib/components.d.ts +42 -38
  92. package/dist/production/lib/components.js +34 -36
  93. package/dist/production/lib/context.js +3 -2
  94. package/dist/production/lib/dom/dom.js +16 -5
  95. package/dist/production/lib/dom/lib.d.ts +2 -2
  96. package/dist/production/lib/dom/lib.js +22 -8
  97. package/dist/production/lib/dom/server.js +5 -3
  98. package/dist/production/lib/dom/ssr/components.js +4 -1
  99. package/dist/production/lib/dom/ssr/data.js +1 -1
  100. package/dist/production/lib/dom/ssr/errorBoundaries.js +2 -1
  101. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  102. package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
  103. package/dist/production/lib/dom/ssr/hydration.d.ts +1 -0
  104. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  105. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  106. package/dist/production/lib/dom/ssr/links.js +1 -1
  107. package/dist/production/lib/dom/ssr/markup.js +1 -1
  108. package/dist/production/lib/dom/ssr/route-discovery.js +1 -1
  109. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  110. package/dist/production/lib/dom/ssr/routes-test-stub.js +3 -1
  111. package/dist/production/lib/dom/ssr/routes.js +2 -1
  112. package/dist/production/lib/dom/ssr/server.js +1 -1
  113. package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
  114. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  115. package/dist/production/lib/dom-export/hydrated-router.d.ts +1 -1
  116. package/dist/production/lib/dom-export/hydrated-router.js +4 -2
  117. package/dist/production/lib/errors.js +1 -1
  118. package/dist/production/lib/hooks.d.ts +30 -0
  119. package/dist/production/lib/hooks.js +45 -6
  120. package/dist/production/lib/href.js +4 -4
  121. package/dist/production/lib/router/history.js +10 -4
  122. package/dist/production/lib/router/instrumentation.js +1 -1
  123. package/dist/production/lib/router/matcher-route-pattern.js +1 -1
  124. package/dist/production/lib/router/matcher-route-pattern.preload.js +1 -1
  125. package/dist/production/lib/router/matcher.js +1 -1
  126. package/dist/production/lib/router/navigation.js +17 -2
  127. package/dist/production/lib/router/router.js +26 -9
  128. package/dist/production/lib/router/url.js +1 -1
  129. package/dist/production/lib/router/utils.d.ts +8 -5
  130. package/dist/production/lib/router/utils.js +24 -9
  131. package/dist/production/lib/rsc/browser.js +27 -4
  132. package/dist/production/lib/rsc/errorBoundaries.js +3 -2
  133. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  134. package/dist/production/lib/rsc/html-stream/server.js +1 -1
  135. package/dist/production/lib/rsc/route-modules.js +1 -1
  136. package/dist/production/lib/rsc/server.rsc.d.ts +4 -1
  137. package/dist/production/lib/rsc/server.ssr.d.ts +1 -0
  138. package/dist/production/lib/rsc/server.ssr.js +5 -4
  139. package/dist/production/lib/server-runtime/cookies.js +1 -1
  140. package/dist/production/lib/server-runtime/crypto.js +1 -1
  141. package/dist/production/lib/server-runtime/data.js +1 -1
  142. package/dist/production/lib/server-runtime/dev.js +1 -1
  143. package/dist/production/lib/server-runtime/entry.js +1 -1
  144. package/dist/production/lib/server-runtime/errors.js +1 -1
  145. package/dist/production/lib/server-runtime/headers.js +1 -1
  146. package/dist/production/lib/server-runtime/invariant.js +1 -1
  147. package/dist/production/lib/server-runtime/mode.js +1 -1
  148. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  149. package/dist/production/lib/server-runtime/routes.js +1 -1
  150. package/dist/production/lib/server-runtime/server.js +9 -6
  151. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  152. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +3 -2
  153. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  154. package/dist/production/lib/server-runtime/sessions.d.ts +1 -1
  155. package/dist/production/lib/server-runtime/sessions.js +5 -3
  156. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  157. package/dist/production/lib/server-runtime/urls.js +1 -1
  158. package/dist/production/lib/server-runtime/warnings.js +1 -1
  159. package/dist/production/lib/types/internal.js +1 -1
  160. package/dist/production/lib/types/route-module-annotations.d.ts +16 -9
  161. package/dist/production/route-pattern.js +1 -1
  162. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  163. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +83 -73
  164. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  165. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  166. package/docs/upgrading/v7.md +11 -0
  167. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,6 +10,7 @@
10
10
  */
11
11
  import { ABSOLUTE_URL_REGEX, PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
12
12
  import { invariant, parsePath, warning } from "./history.js";
13
+ import { validateDocumentNavigationTarget } from "./navigation.js";
13
14
  import * as React$1 from "react";
14
15
  //#region lib/router/utils.ts
15
16
  /**
@@ -422,13 +423,14 @@ function encodePathParam(value) {
422
423
  /**
423
424
  * Returns a path with params interpolated.
424
425
  *
425
- * Param values are percent-encoded for use in a path segment: characters that
426
- * would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
426
+ * Named param values are percent-encoded for use in a path segment: characters
427
+ * that would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
427
428
  * are escaped, while characters that RFC 3986 allows literally in a path
428
429
  * segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
429
430
  * encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
430
- * delimiters and must be escaped. Splat (`*`) values are encoded per segment,
431
- * preserving `/` separators.
431
+ * delimiters and must be escaped. Splat (`*`) values are interpolated without
432
+ * per-segment encoding. Leading URL separators and schemes are handled so
433
+ * interpolated values remain paths.
432
434
  *
433
435
  * See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
434
436
  *
@@ -453,7 +455,7 @@ function generatePath(originalPath, params = {}) {
453
455
  }
454
456
  const prefix = path.startsWith("/") ? "/" : "";
455
457
  const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
456
- return prefix + path.split(/\/+/).map((segment, index, array) => {
458
+ let result = (prefix + path.split(/\/+/).map((segment, index, array) => {
457
459
  if (index === array.length - 1 && segment === "*") return stringify(params["*"]);
458
460
  const keyMatch = segment.match(/^:([\w-]+)(\??)(.*)/);
459
461
  if (keyMatch) {
@@ -463,12 +465,18 @@ function generatePath(originalPath, params = {}) {
463
465
  return encodePathParam(stringify(param)) + suffix;
464
466
  }
465
467
  return segment.replace(/\?$/g, "");
466
- }).filter((segment) => !!segment).join("/");
468
+ }).filter((segment) => !!segment).join("/")).replace(/^[\\/]{2,}/, "/");
469
+ if (!prefix && (path.startsWith(":") || path === "*")) result = result.replace(/^([a-z][a-z0-9+.-]*):/i, "$1%3A");
470
+ validateDocumentNavigationTarget(result);
471
+ return result;
467
472
  }
473
+ const MAX_OPTIONAL_PATH_SEGMENTS = 12;
468
474
  /**
469
475
  * Performs pattern matching on a URL pathname and returns information about
470
476
  * the match.
471
477
  *
478
+ * Throws if the pattern contains more than 12 optional (`?`) markers.
479
+ *
472
480
  * @public
473
481
  * @category Utils
474
482
  * @param pattern The pattern to match against the URL pathname. This can be a
@@ -485,7 +493,10 @@ function matchPath(pattern, pathname) {
485
493
  caseSensitive: false,
486
494
  end: true
487
495
  };
488
- let [matcher, compiledParams] = compilePath(pattern.path, pattern.caseSensitive, pattern.end);
496
+ let { path } = pattern;
497
+ let optionalSegments = 0;
498
+ for (let index = path.indexOf("?"); index !== -1; index = path.indexOf("?", index + 1)) if (++optionalSegments > MAX_OPTIONAL_PATH_SEGMENTS) throw new Error(`Path pattern ${JSON.stringify(path)} exceeds the limit of ${MAX_OPTIONAL_PATH_SEGMENTS} optional segments.`);
499
+ let [matcher, compiledParams] = compilePath(path, pattern.caseSensitive, pattern.end);
489
500
  return matchPathImpl(pattern, pathname, matcher, compiledParams);
490
501
  }
491
502
  function matchPathImpl(pattern, pathname, matcher, compiledParams) {
@@ -705,11 +716,15 @@ function data(data, init) {
705
716
  * header.
706
717
  */
707
718
  const redirect = (url, init = 302) => {
719
+ validateDocumentNavigationTarget(url);
708
720
  let responseInit = init;
709
721
  if (typeof responseInit === "number") responseInit = { status: responseInit };
710
- else if (typeof responseInit.status === "undefined") responseInit.status = 302;
711
722
  let headers = new Headers(responseInit.headers);
712
723
  headers.set("Location", url);
724
+ if (typeof responseInit.status === "undefined") responseInit = {
725
+ ...responseInit,
726
+ status: 302
727
+ };
713
728
  return new Response(null, {
714
729
  ...responseInit,
715
730
  headers
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,8 +10,8 @@
10
10
  */
11
11
  import { PROTOCOL_RELATIVE_URL_REGEX } from "../router/url.js";
12
12
  import { createBrowserHistory, createPath, invariant } from "../router/history.js";
13
- import { ErrorResponseImpl, createContext, resolvePath } from "../router/utils.js";
14
13
  import { validateNavigationTarget } from "../router/navigation.js";
14
+ import { ErrorResponseImpl, createContext, resolvePath } from "../router/utils.js";
15
15
  import { createRouter, hasInvalidProtocol, isMutationMethod } from "../router/router.js";
16
16
  import { RSCRouterContext } from "../context.js";
17
17
  import { createRequestInit } from "../dom/ssr/data.js";
@@ -163,6 +163,7 @@ function createRouterFromPayload({ fetchImplementation, createFromReadableStream
163
163
  invariant(match, "Route not found in payload");
164
164
  return {
165
165
  clientLoader: match.clientLoader,
166
+ clientMiddleware: match.clientMiddleware,
166
167
  hasLoader: match.hasLoader,
167
168
  hasHydrateFallback: match.hydrateFallbackElement != null
168
169
  };
@@ -207,10 +208,11 @@ function createRouterFromPayload({ fetchImplementation, createFromReadableStream
207
208
  return routes.map((route) => {
208
209
  const routeUpdate = routeUpdateByRouteId.get(route.id);
209
210
  if (routeUpdate) {
210
- const { routeModule, hasAction, hasComponent, hasLoader } = routeUpdate;
211
+ const { routeModule, hasAction, hasComponent, hasLoader, hasClientMiddleware } = routeUpdate;
211
212
  const newRoute = createRouteFromServerManifest({
212
213
  clientAction: routeModule.clientAction,
213
214
  clientLoader: routeModule.clientLoader,
215
+ clientMiddleware: hasClientMiddleware ? routeModule.clientMiddleware ?? route.middleware : void 0,
214
216
  element: route.element,
215
217
  errorElement: route.errorElement,
216
218
  handle: route.handle,
@@ -389,6 +391,26 @@ function RSCHydratedRouter({ createFromReadableStream, fetch: fetchImplementatio
389
391
  routes,
390
392
  router
391
393
  ]);
394
+ React$1.useLayoutEffect(() => {
395
+ if (state.initialized) return;
396
+ let unsubscribe = () => {};
397
+ unsubscribe = router.subscribe((newState) => {
398
+ if (newState.initialized) {
399
+ unsubscribe();
400
+ React$1.startTransition(() => {
401
+ setState((current) => current.state.initialized ? current : {
402
+ ...current,
403
+ state: newState
404
+ });
405
+ });
406
+ }
407
+ });
408
+ return unsubscribe;
409
+ }, [
410
+ router.subscribe,
411
+ router,
412
+ state.initialized
413
+ ]);
392
414
  const transitionEnabledRouter = React$1.useMemo(() => ({
393
415
  ...router,
394
416
  state,
@@ -508,6 +530,7 @@ function createRouteFromServerManifest(match, payload) {
508
530
  throw noActionDefinedError("action", match.id);
509
531
  },
510
532
  path: match.path,
533
+ middleware: match.clientMiddleware,
511
534
  shouldRevalidate: match.shouldRevalidate,
512
535
  hasLoader: true,
513
536
  hasClientLoader: match.clientLoader != null,
@@ -560,13 +583,13 @@ async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fet
560
583
  if (!response.body || response.status < 200 || response.status >= 300) throw new Error("Unable to fetch new route matches from the server");
561
584
  let payload = await createFromReadableStream(response.body, { temporaryReferences: void 0 });
562
585
  if (payload.type !== "manifest") throw new Error("Failed to patch routes");
563
- paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
564
586
  let patches = await payload.patches;
565
587
  React$1.startTransition(() => {
566
588
  patches.forEach((p) => {
567
589
  window.__reactRouterDataRouter.patchRoutes(p.parentId ?? null, [createRouteFromServerManifest(p)]);
568
590
  });
569
591
  });
592
+ paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
570
593
  }
571
594
  function addToFifoQueue(path, queue) {
572
595
  if (queue.size >= discoveredPathsMaxSize) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,6 +9,7 @@
9
9
  * @license MIT
10
10
  */
11
11
  import { isRouteErrorResponse } from "../router/utils.js";
12
+ import { RSCErrorAlreadyReportedContext } from "../context.js";
12
13
  import { useRouteError } from "../hooks.js";
13
14
  import React from "react";
14
15
  //#region lib/rsc/errorBoundaries.tsx
@@ -52,7 +53,7 @@ function ErrorWrapper({ renderAppShell, title, children }) {
52
53
  } }, children)));
53
54
  }
54
55
  function RSCDefaultRootErrorBoundaryImpl({ error, renderAppShell }) {
55
- console.error(error);
56
+ if (!React.useContext(RSCErrorAlreadyReportedContext)) console.error(error);
56
57
  let heyDeveloper = /* @__PURE__ */ React.createElement("script", { dangerouslySetInnerHTML: { __html: `
57
58
  console.log(
58
59
  "💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -11,6 +11,7 @@ type RSCRouteConfigEntryBase = {
11
11
  action?: ActionFunction;
12
12
  clientAction?: ClientActionFunction;
13
13
  clientLoader?: ClientLoaderFunction;
14
+ clientMiddleware?: MiddlewareFunction<any>[];
14
15
  ErrorBoundary?: React$1.ComponentType<any>;
15
16
  handle?: any;
16
17
  headers?: HeadersFunction;
@@ -42,6 +43,7 @@ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
42
43
  type RSCRouteManifest = {
43
44
  clientAction?: ClientActionFunction;
44
45
  clientLoader?: ClientLoaderFunction;
46
+ clientMiddleware?: MiddlewareFunction<any>[];
45
47
  element?: React$1.ReactElement | false;
46
48
  errorElement?: React$1.ReactElement;
47
49
  handle?: any;
@@ -179,7 +181,8 @@ type RouteDiscovery = {
179
181
  * @param opts.clientVersion A version derived from the client build output used
180
182
  * to detect stale clients during lazy route discovery.
181
183
  * @param opts.onError An optional error handler that will be called with any
182
- * errors that occur during the request processing.
184
+ * errors that occur during the request processing. Defaults to logging errors
185
+ * with `console.error` unless the request was aborted.
183
186
  * @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
184
187
  * to match against.
185
188
  * @param opts.requestContext An instance of {@link RouterContextProvider}
@@ -5,6 +5,7 @@ import * as React$1 from "react";
5
5
  //#region lib/rsc/server.ssr.d.ts
6
6
  type DecodedPayload = Promise<RSCPayload> & {
7
7
  _deepestRenderedBoundaryId?: string | null;
8
+ _isErrorRender?: boolean;
8
9
  formState: Promise<any>;
9
10
  };
10
11
  type SSRCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>) => Promise<unknown>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { isRouteErrorResponse } from "../router/utils.js";
12
12
  import { createDataRouteMatcher, hasInvalidProtocol } from "../router/router.js";
13
- import { RSCRouterContext } from "../context.js";
13
+ import { RSCErrorAlreadyReportedContext, RSCRouterContext } from "../context.js";
14
14
  import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "../errors.js";
15
15
  import { escapeAttribute } from "../dom/ssr/markup.js";
16
16
  import { shouldHydrateRouteLoader } from "../dom/ssr/routes.js";
@@ -214,6 +214,7 @@ async function routeRSCServerRequest({ request, serverResponse, createFromReadab
214
214
  errors: deepestRenderedBoundaryId ? { [deepestRenderedBoundaryId]: normalizedError } : {}
215
215
  }));
216
216
  return Object.defineProperties(payloadPromise, {
217
+ _isErrorRender: { value: true },
217
218
  _deepestRenderedBoundaryId: {
218
219
  get() {
219
220
  return deepestRenderedBoundaryId;
@@ -407,11 +408,11 @@ function RSCStaticRouter({ getPayload, nonce }) {
407
408
  routeModules: createRSCRouteModules(payload),
408
409
  nonce
409
410
  };
410
- return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(StaticRouterProvider, {
411
+ return /* @__PURE__ */ React$1.createElement(RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React$1.createElement(RSCRouterGlobalErrorBoundary, { location: payload.location }, /* @__PURE__ */ React$1.createElement(FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React$1.createElement(RSCErrorAlreadyReportedContext.Provider, { value: payload.errors != null && !decoded._isErrorRender }, /* @__PURE__ */ React$1.createElement(StaticRouterProvider, {
411
412
  context,
412
413
  router,
413
414
  hydrate: false
414
- }))));
415
+ })))));
415
416
  }
416
417
  function isReactServerRequest(url) {
417
418
  return url.pathname.endsWith(".rsc");
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -129,11 +129,14 @@ function derive(build, mode) {
129
129
  else if (mode === "development" && getDevServerHooks()?.getCriticalCss) criticalCss = await getDevServerHooks()?.getCriticalCss?.(pathname);
130
130
  response = await handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, isSpaMode, criticalCss);
131
131
  }
132
- if (request.method === "HEAD") return new Response(null, {
133
- headers: response.headers,
134
- status: response.status,
135
- statusText: response.statusText
136
- });
132
+ if (request.method === "HEAD") {
133
+ response.body?.cancel().catch(() => {});
134
+ return new Response(null, {
135
+ headers: response.headers,
136
+ status: response.status,
137
+ statusText: response.statusText
138
+ });
139
+ }
137
140
  return response;
138
141
  };
139
142
  if (requestHandlerInstrumentations?.length) requestHandler = instrumentHandler(requestHandler, requestHandlerInstrumentations);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -33,7 +33,8 @@ function createCookieSessionStorage({ cookie: cookieArg } = {}) {
33
33
  warnOnceAboutSigningSessionCookie(cookie);
34
34
  return {
35
35
  async getSession(cookieHeader, options) {
36
- return createSession(cookieHeader && await cookie.parse(cookieHeader, options) || {});
36
+ let data = cookieHeader && await cookie.parse(cookieHeader, options);
37
+ return createSession(typeof data === "object" && data !== null && !Array.isArray(data) ? data : {});
37
38
  },
38
39
  async commitSession(session, options) {
39
40
  let serializedCookie = await cookie.serialize(session.data, options);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -50,7 +50,7 @@ interface Session<Data = SessionData, FlashData = Data> {
50
50
  /**
51
51
  * Removes a value from the session.
52
52
  */
53
- unset(name: keyof Data & string): void;
53
+ unset(name: (keyof Data | keyof FlashData) & string): void;
54
54
  }
55
55
  type FlashSessionData<Data, FlashData> = Partial<Data & { [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key] }>;
56
56
  type FlashDataKey<Key extends string> = `__flash_${Key}__`;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -55,6 +55,7 @@ const createSession = (initialData = {}, id = "") => {
55
55
  },
56
56
  unset(name) {
57
57
  map.delete(name);
58
+ map.delete(flash(name));
58
59
  }
59
60
  };
60
61
  };
@@ -88,8 +89,9 @@ function createSessionStorage({ cookie: cookieArg, createData, readData, updateD
88
89
  warnOnceAboutSigningSessionCookie(cookie);
89
90
  return {
90
91
  async getSession(cookieHeader, options) {
91
- let id = cookieHeader && await cookie.parse(cookieHeader, options);
92
- return createSession(id && await readData(id) || {}, id || "");
92
+ let parsedId = cookieHeader && await cookie.parse(cookieHeader, options);
93
+ let id = typeof parsedId === "string" && parsedId ? parsedId : "";
94
+ return createSession((id ? await readData(id) : null) || {}, id);
93
95
  },
94
96
  async commitSession(session, options) {
95
97
  let { id, data } = session;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -14,24 +14,31 @@ type Props = {
14
14
  loaderData: unknown;
15
15
  actionData: unknown;
16
16
  };
17
- type RouteInfo = Props & {
17
+ type MatchInfo = {
18
+ id: string;
18
19
  module: RouteModule;
19
- matches: Array<MatchInfo>;
20
20
  };
21
- type MatchInfo = {
21
+ type MatchInfoWithLoaderData = {
22
22
  id: string;
23
+ module?: never;
24
+ loaderData: unknown;
25
+ };
26
+ type AnyMatchInfo = MatchInfo | MatchInfoWithLoaderData;
27
+ type RouteInfo = Props & {
23
28
  module: RouteModule;
29
+ matches: Array<AnyMatchInfo>;
24
30
  };
25
- type MetaMatch<T extends MatchInfo> = Pretty<{
31
+ type MatchData<T extends AnyMatchInfo> = T extends MatchInfo ? GetLoaderData<T["module"]> : T extends MatchInfoWithLoaderData ? T["loaderData"] : never;
32
+ type MetaMatch<T extends AnyMatchInfo> = Pretty<{
26
33
  id: T["id"];
27
34
  params: Record<string, string | undefined>;
28
35
  pathname: string;
29
36
  meta: MetaDescriptor[];
30
- loaderData: GetLoaderData<T["module"]>;
37
+ loaderData: MatchData<T>;
31
38
  handle?: unknown;
32
39
  error?: unknown;
33
40
  }>;
34
- type MetaMatches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : Array<MetaMatch<MatchInfo> | undefined>;
41
+ type MetaMatches<T extends Array<AnyMatchInfo>> = T extends [infer F extends AnyMatchInfo, ...infer R extends Array<AnyMatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : T extends [] ? [] : Array<MetaMatch<AnyMatchInfo> | undefined>;
35
42
  type HasErrorBoundary<T extends RouteInfo> = T["module"] extends {
36
43
  ErrorBoundary: Func;
37
44
  } ? true : false;
@@ -68,14 +75,14 @@ type CreateHydrateFallbackProps<T extends RouteInfo, RSCEnabled extends boolean>
68
75
  /** The data returned from the `loader` or `clientLoader` */loaderData?: T["loaderData"]; /** The data returned from the `action` or `clientAction` following an action submission. */
69
76
  actionData?: T["actionData"];
70
77
  });
71
- type Match<T extends MatchInfo> = Pretty<{
78
+ type Match<T extends AnyMatchInfo> = Pretty<{
72
79
  id: T["id"];
73
80
  params: Record<string, string | undefined>;
74
81
  pathname: string;
75
- loaderData: GetLoaderData<T["module"]>;
82
+ loaderData: MatchData<T>;
76
83
  handle: unknown;
77
84
  }>;
78
- type Matches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [Match<F>, ...Matches<R>] : Array<Match<MatchInfo> | undefined>;
85
+ type Matches<T extends Array<AnyMatchInfo>> = T extends [infer F extends AnyMatchInfo, ...infer R extends Array<AnyMatchInfo>] ? [Match<F>, ...Matches<R>] : Array<Match<AnyMatchInfo> | undefined>;
79
86
  type CreateComponentProps<T extends RouteInfo, RSCEnabled extends boolean> = {
80
87
  /**
81
88
  * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.5.1
2
+ * react-router v8.5.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *