react-router 8.0.1 → 8.2.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 (148) hide show
  1. package/CHANGELOG.md +24 -0
  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 +35 -9
  5. package/dist/development/index-react-server.js +190 -157
  6. package/dist/development/index.d.ts +2 -2
  7. package/dist/development/index.js +1 -1
  8. package/dist/development/lib/actions.js +1 -1
  9. package/dist/development/lib/components.js +1 -1
  10. package/dist/development/lib/context.js +1 -1
  11. package/dist/development/lib/dom/dom.js +1 -1
  12. package/dist/development/lib/dom/lib.js +2 -2
  13. package/dist/development/lib/dom/server.js +1 -1
  14. package/dist/development/lib/dom/ssr/components.js +1 -1
  15. package/dist/development/lib/dom/ssr/data.js +1 -1
  16. package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
  17. package/dist/development/lib/dom/ssr/fallback.js +1 -1
  18. package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
  19. package/dist/development/lib/dom/ssr/hydration.js +1 -1
  20. package/dist/development/lib/dom/ssr/invariant.js +1 -1
  21. package/dist/development/lib/dom/ssr/links.js +1 -1
  22. package/dist/development/lib/dom/ssr/markup.js +1 -1
  23. package/dist/development/lib/dom/ssr/routeModules.js +1 -1
  24. package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
  25. package/dist/development/lib/dom/ssr/routes.js +1 -1
  26. package/dist/development/lib/dom/ssr/server.js +1 -1
  27. package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
  28. package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
  29. package/dist/development/lib/dom-export/hydrated-router.js +1 -1
  30. package/dist/development/lib/errors.js +1 -1
  31. package/dist/development/lib/hooks.d.ts +33 -6
  32. package/dist/development/lib/hooks.js +34 -7
  33. package/dist/development/lib/href.js +6 -3
  34. package/dist/development/lib/router/history.js +1 -1
  35. package/dist/development/lib/router/instrumentation.d.ts +33 -8
  36. package/dist/development/lib/router/instrumentation.js +176 -99
  37. package/dist/development/lib/router/router.js +20 -20
  38. package/dist/development/lib/router/url.js +1 -1
  39. package/dist/development/lib/router/utils.js +21 -4
  40. package/dist/development/lib/rsc/browser.js +1 -1
  41. package/dist/development/lib/rsc/errorBoundaries.js +1 -1
  42. package/dist/development/lib/rsc/html-stream/browser.js +1 -1
  43. package/dist/development/lib/rsc/html-stream/server.js +1 -1
  44. package/dist/development/lib/rsc/route-modules.js +1 -1
  45. package/dist/development/lib/rsc/server.rsc.d.ts +3 -2
  46. package/dist/development/lib/rsc/server.ssr.js +1 -1
  47. package/dist/development/lib/server-runtime/cookies.js +1 -1
  48. package/dist/development/lib/server-runtime/crypto.js +1 -1
  49. package/dist/development/lib/server-runtime/data.js +1 -1
  50. package/dist/development/lib/server-runtime/dev.js +1 -1
  51. package/dist/development/lib/server-runtime/entry.js +1 -1
  52. package/dist/development/lib/server-runtime/errors.js +1 -1
  53. package/dist/development/lib/server-runtime/headers.js +1 -1
  54. package/dist/development/lib/server-runtime/invariant.js +1 -1
  55. package/dist/development/lib/server-runtime/mode.js +1 -1
  56. package/dist/development/lib/server-runtime/routeMatching.js +1 -1
  57. package/dist/development/lib/server-runtime/routes.js +1 -1
  58. package/dist/development/lib/server-runtime/server.js +12 -5
  59. package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
  60. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
  61. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
  62. package/dist/development/lib/server-runtime/sessions.js +1 -1
  63. package/dist/development/lib/server-runtime/single-fetch.js +1 -1
  64. package/dist/development/lib/server-runtime/urls.js +1 -1
  65. package/dist/development/lib/server-runtime/warnings.js +1 -1
  66. package/dist/development/lib/types/internal.js +1 -1
  67. package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
  68. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  69. package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
  70. package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
  71. package/dist/production/dom-export.js +1 -1
  72. package/dist/production/index-react-server-client.js +1 -1
  73. package/dist/production/index-react-server.d.ts +35 -9
  74. package/dist/production/index-react-server.js +190 -157
  75. package/dist/production/index.d.ts +2 -2
  76. package/dist/production/index.js +1 -1
  77. package/dist/production/lib/actions.js +1 -1
  78. package/dist/production/lib/components.js +1 -1
  79. package/dist/production/lib/context.js +1 -1
  80. package/dist/production/lib/dom/dom.js +1 -1
  81. package/dist/production/lib/dom/lib.js +2 -2
  82. package/dist/production/lib/dom/server.js +1 -1
  83. package/dist/production/lib/dom/ssr/components.js +1 -1
  84. package/dist/production/lib/dom/ssr/data.js +1 -1
  85. package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
  86. package/dist/production/lib/dom/ssr/fallback.js +1 -1
  87. package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
  88. package/dist/production/lib/dom/ssr/hydration.js +1 -1
  89. package/dist/production/lib/dom/ssr/invariant.js +1 -1
  90. package/dist/production/lib/dom/ssr/links.js +1 -1
  91. package/dist/production/lib/dom/ssr/markup.js +1 -1
  92. package/dist/production/lib/dom/ssr/routeModules.js +1 -1
  93. package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
  94. package/dist/production/lib/dom/ssr/routes.js +1 -1
  95. package/dist/production/lib/dom/ssr/server.js +1 -1
  96. package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
  97. package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
  98. package/dist/production/lib/dom-export/hydrated-router.js +1 -1
  99. package/dist/production/lib/errors.js +1 -1
  100. package/dist/production/lib/hooks.d.ts +33 -6
  101. package/dist/production/lib/hooks.js +34 -7
  102. package/dist/production/lib/href.js +6 -3
  103. package/dist/production/lib/router/history.js +1 -1
  104. package/dist/production/lib/router/instrumentation.d.ts +33 -8
  105. package/dist/production/lib/router/instrumentation.js +176 -99
  106. package/dist/production/lib/router/router.js +20 -20
  107. package/dist/production/lib/router/url.js +1 -1
  108. package/dist/production/lib/router/utils.js +21 -4
  109. package/dist/production/lib/rsc/browser.js +1 -1
  110. package/dist/production/lib/rsc/errorBoundaries.js +1 -1
  111. package/dist/production/lib/rsc/html-stream/browser.js +1 -1
  112. package/dist/production/lib/rsc/html-stream/server.js +1 -1
  113. package/dist/production/lib/rsc/route-modules.js +1 -1
  114. package/dist/production/lib/rsc/server.rsc.d.ts +3 -2
  115. package/dist/production/lib/rsc/server.ssr.js +1 -1
  116. package/dist/production/lib/server-runtime/cookies.js +1 -1
  117. package/dist/production/lib/server-runtime/crypto.js +1 -1
  118. package/dist/production/lib/server-runtime/data.js +1 -1
  119. package/dist/production/lib/server-runtime/dev.js +1 -1
  120. package/dist/production/lib/server-runtime/entry.js +1 -1
  121. package/dist/production/lib/server-runtime/errors.js +1 -1
  122. package/dist/production/lib/server-runtime/headers.js +1 -1
  123. package/dist/production/lib/server-runtime/invariant.js +1 -1
  124. package/dist/production/lib/server-runtime/mode.js +1 -1
  125. package/dist/production/lib/server-runtime/routeMatching.js +1 -1
  126. package/dist/production/lib/server-runtime/routes.js +1 -1
  127. package/dist/production/lib/server-runtime/server.js +12 -5
  128. package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
  129. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
  130. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
  131. package/dist/production/lib/server-runtime/sessions.js +1 -1
  132. package/dist/production/lib/server-runtime/single-fetch.js +1 -1
  133. package/dist/production/lib/server-runtime/urls.js +1 -1
  134. package/dist/production/lib/server-runtime/warnings.js +1 -1
  135. package/dist/production/lib/types/internal.js +1 -1
  136. package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
  137. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
  138. package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
  139. package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
  140. package/docs/explanation/hot-module-replacement.md +1 -1
  141. package/docs/how-to/data-strategy.md +1 -1
  142. package/docs/how-to/instrumentation.md +131 -26
  143. package/docs/start/framework/deploying.md +4 -0
  144. package/docs/upgrading/component-routes.md +2 -2
  145. package/docs/upgrading/future.md +33 -0
  146. package/docs/upgrading/router-provider.md +6 -6
  147. package/docs/upgrading/v7.md +39 -22
  148. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -143,12 +143,16 @@ interface NavigateFunction {
143
143
  * All properties are optional.
144
144
  *
145
145
  * ```tsx
146
- * navigate({
147
- * pathname: "/some/route",
148
- * search: "?search=param",
149
- * hash: "#hash",
150
- * state: { some: "state" },
151
- * });
146
+ * navigate(
147
+ * {
148
+ * pathname: "/some/route",
149
+ * search: "?search=param",
150
+ * hash: "#hash",
151
+ * },
152
+ * {
153
+ * state: { some: "state" },
154
+ * },
155
+ * );
152
156
  * ```
153
157
  *
154
158
  * If you use `state`, that will be available on the {@link Location} object on
@@ -576,6 +580,29 @@ declare function useRevalidator(): {
576
580
  * parent/child routes or the route [`handle`](../../start/framework/route-module#handle)
577
581
  * property
578
582
  *
583
+ * Pairing the route `handle` with `useMatches` gets very powerful since you can put
584
+ * whatever you want on a route handle and have access to `useMatches` anywhere.
585
+ * Please see the [handle](../../how-to/using-handle) documentation for an example
586
+ * of breadcrumbs via `useMatches`/`handle`.
587
+ *
588
+ * ```tsx
589
+ * import { useMatches } from "react-router";
590
+ *
591
+ * function SomeComponent() {
592
+ * const matches = useMatches();
593
+ * // matches[i].id // route id
594
+ * // matches[i].pathname // the portion of the URL the route matched
595
+ * // matches[i].params // the parsed params from the URL
596
+ * // matches[i].loaderData // the data from the loader
597
+ * // matches[i].handle // the route handle with any app specific data
598
+ * }
599
+ * ```
600
+ *
601
+ * <docs-info>useMatches only works with a data router like `createBrowserRouter`,
602
+ * since they know the full route tree up front and can provide all of the current
603
+ * matches. Additionally, `useMatches` will not match down into any descendant route
604
+ * trees since the router isn't aware of the descendant routes.</docs-info>
605
+ *
579
606
  * @public
580
607
  * @category Hooks
581
608
  * @mode framework
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -162,12 +162,16 @@ const navigateEffectWarning = "You should call navigate() in a React.useEffect()
162
162
  * All properties are optional.
163
163
  *
164
164
  * ```tsx
165
- * navigate({
166
- * pathname: "/some/route",
167
- * search: "?search=param",
168
- * hash: "#hash",
169
- * state: { some: "state" },
170
- * });
165
+ * navigate(
166
+ * {
167
+ * pathname: "/some/route",
168
+ * search: "?search=param",
169
+ * hash: "#hash",
170
+ * },
171
+ * {
172
+ * state: { some: "state" },
173
+ * },
174
+ * );
171
175
  * ```
172
176
  *
173
177
  * If you use `state`, that will be available on the {@link Location} object on
@@ -919,6 +923,29 @@ function useRevalidator() {
919
923
  * parent/child routes or the route [`handle`](../../start/framework/route-module#handle)
920
924
  * property
921
925
  *
926
+ * Pairing the route `handle` with `useMatches` gets very powerful since you can put
927
+ * whatever you want on a route handle and have access to `useMatches` anywhere.
928
+ * Please see the [handle](../../how-to/using-handle) documentation for an example
929
+ * of breadcrumbs via `useMatches`/`handle`.
930
+ *
931
+ * ```tsx
932
+ * import { useMatches } from "react-router";
933
+ *
934
+ * function SomeComponent() {
935
+ * const matches = useMatches();
936
+ * // matches[i].id // route id
937
+ * // matches[i].pathname // the portion of the URL the route matched
938
+ * // matches[i].params // the parsed params from the URL
939
+ * // matches[i].loaderData // the data from the loader
940
+ * // matches[i].handle // the route handle with any app specific data
941
+ * }
942
+ * ```
943
+ *
944
+ * <docs-info>useMatches only works with a data router like `createBrowserRouter`,
945
+ * since they know the full route tree up front and can provide all of the current
946
+ * matches. Additionally, `useMatches` will not match down into any descendant route
947
+ * trees since the router isn't aware of the descendant routes.</docs-info>
948
+ *
922
949
  * @public
923
950
  * @category Hooks
924
951
  * @mode framework
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,6 +9,9 @@
9
9
  * @license MIT
10
10
  */
11
11
  //#region lib/href.ts
12
+ function stringify(p) {
13
+ return p == null ? "" : typeof p === "string" ? p : String(p);
14
+ }
12
15
  /**
13
16
  Returns a resolved URL path for the specified route.
14
17
 
@@ -25,11 +28,11 @@ function href(path, ...args) {
25
28
  const isRequired = questionMark === void 0;
26
29
  const value = params?.[param];
27
30
  if (isRequired && value === void 0) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
28
- return value === void 0 ? "" : "/" + value;
31
+ return value == null ? "" : "/" + encodeURIComponent(stringify(value));
29
32
  });
30
33
  if (path.endsWith("*")) {
31
34
  const value = params?.["*"];
32
- if (value !== void 0) result += "/" + value;
35
+ if (value !== void 0) result += "/" + stringify(value).split("/").map(encodeURIComponent).join("/");
33
36
  }
34
37
  return result || "/";
35
38
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v8.0.1
2
+ * react-router v8.2.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -12,6 +12,19 @@ type ClientInstrumentation = {
12
12
  type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
13
13
  type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
14
14
  type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
15
+ /**
16
+ * Route metadata available after React Router has matched an instrumented
17
+ * request, navigation, or fetcher call.
18
+ */
19
+ type InstrumentationResultMeta = {
20
+ url: LoaderFunctionArgs["url"];
21
+ pattern: string;
22
+ params: LoaderFunctionArgs["params"];
23
+ };
24
+ /**
25
+ * Result returned by route-level instrumented handler calls, such as
26
+ * instrumented loaders, actions, middleware, and lazy route functions.
27
+ */
15
28
  type InstrumentationHandlerResult = {
16
29
  status: "success";
17
30
  error: undefined;
@@ -19,7 +32,21 @@ type InstrumentationHandlerResult = {
19
32
  status: "error";
20
33
  error: Error;
21
34
  };
22
- type InstrumentFunction<T> = (handler: () => Promise<InstrumentationHandlerResult>, info: T) => Promise<void>;
35
+ /**
36
+ * Result returned by client-side router instrumented navigation and fetcher
37
+ * calls.
38
+ */
39
+ type InstrumentationClientRouterResult = InstrumentationHandlerResult & {
40
+ meta: InstrumentationResultMeta | undefined;
41
+ };
42
+ /**
43
+ * Result returned by server request handler instrumentation.
44
+ */
45
+ type InstrumentationServerHandlerResult = InstrumentationHandlerResult & {
46
+ statusCode: number;
47
+ meta: InstrumentationResultMeta | undefined;
48
+ };
49
+ type InstrumentFunction<T, TInnerResult = InstrumentationHandlerResult> = (handler: () => Promise<TInnerResult>, info: T) => Promise<void>;
23
50
  type ReadonlyRequest = {
24
51
  method: string;
25
52
  url: string;
@@ -42,18 +69,16 @@ type RouteInstrumentations = {
42
69
  action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
43
70
  };
44
71
  type RouteLazyInstrumentationInfo = undefined;
45
- type RouteHandlerInstrumentationInfo = Readonly<{
72
+ type RouteHandlerInstrumentationInfo = Readonly<Omit<LoaderFunctionArgs, "request" | "context"> & {
46
73
  request: ReadonlyRequest;
47
- params: LoaderFunctionArgs["params"];
48
- pattern: string;
49
74
  context: ReadonlyContext;
50
75
  }>;
51
76
  type InstrumentableRouter = {
52
77
  instrument(instrumentations: RouterInstrumentations): void;
53
78
  };
54
79
  type RouterInstrumentations = {
55
- navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
56
- fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
80
+ navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo, InstrumentationClientRouterResult>;
81
+ fetch?: InstrumentFunction<RouterFetchInstrumentationInfo, InstrumentationClientRouterResult>;
57
82
  };
58
83
  type RouterNavigationInstrumentationInfo = Readonly<{
59
84
  to: string | number;
@@ -76,11 +101,11 @@ type InstrumentableRequestHandler = {
76
101
  instrument(instrumentations: RequestHandlerInstrumentations): void;
77
102
  };
78
103
  type RequestHandlerInstrumentations = {
79
- request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
104
+ request?: InstrumentFunction<RequestHandlerInstrumentationInfo, InstrumentationServerHandlerResult>;
80
105
  };
81
106
  type RequestHandlerInstrumentationInfo = Readonly<{
82
107
  request: ReadonlyRequest;
83
108
  context: ReadonlyContext | undefined;
84
109
  }>;
85
110
  //#endregion
86
- export { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationHandlerResult, ServerInstrumentation };
111
+ export { ClientInstrumentation, InstrumentRequestHandlerFunction, InstrumentRouteFunction, InstrumentRouterFunction, InstrumentationClientRouterResult, InstrumentationHandlerResult, InstrumentationServerHandlerResult, ServerInstrumentation };