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.
- package/CHANGELOG.md +24 -0
- package/dist/development/dom-export.js +1 -1
- package/dist/development/index-react-server-client.js +1 -1
- package/dist/development/index-react-server.d.ts +35 -9
- package/dist/development/index-react-server.js +190 -157
- package/dist/development/index.d.ts +2 -2
- package/dist/development/index.js +1 -1
- package/dist/development/lib/actions.js +1 -1
- package/dist/development/lib/components.js +1 -1
- package/dist/development/lib/context.js +1 -1
- package/dist/development/lib/dom/dom.js +1 -1
- package/dist/development/lib/dom/lib.js +2 -2
- package/dist/development/lib/dom/server.js +1 -1
- package/dist/development/lib/dom/ssr/components.js +1 -1
- package/dist/development/lib/dom/ssr/data.js +1 -1
- package/dist/development/lib/dom/ssr/errorBoundaries.js +1 -1
- package/dist/development/lib/dom/ssr/fallback.js +1 -1
- package/dist/development/lib/dom/ssr/fog-of-war.js +1 -1
- package/dist/development/lib/dom/ssr/hydration.js +1 -1
- package/dist/development/lib/dom/ssr/invariant.js +1 -1
- package/dist/development/lib/dom/ssr/links.js +1 -1
- package/dist/development/lib/dom/ssr/markup.js +1 -1
- package/dist/development/lib/dom/ssr/routeModules.js +1 -1
- package/dist/development/lib/dom/ssr/routes-test-stub.js +1 -1
- package/dist/development/lib/dom/ssr/routes.js +1 -1
- package/dist/development/lib/dom/ssr/server.js +1 -1
- package/dist/development/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/development/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/development/lib/dom-export/hydrated-router.js +1 -1
- package/dist/development/lib/errors.js +1 -1
- package/dist/development/lib/hooks.d.ts +33 -6
- package/dist/development/lib/hooks.js +34 -7
- package/dist/development/lib/href.js +6 -3
- package/dist/development/lib/router/history.js +1 -1
- package/dist/development/lib/router/instrumentation.d.ts +33 -8
- package/dist/development/lib/router/instrumentation.js +176 -99
- package/dist/development/lib/router/router.js +20 -20
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.js +21 -4
- package/dist/development/lib/rsc/browser.js +1 -1
- package/dist/development/lib/rsc/errorBoundaries.js +1 -1
- package/dist/development/lib/rsc/html-stream/browser.js +1 -1
- package/dist/development/lib/rsc/html-stream/server.js +1 -1
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +3 -2
- package/dist/development/lib/rsc/server.ssr.js +1 -1
- package/dist/development/lib/server-runtime/cookies.js +1 -1
- package/dist/development/lib/server-runtime/crypto.js +1 -1
- package/dist/development/lib/server-runtime/data.js +1 -1
- package/dist/development/lib/server-runtime/dev.js +1 -1
- package/dist/development/lib/server-runtime/entry.js +1 -1
- package/dist/development/lib/server-runtime/errors.js +1 -1
- package/dist/development/lib/server-runtime/headers.js +1 -1
- package/dist/development/lib/server-runtime/invariant.js +1 -1
- package/dist/development/lib/server-runtime/mode.js +1 -1
- package/dist/development/lib/server-runtime/routeMatching.js +1 -1
- package/dist/development/lib/server-runtime/routes.js +1 -1
- package/dist/development/lib/server-runtime/server.js +12 -5
- package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/development/lib/server-runtime/sessions.js +1 -1
- package/dist/development/lib/server-runtime/single-fetch.js +1 -1
- package/dist/development/lib/server-runtime/urls.js +1 -1
- package/dist/development/lib/server-runtime/warnings.js +1 -1
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/development/vendor/turbo-stream-v2/utils.js +1 -1
- package/dist/production/dom-export.js +1 -1
- package/dist/production/index-react-server-client.js +1 -1
- package/dist/production/index-react-server.d.ts +35 -9
- package/dist/production/index-react-server.js +190 -157
- package/dist/production/index.d.ts +2 -2
- package/dist/production/index.js +1 -1
- package/dist/production/lib/actions.js +1 -1
- package/dist/production/lib/components.js +1 -1
- package/dist/production/lib/context.js +1 -1
- package/dist/production/lib/dom/dom.js +1 -1
- package/dist/production/lib/dom/lib.js +2 -2
- package/dist/production/lib/dom/server.js +1 -1
- package/dist/production/lib/dom/ssr/components.js +1 -1
- package/dist/production/lib/dom/ssr/data.js +1 -1
- package/dist/production/lib/dom/ssr/errorBoundaries.js +1 -1
- package/dist/production/lib/dom/ssr/fallback.js +1 -1
- package/dist/production/lib/dom/ssr/fog-of-war.js +1 -1
- package/dist/production/lib/dom/ssr/hydration.js +1 -1
- package/dist/production/lib/dom/ssr/invariant.js +1 -1
- package/dist/production/lib/dom/ssr/links.js +1 -1
- package/dist/production/lib/dom/ssr/markup.js +1 -1
- package/dist/production/lib/dom/ssr/routeModules.js +1 -1
- package/dist/production/lib/dom/ssr/routes-test-stub.js +1 -1
- package/dist/production/lib/dom/ssr/routes.js +1 -1
- package/dist/production/lib/dom/ssr/server.js +1 -1
- package/dist/production/lib/dom/ssr/single-fetch.js +1 -1
- package/dist/production/lib/dom-export/dom-router-provider.js +1 -1
- package/dist/production/lib/dom-export/hydrated-router.js +1 -1
- package/dist/production/lib/errors.js +1 -1
- package/dist/production/lib/hooks.d.ts +33 -6
- package/dist/production/lib/hooks.js +34 -7
- package/dist/production/lib/href.js +6 -3
- package/dist/production/lib/router/history.js +1 -1
- package/dist/production/lib/router/instrumentation.d.ts +33 -8
- package/dist/production/lib/router/instrumentation.js +176 -99
- package/dist/production/lib/router/router.js +20 -20
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.js +21 -4
- package/dist/production/lib/rsc/browser.js +1 -1
- package/dist/production/lib/rsc/errorBoundaries.js +1 -1
- package/dist/production/lib/rsc/html-stream/browser.js +1 -1
- package/dist/production/lib/rsc/html-stream/server.js +1 -1
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +3 -2
- package/dist/production/lib/rsc/server.ssr.js +1 -1
- package/dist/production/lib/server-runtime/cookies.js +1 -1
- package/dist/production/lib/server-runtime/crypto.js +1 -1
- package/dist/production/lib/server-runtime/data.js +1 -1
- package/dist/production/lib/server-runtime/dev.js +1 -1
- package/dist/production/lib/server-runtime/entry.js +1 -1
- package/dist/production/lib/server-runtime/errors.js +1 -1
- package/dist/production/lib/server-runtime/headers.js +1 -1
- package/dist/production/lib/server-runtime/invariant.js +1 -1
- package/dist/production/lib/server-runtime/mode.js +1 -1
- package/dist/production/lib/server-runtime/routeMatching.js +1 -1
- package/dist/production/lib/server-runtime/routes.js +1 -1
- package/dist/production/lib/server-runtime/server.js +12 -5
- package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +1 -1
- package/dist/production/lib/server-runtime/sessions.js +1 -1
- package/dist/production/lib/server-runtime/single-fetch.js +1 -1
- package/dist/production/lib/server-runtime/urls.js +1 -1
- package/dist/production/lib/server-runtime/warnings.js +1 -1
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/flatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +1 -1
- package/dist/production/vendor/turbo-stream-v2/utils.js +1 -1
- package/docs/explanation/hot-module-replacement.md +1 -1
- package/docs/how-to/data-strategy.md +1 -1
- package/docs/how-to/instrumentation.md +131 -26
- package/docs/start/framework/deploying.md +4 -0
- package/docs/upgrading/component-routes.md +2 -2
- package/docs/upgrading/future.md +33 -0
- package/docs/upgrading/router-provider.md +6 -6
- package/docs/upgrading/v7.md +39 -22
- package/package.json +1 -1
|
@@ -143,12 +143,16 @@ interface NavigateFunction {
|
|
|
143
143
|
* All properties are optional.
|
|
144
144
|
*
|
|
145
145
|
* ```tsx
|
|
146
|
-
* navigate(
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
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
|
|
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
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
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
|
|
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
|
|
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
|
}
|
|
@@ -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
|
-
|
|
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 };
|