react-router 8.1.0 → 8.3.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 +83 -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 +109 -19
- package/dist/development/index-react-server.js +176 -45
- 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.d.ts +24 -24
- package/dist/development/lib/dom/dom.js +25 -25
- package/dist/development/lib/dom/lib.d.ts +2 -1
- package/dist/development/lib/dom/lib.js +5 -4
- 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 +26 -21
- 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.d.ts +13 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +14 -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.d.ts +24 -8
- package/dist/development/lib/href.js +31 -11
- package/dist/development/lib/router/history.d.ts +6 -0
- package/dist/development/lib/router/history.js +7 -1
- package/dist/development/lib/router/instrumentation.js +1 -1
- package/dist/development/lib/router/router.js +2 -2
- package/dist/development/lib/router/url.js +1 -1
- package/dist/development/lib/router/utils.d.ts +12 -0
- package/dist/development/lib/router/utils.js +61 -5
- package/dist/development/lib/rsc/browser.js +34 -24
- 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 +29 -10
- package/dist/development/lib/rsc/route-modules.js +1 -1
- package/dist/development/lib/rsc/server.rsc.d.ts +8 -3
- package/dist/development/lib/rsc/server.ssr.d.ts +29 -6
- package/dist/development/lib/rsc/server.ssr.js +27 -12
- package/dist/development/lib/server-runtime/cookies.d.ts +28 -2
- package/dist/development/lib/server-runtime/cookies.js +17 -3
- 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.d.ts +12 -0
- package/dist/development/lib/server-runtime/server.js +13 -1
- package/dist/development/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +8 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +9 -1
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +10 -4
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +12 -6
- package/dist/development/lib/server-runtime/sessions.d.ts +31 -2
- package/dist/development/lib/server-runtime/sessions.js +20 -3
- 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 +109 -19
- package/dist/production/index-react-server.js +176 -45
- 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.d.ts +24 -24
- package/dist/production/lib/dom/dom.js +25 -25
- package/dist/production/lib/dom/lib.d.ts +2 -1
- package/dist/production/lib/dom/lib.js +5 -4
- 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 +26 -21
- 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.d.ts +13 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +14 -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.d.ts +24 -8
- package/dist/production/lib/href.js +31 -11
- package/dist/production/lib/router/history.d.ts +6 -0
- package/dist/production/lib/router/history.js +7 -1
- package/dist/production/lib/router/instrumentation.js +1 -1
- package/dist/production/lib/router/router.js +2 -2
- package/dist/production/lib/router/url.js +1 -1
- package/dist/production/lib/router/utils.d.ts +12 -0
- package/dist/production/lib/router/utils.js +61 -5
- package/dist/production/lib/rsc/browser.js +34 -24
- 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 +29 -10
- package/dist/production/lib/rsc/route-modules.js +1 -1
- package/dist/production/lib/rsc/server.rsc.d.ts +8 -3
- package/dist/production/lib/rsc/server.ssr.d.ts +29 -6
- package/dist/production/lib/rsc/server.ssr.js +27 -12
- package/dist/production/lib/server-runtime/cookies.d.ts +28 -2
- package/dist/production/lib/server-runtime/cookies.js +17 -3
- 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.d.ts +12 -0
- package/dist/production/lib/server-runtime/server.js +13 -1
- package/dist/production/lib/server-runtime/serverHandoff.js +1 -1
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +8 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +9 -1
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +10 -4
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +12 -6
- package/dist/production/lib/server-runtime/sessions.d.ts +31 -2
- package/dist/production/lib/server-runtime/sessions.js +20 -3
- 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/explanation/sessions-and-cookies.md +13 -13
- package/docs/explanation/state-management.md +2 -2
- package/docs/how-to/data-strategy.md +1 -1
- package/docs/how-to/presets.md +2 -2
- package/docs/how-to/react-server-components.md +53 -1
- package/docs/how-to/security.md +8 -1
- package/docs/how-to/server-bundles.md +2 -2
- package/docs/start/data/route-object.md +2 -2
- package/docs/start/data/routing.md +1 -1
- package/docs/start/framework/deploying.md +4 -0
- package/docs/start/framework/pending-ui.md +1 -1
- package/docs/start/framework/route-module.md +8 -8
- package/docs/start/framework/routing.md +1 -1
- package/docs/upgrading/component-routes.md +1 -1
- package/docs/upgrading/future.md +33 -0
- package/docs/upgrading/router-provider.md +5 -5
- package/docs/upgrading/v7.md +39 -22
- package/package.json +1 -1
|
@@ -5,6 +5,18 @@ import { ServerBuild } from "./build.js";
|
|
|
5
5
|
//#region lib/server-runtime/server.d.ts
|
|
6
6
|
type RequestHandler = (request: Request, loadContext?: RouterContextProvider) => Promise<Response>;
|
|
7
7
|
type CreateRequestHandlerFunction = (build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>), mode?: string) => RequestHandler;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a request handler for a React Router server build.
|
|
10
|
+
*
|
|
11
|
+
* This is a low-level API used by server adapters to translate incoming
|
|
12
|
+
* requests into React Router responses.
|
|
13
|
+
*
|
|
14
|
+
* @category Utils
|
|
15
|
+
* @param build The server build, or a function that resolves to the server
|
|
16
|
+
* build, used to handle requests.
|
|
17
|
+
* @param mode The mode in which the server build is running.
|
|
18
|
+
* @returns A request handler that returns a response for each incoming request.
|
|
19
|
+
*/
|
|
8
20
|
declare const createRequestHandler: CreateRequestHandlerFunction;
|
|
9
21
|
//#endregion
|
|
10
22
|
export { CreateRequestHandlerFunction, RequestHandler, createRequestHandler };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.
|
|
2
|
+
* react-router v8.3.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -137,6 +137,18 @@ function derive(build, mode) {
|
|
|
137
137
|
requestHandler
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Creates a request handler for a React Router server build.
|
|
142
|
+
*
|
|
143
|
+
* This is a low-level API used by server adapters to translate incoming
|
|
144
|
+
* requests into React Router responses.
|
|
145
|
+
*
|
|
146
|
+
* @category Utils
|
|
147
|
+
* @param build The server build, or a function that resolves to the server
|
|
148
|
+
* build, used to handle requests.
|
|
149
|
+
* @param mode The mode in which the server build is running.
|
|
150
|
+
* @returns A request handler that returns a response for each incoming request.
|
|
151
|
+
*/
|
|
140
152
|
const createRequestHandler = (build, mode) => {
|
|
141
153
|
let _build;
|
|
142
154
|
let serverMode;
|
|
@@ -17,6 +17,14 @@ interface CookieSessionStorageOptions {
|
|
|
17
17
|
* needed, and can help to simplify some load-balanced scenarios. However, it
|
|
18
18
|
* also has the limitation that serialized session data may not exceed the
|
|
19
19
|
* browser's maximum cookie size. Trade-offs!
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @category Utils
|
|
23
|
+
* @mode framework
|
|
24
|
+
* @mode data
|
|
25
|
+
* @param options Options for creating the cookie-backed session storage.
|
|
26
|
+
* @returns A {@link SessionStorage} object that stores all session data in its
|
|
27
|
+
* cookie.
|
|
20
28
|
*/
|
|
21
29
|
declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({
|
|
22
30
|
cookie: cookieArg
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.
|
|
2
|
+
* react-router v8.3.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -19,6 +19,14 @@ import { createSession, warnOnceAboutSigningSessionCookie } from "../sessions.js
|
|
|
19
19
|
* needed, and can help to simplify some load-balanced scenarios. However, it
|
|
20
20
|
* also has the limitation that serialized session data may not exceed the
|
|
21
21
|
* browser's maximum cookie size. Trade-offs!
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
* @category Utils
|
|
25
|
+
* @mode framework
|
|
26
|
+
* @mode data
|
|
27
|
+
* @param options Options for creating the cookie-backed session storage.
|
|
28
|
+
* @returns A {@link SessionStorage} object that stores all session data in its
|
|
29
|
+
* cookie.
|
|
22
30
|
*/
|
|
23
31
|
function createCookieSessionStorage({ cookie: cookieArg } = {}) {
|
|
24
32
|
let cookie = isCookie(cookieArg) ? cookieArg : createCookie(cookieArg?.name || "__session", cookieArg);
|
|
@@ -10,11 +10,17 @@ interface MemorySessionStorageOptions {
|
|
|
10
10
|
cookie?: SessionIdStorageStrategy["cookie"];
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Creates and returns a simple in-memory SessionStorage object
|
|
14
|
-
* for testing and as a reference implementation.
|
|
13
|
+
* Creates and returns a simple in-memory SessionStorage object.
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Intended for local development and testing. It does not scale beyond a single
|
|
16
|
+
* process, and all session data is lost when the server process stops/restarts.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
* @category Utils
|
|
20
|
+
* @mode framework
|
|
21
|
+
* @mode data
|
|
22
|
+
* @param options Options for creating the in-memory session storage.
|
|
23
|
+
* @returns A {@link SessionStorage} object that stores session data in memory.
|
|
18
24
|
*/
|
|
19
25
|
declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({
|
|
20
26
|
cookie
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.
|
|
2
|
+
* react-router v8.3.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -11,18 +11,24 @@
|
|
|
11
11
|
import { createSessionStorage } from "../sessions.js";
|
|
12
12
|
//#region lib/server-runtime/sessions/memoryStorage.ts
|
|
13
13
|
/**
|
|
14
|
-
* Creates and returns a simple in-memory SessionStorage object
|
|
15
|
-
* for testing and as a reference implementation.
|
|
14
|
+
* Creates and returns a simple in-memory SessionStorage object.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Intended for local development and testing. It does not scale beyond a single
|
|
17
|
+
* process, and all session data is lost when the server process stops/restarts.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
* @category Utils
|
|
21
|
+
* @mode framework
|
|
22
|
+
* @mode data
|
|
23
|
+
* @param options Options for creating the in-memory session storage.
|
|
24
|
+
* @returns A {@link SessionStorage} object that stores session data in memory.
|
|
19
25
|
*/
|
|
20
26
|
function createMemorySessionStorage({ cookie } = {}) {
|
|
21
27
|
let map = /* @__PURE__ */ new Map();
|
|
22
28
|
return createSessionStorage({
|
|
23
29
|
cookie,
|
|
24
30
|
async createData(data, expires) {
|
|
25
|
-
let id =
|
|
31
|
+
let id = crypto.randomUUID();
|
|
26
32
|
map.set(id, {
|
|
27
33
|
data,
|
|
28
34
|
expires
|
|
@@ -60,13 +60,37 @@ type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?
|
|
|
60
60
|
*
|
|
61
61
|
* Note: This function is typically not invoked directly by application code.
|
|
62
62
|
* Instead, use a `SessionStorage` object's `getSession` method.
|
|
63
|
+
*
|
|
64
|
+
* @category Utils
|
|
65
|
+
* @param initialData The initial data for the session.
|
|
66
|
+
* @param id The identifier for the session. Defaults to an empty string for a
|
|
67
|
+
* new session.
|
|
68
|
+
* @returns A new {@link Session} object.
|
|
63
69
|
*/
|
|
64
70
|
declare const createSession: CreateSessionFunction;
|
|
71
|
+
/**
|
|
72
|
+
* A function that determines whether a value is a React Router {@link Session}
|
|
73
|
+
* object.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
* @category Utils
|
|
77
|
+
* @mode framework
|
|
78
|
+
* @mode data
|
|
79
|
+
* @param object The value to check.
|
|
80
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
81
|
+
* otherwise, `false`.
|
|
82
|
+
*/
|
|
65
83
|
type IsSessionFunction = (object: any) => object is Session;
|
|
66
84
|
/**
|
|
67
|
-
* Returns true if
|
|
85
|
+
* Returns `true` if a value is a React Router {@link Session} object.
|
|
68
86
|
*
|
|
69
|
-
* @
|
|
87
|
+
* @public
|
|
88
|
+
* @category Utils
|
|
89
|
+
* @mode framework
|
|
90
|
+
* @mode data
|
|
91
|
+
* @param object The value to check.
|
|
92
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
93
|
+
* otherwise, `false`.
|
|
70
94
|
*/
|
|
71
95
|
declare const isSession: IsSessionFunction;
|
|
72
96
|
/**
|
|
@@ -133,6 +157,11 @@ interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
|
|
|
133
157
|
*
|
|
134
158
|
* Note: This is a low-level API that should only be used if none of the
|
|
135
159
|
* existing session storage options meet your requirements.
|
|
160
|
+
*
|
|
161
|
+
* @category Utils
|
|
162
|
+
* @param strategy The strategy used to store session identifiers and data.
|
|
163
|
+
* @returns A {@link SessionStorage} object that persists session data using the
|
|
164
|
+
* provided strategy.
|
|
136
165
|
*/
|
|
137
166
|
declare function createSessionStorage<Data = SessionData, FlashData = Data>({
|
|
138
167
|
cookie: cookieArg,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v8.
|
|
2
|
+
* react-router v8.3.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -19,6 +19,12 @@ function flash(name) {
|
|
|
19
19
|
*
|
|
20
20
|
* Note: This function is typically not invoked directly by application code.
|
|
21
21
|
* Instead, use a `SessionStorage` object's `getSession` method.
|
|
22
|
+
*
|
|
23
|
+
* @category Utils
|
|
24
|
+
* @param initialData The initial data for the session.
|
|
25
|
+
* @param id The identifier for the session. Defaults to an empty string for a
|
|
26
|
+
* new session.
|
|
27
|
+
* @returns A new {@link Session} object.
|
|
22
28
|
*/
|
|
23
29
|
const createSession = (initialData = {}, id = "") => {
|
|
24
30
|
let map = new Map(Object.entries(initialData));
|
|
@@ -53,9 +59,15 @@ const createSession = (initialData = {}, id = "") => {
|
|
|
53
59
|
};
|
|
54
60
|
};
|
|
55
61
|
/**
|
|
56
|
-
* Returns true if
|
|
62
|
+
* Returns `true` if a value is a React Router {@link Session} object.
|
|
57
63
|
*
|
|
58
|
-
* @
|
|
64
|
+
* @public
|
|
65
|
+
* @category Utils
|
|
66
|
+
* @mode framework
|
|
67
|
+
* @mode data
|
|
68
|
+
* @param object The value to check.
|
|
69
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
70
|
+
* otherwise, `false`.
|
|
59
71
|
*/
|
|
60
72
|
const isSession = (object) => {
|
|
61
73
|
return object != null && typeof object.id === "string" && typeof object.data !== "undefined" && typeof object.has === "function" && typeof object.get === "function" && typeof object.set === "function" && typeof object.flash === "function" && typeof object.unset === "function";
|
|
@@ -65,6 +77,11 @@ const isSession = (object) => {
|
|
|
65
77
|
*
|
|
66
78
|
* Note: This is a low-level API that should only be used if none of the
|
|
67
79
|
* existing session storage options meet your requirements.
|
|
80
|
+
*
|
|
81
|
+
* @category Utils
|
|
82
|
+
* @param strategy The strategy used to store session identifiers and data.
|
|
83
|
+
* @returns A {@link SessionStorage} object that persists session data using the
|
|
84
|
+
* provided strategy.
|
|
68
85
|
*/
|
|
69
86
|
function createSessionStorage({ cookie: cookieArg, createData, readData, updateData, deleteData }) {
|
|
70
87
|
let cookie = isCookie(cookieArg) ? cookieArg : createCookie(cookieArg?.name || "__session", cookieArg);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { CookieParseOptions, CookieParseOptions as CookieParseOptions$1, CookieSerializeOptions, CookieSerializeOptions as CookieSerializeOptions$1 } from "cookie-es";
|
|
4
4
|
import { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, unstable_HistoryRouter } from "react-router/internal/react-server-client";
|
|
5
|
+
import { ReactFormState } from "react-dom/client";
|
|
5
6
|
|
|
6
7
|
//#region lib/router/history.d.ts
|
|
7
8
|
/**
|
|
@@ -2317,14 +2318,14 @@ type RSCRenderPayload = {
|
|
|
2317
2318
|
type: "render";
|
|
2318
2319
|
actionData: Record<string, any> | null;
|
|
2319
2320
|
basename: string | undefined;
|
|
2321
|
+
clientVersion?: string;
|
|
2320
2322
|
errors: Record<string, any> | null;
|
|
2321
2323
|
loaderData: Record<string, any>;
|
|
2322
2324
|
location: Location;
|
|
2323
2325
|
routeDiscovery: RouteDiscovery;
|
|
2324
2326
|
matches: RSCRouteMatch[];
|
|
2325
2327
|
patches?: Promise<RSCRouteManifest[]>;
|
|
2326
|
-
|
|
2327
|
-
formState?: unknown;
|
|
2328
|
+
formState?: ReactFormState;
|
|
2328
2329
|
};
|
|
2329
2330
|
type RSCManifestPayload = {
|
|
2330
2331
|
type: "manifest";
|
|
@@ -2350,7 +2351,7 @@ type RSCMatch = {
|
|
|
2350
2351
|
payload: RSCPayload;
|
|
2351
2352
|
};
|
|
2352
2353
|
type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
|
|
2353
|
-
type DecodeFormStateFunction = (result: unknown, formData: FormData) =>
|
|
2354
|
+
type DecodeFormStateFunction = (result: unknown, formData: FormData) => Promise<ReactFormState | undefined>;
|
|
2354
2355
|
type DecodeReplyFunction = (reply: FormData | string, options: {
|
|
2355
2356
|
temporaryReferences: unknown;
|
|
2356
2357
|
}) => Promise<unknown[]>;
|
|
@@ -2420,6 +2421,8 @@ type RouteDiscovery = {
|
|
|
2420
2421
|
* encoding the {@link unstable_RSCPayload}.
|
|
2421
2422
|
* @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
|
|
2422
2423
|
* `loadServerAction` function, used to load a server action by ID.
|
|
2424
|
+
* @param opts.clientVersion A version derived from the client build output used
|
|
2425
|
+
* to detect stale clients during lazy route discovery.
|
|
2423
2426
|
* @param opts.onError An optional error handler that will be called with any
|
|
2424
2427
|
* errors that occur during the request processing.
|
|
2425
2428
|
* @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
@@ -2443,6 +2446,7 @@ declare function matchRSCServerRequest({
|
|
|
2443
2446
|
loadServerAction,
|
|
2444
2447
|
decodeAction,
|
|
2445
2448
|
decodeFormState,
|
|
2449
|
+
clientVersion,
|
|
2446
2450
|
onError,
|
|
2447
2451
|
request,
|
|
2448
2452
|
routes,
|
|
@@ -2456,6 +2460,7 @@ declare function matchRSCServerRequest({
|
|
|
2456
2460
|
decodeFormState?: DecodeFormStateFunction;
|
|
2457
2461
|
requestContext?: RouterContextProvider;
|
|
2458
2462
|
loadServerAction?: LoadServerActionFunction;
|
|
2463
|
+
clientVersion?: string;
|
|
2459
2464
|
onError?: (error: unknown) => void;
|
|
2460
2465
|
request: Request;
|
|
2461
2466
|
routes: RSCRouteConfigEntry[];
|
|
@@ -2489,14 +2494,30 @@ type Pages = Register extends {
|
|
|
2489
2494
|
type Args = { [K in keyof Pages]: ToArgs<Pages[K]["params"]> };
|
|
2490
2495
|
type ToArgs<Params extends Record<string, string | undefined>> = Equal<Params, {}> extends true ? [] : Partial<Params> extends Params ? [Params] | [] : [Params];
|
|
2491
2496
|
/**
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2497
|
+
* Returns a resolved URL path for the specified route.
|
|
2498
|
+
*
|
|
2499
|
+
* Param values are percent-encoded for use in a path segment: characters that
|
|
2500
|
+
* would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
|
2501
|
+
* are escaped, while characters that RFC 3986 allows literally in a path
|
|
2502
|
+
* segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
|
|
2503
|
+
* encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
|
|
2504
|
+
* delimiters and must be escaped. Splat (`*`) values are encoded per segment,
|
|
2505
|
+
* preserving `/` separators.
|
|
2506
|
+
*
|
|
2507
|
+
* See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
|
|
2508
|
+
*
|
|
2509
|
+
* @example
|
|
2510
|
+
* const h = href("/:lang?/about", { lang: "en" })
|
|
2511
|
+
* // -> `/en/about`
|
|
2512
|
+
*
|
|
2513
|
+
* <Link to={href("/products/:id", { id: "abc123" })} />
|
|
2514
|
+
*
|
|
2515
|
+
* @public
|
|
2516
|
+
* @category Utils
|
|
2517
|
+
* @mode framework
|
|
2518
|
+
* @param path The route path to resolve
|
|
2519
|
+
* @param args The route params to use when resolving the path
|
|
2520
|
+
* @returns The resolved URL path
|
|
2500
2521
|
*/
|
|
2501
2522
|
declare function href<Path extends keyof Args>(path: Path, ...args: Args[Path]): string;
|
|
2502
2523
|
//#endregion
|
|
@@ -2552,13 +2573,39 @@ interface Cookie {
|
|
|
2552
2573
|
}
|
|
2553
2574
|
/**
|
|
2554
2575
|
* Creates a logical container for managing a browser cookie from the server.
|
|
2576
|
+
*
|
|
2577
|
+
* @public
|
|
2578
|
+
* @category Utils
|
|
2579
|
+
* @mode framework
|
|
2580
|
+
* @mode data
|
|
2581
|
+
* @param name The name of the cookie.
|
|
2582
|
+
* @param cookieOptions Options for parsing and serializing the cookie.
|
|
2583
|
+
* @returns A {@link Cookie} object for parsing and serializing the cookie.
|
|
2555
2584
|
*/
|
|
2556
2585
|
declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
|
|
2586
|
+
/**
|
|
2587
|
+
* A function that determines whether a value is a React Router {@link Cookie}
|
|
2588
|
+
* object.
|
|
2589
|
+
*
|
|
2590
|
+
* @public
|
|
2591
|
+
* @category Utils
|
|
2592
|
+
* @mode framework
|
|
2593
|
+
* @mode data
|
|
2594
|
+
* @param object The value to check.
|
|
2595
|
+
* @returns `true` if the value is a React Router {@link Cookie} object;
|
|
2596
|
+
* otherwise, `false`.
|
|
2597
|
+
*/
|
|
2557
2598
|
type IsCookieFunction = (object: any) => object is Cookie;
|
|
2558
2599
|
/**
|
|
2559
|
-
* Returns true if
|
|
2600
|
+
* Returns `true` if a value is a React Router {@link Cookie} object.
|
|
2560
2601
|
*
|
|
2561
|
-
* @
|
|
2602
|
+
* @public
|
|
2603
|
+
* @category Utils
|
|
2604
|
+
* @mode framework
|
|
2605
|
+
* @mode data
|
|
2606
|
+
* @param object The value to check.
|
|
2607
|
+
* @returns `true` if the value is a React Router {@link Cookie} object;
|
|
2608
|
+
* otherwise, `false`.
|
|
2562
2609
|
*/
|
|
2563
2610
|
declare const isCookie: IsCookieFunction;
|
|
2564
2611
|
//#endregion
|
|
@@ -2620,13 +2667,37 @@ type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?
|
|
|
2620
2667
|
*
|
|
2621
2668
|
* Note: This function is typically not invoked directly by application code.
|
|
2622
2669
|
* Instead, use a `SessionStorage` object's `getSession` method.
|
|
2670
|
+
*
|
|
2671
|
+
* @category Utils
|
|
2672
|
+
* @param initialData The initial data for the session.
|
|
2673
|
+
* @param id The identifier for the session. Defaults to an empty string for a
|
|
2674
|
+
* new session.
|
|
2675
|
+
* @returns A new {@link Session} object.
|
|
2623
2676
|
*/
|
|
2624
2677
|
declare const createSession: CreateSessionFunction;
|
|
2678
|
+
/**
|
|
2679
|
+
* A function that determines whether a value is a React Router {@link Session}
|
|
2680
|
+
* object.
|
|
2681
|
+
*
|
|
2682
|
+
* @public
|
|
2683
|
+
* @category Utils
|
|
2684
|
+
* @mode framework
|
|
2685
|
+
* @mode data
|
|
2686
|
+
* @param object The value to check.
|
|
2687
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
2688
|
+
* otherwise, `false`.
|
|
2689
|
+
*/
|
|
2625
2690
|
type IsSessionFunction = (object: any) => object is Session;
|
|
2626
2691
|
/**
|
|
2627
|
-
* Returns true if
|
|
2692
|
+
* Returns `true` if a value is a React Router {@link Session} object.
|
|
2628
2693
|
*
|
|
2629
|
-
* @
|
|
2694
|
+
* @public
|
|
2695
|
+
* @category Utils
|
|
2696
|
+
* @mode framework
|
|
2697
|
+
* @mode data
|
|
2698
|
+
* @param object The value to check.
|
|
2699
|
+
* @returns `true` if the value is a React Router {@link Session} object;
|
|
2700
|
+
* otherwise, `false`.
|
|
2630
2701
|
*/
|
|
2631
2702
|
declare const isSession: IsSessionFunction;
|
|
2632
2703
|
/**
|
|
@@ -2693,6 +2764,11 @@ interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
|
|
|
2693
2764
|
*
|
|
2694
2765
|
* Note: This is a low-level API that should only be used if none of the
|
|
2695
2766
|
* existing session storage options meet your requirements.
|
|
2767
|
+
*
|
|
2768
|
+
* @category Utils
|
|
2769
|
+
* @param strategy The strategy used to store session identifiers and data.
|
|
2770
|
+
* @returns A {@link SessionStorage} object that persists session data using the
|
|
2771
|
+
* provided strategy.
|
|
2696
2772
|
*/
|
|
2697
2773
|
declare function createSessionStorage<Data = SessionData, FlashData = Data>({
|
|
2698
2774
|
cookie: cookieArg,
|
|
@@ -2718,6 +2794,14 @@ interface CookieSessionStorageOptions {
|
|
|
2718
2794
|
* needed, and can help to simplify some load-balanced scenarios. However, it
|
|
2719
2795
|
* also has the limitation that serialized session data may not exceed the
|
|
2720
2796
|
* browser's maximum cookie size. Trade-offs!
|
|
2797
|
+
*
|
|
2798
|
+
* @public
|
|
2799
|
+
* @category Utils
|
|
2800
|
+
* @mode framework
|
|
2801
|
+
* @mode data
|
|
2802
|
+
* @param options Options for creating the cookie-backed session storage.
|
|
2803
|
+
* @returns A {@link SessionStorage} object that stores all session data in its
|
|
2804
|
+
* cookie.
|
|
2721
2805
|
*/
|
|
2722
2806
|
declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({
|
|
2723
2807
|
cookie: cookieArg
|
|
@@ -2732,11 +2816,17 @@ interface MemorySessionStorageOptions {
|
|
|
2732
2816
|
cookie?: SessionIdStorageStrategy["cookie"];
|
|
2733
2817
|
}
|
|
2734
2818
|
/**
|
|
2735
|
-
* Creates and returns a simple in-memory SessionStorage object
|
|
2736
|
-
*
|
|
2819
|
+
* Creates and returns a simple in-memory SessionStorage object.
|
|
2820
|
+
*
|
|
2821
|
+
* Intended for local development and testing. It does not scale beyond a single
|
|
2822
|
+
* process, and all session data is lost when the server process stops/restarts.
|
|
2737
2823
|
*
|
|
2738
|
-
*
|
|
2739
|
-
*
|
|
2824
|
+
* @public
|
|
2825
|
+
* @category Utils
|
|
2826
|
+
* @mode framework
|
|
2827
|
+
* @mode data
|
|
2828
|
+
* @param options Options for creating the in-memory session storage.
|
|
2829
|
+
* @returns A {@link SessionStorage} object that stores session data in memory.
|
|
2740
2830
|
*/
|
|
2741
2831
|
declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({
|
|
2742
2832
|
cookie
|