react-router 7.9.4 → 7.9.6

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 (74) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/development/browser-BbBXFHbO.d.ts +310 -0
  3. package/dist/development/browser-C07r42Tt.d.mts +310 -0
  4. package/dist/development/{chunk-OIYGIGL5.mjs → chunk-4WY6JWTD.mjs} +458 -43
  5. package/dist/development/{chunk-DI2QHYMJ.js → chunk-AMVS5XVJ.js} +1314 -138
  6. package/dist/development/{chunk-WY5IRSCW.mjs → chunk-G3INQAYP.mjs} +197 -857
  7. package/dist/development/chunk-O4JVZSOY.js +1310 -0
  8. package/dist/development/chunk-PZWDWJAY.js +188 -0
  9. package/dist/development/dom-export.d.mts +103 -6
  10. package/dist/development/dom-export.d.ts +103 -4
  11. package/dist/development/dom-export.js +708 -20
  12. package/dist/development/dom-export.mjs +692 -11
  13. package/dist/{production/index-react-server-client-BbRcBjrA.d.ts → development/index-react-server-client-Da3kmxNd.d.ts} +195 -135
  14. package/dist/{production/index-react-server-client-BIz4AUNd.d.mts → development/index-react-server-client-rcoGPJhU.d.mts} +137 -78
  15. package/dist/development/index-react-server-client.d.mts +2 -3
  16. package/dist/development/index-react-server-client.d.ts +2 -2
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.d.mts +107 -3
  20. package/dist/development/index-react-server.d.ts +107 -3
  21. package/dist/development/index-react-server.js +259 -13
  22. package/dist/development/index-react-server.mjs +259 -13
  23. package/dist/development/index.d.mts +14 -320
  24. package/dist/development/index.d.ts +14 -362
  25. package/dist/development/index.js +146 -962
  26. package/dist/development/index.mjs +3 -9
  27. package/dist/development/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  28. package/dist/development/lib/types/internal.d.mts +2 -3
  29. package/dist/development/lib/types/internal.d.ts +2 -2
  30. package/dist/development/lib/types/internal.js +1 -1
  31. package/dist/development/lib/types/internal.mjs +1 -1
  32. package/dist/{production/register-C34pU-in.d.ts → development/register-BpU9rFBJ.d.ts} +1 -1
  33. package/dist/development/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  34. package/dist/{production/context-DSyS5mLj.d.mts → development/router-CAvh_Drx.d.mts} +1877 -1254
  35. package/dist/production/browser-BbBXFHbO.d.ts +310 -0
  36. package/dist/production/browser-C07r42Tt.d.mts +310 -0
  37. package/dist/production/{chunk-4E5LHRQP.js → chunk-EAIF67OW.js} +1314 -138
  38. package/dist/production/{chunk-FR6HSPLK.mjs → chunk-FDUMZGKM.mjs} +197 -857
  39. package/dist/production/{chunk-3TADTUL4.mjs → chunk-FUSXQSWG.mjs} +458 -43
  40. package/dist/production/chunk-G5A35OQU.js +188 -0
  41. package/dist/production/chunk-QN64DHI4.js +1310 -0
  42. package/dist/production/dom-export.d.mts +103 -6
  43. package/dist/production/dom-export.d.ts +103 -4
  44. package/dist/production/dom-export.js +708 -20
  45. package/dist/production/dom-export.mjs +692 -11
  46. package/dist/{development/index-react-server-client-BIz4AUNd.d.mts → production/index-react-server-client-Da3kmxNd.d.ts} +137 -78
  47. package/dist/{development/index-react-server-client-BbRcBjrA.d.ts → production/index-react-server-client-rcoGPJhU.d.mts} +195 -135
  48. package/dist/production/index-react-server-client.d.mts +2 -3
  49. package/dist/production/index-react-server-client.d.ts +2 -2
  50. package/dist/production/index-react-server-client.js +4 -4
  51. package/dist/production/index-react-server-client.mjs +2 -2
  52. package/dist/production/index-react-server.d.mts +107 -3
  53. package/dist/production/index-react-server.d.ts +107 -3
  54. package/dist/production/index-react-server.js +259 -13
  55. package/dist/production/index-react-server.mjs +259 -13
  56. package/dist/production/index.d.mts +14 -320
  57. package/dist/production/index.d.ts +14 -362
  58. package/dist/production/index.js +146 -962
  59. package/dist/production/index.mjs +3 -9
  60. package/dist/production/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  61. package/dist/production/lib/types/internal.d.mts +2 -3
  62. package/dist/production/lib/types/internal.d.ts +2 -2
  63. package/dist/production/lib/types/internal.js +1 -1
  64. package/dist/production/lib/types/internal.mjs +1 -1
  65. package/dist/{development/register-C34pU-in.d.ts → production/register-BpU9rFBJ.d.ts} +1 -1
  66. package/dist/production/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  67. package/dist/{development/context-DSyS5mLj.d.mts → production/router-CAvh_Drx.d.mts} +1877 -1254
  68. package/package.json +1 -1
  69. package/dist/development/browser-z32v5KVN.d.mts +0 -46
  70. package/dist/development/chunk-72XNTZCV.js +0 -2089
  71. package/dist/development/route-data-DZQOUSqV.d.mts +0 -473
  72. package/dist/production/browser-z32v5KVN.d.mts +0 -46
  73. package/dist/production/chunk-WNLQ53P5.js +0 -2089
  74. package/dist/production/route-data-DZQOUSqV.d.mts +0 -473
package/CHANGELOG.md CHANGED
@@ -1,5 +1,75 @@
1
1
  # `react-router`
2
2
 
3
+ ## 7.9.6
4
+
5
+ ### Patch Changes
6
+
7
+ - \[UNSTABLE] Add `location`/`params` as arguments to client-side `unstable_onError` to permit enhanced error reporting. ([#14509](https://github.com/remix-run/react-router/pull/14509))
8
+
9
+ ⚠️ This is a breaking change if you've already adopted `unstable_onError`. The second `errorInfo` parameter is now an object with `location` and `params`:
10
+
11
+ ```tsx
12
+ // Before
13
+ function errorHandler(error: unknown, errorInfo?: React.errorInfo) {
14
+ /*...*/
15
+ }
16
+
17
+ // After
18
+ function errorHandler(
19
+ error: unknown,
20
+ info: {
21
+ location: Location;
22
+ params: Params;
23
+ errorInfo?: React.ErrorInfo;
24
+ },
25
+ ) {
26
+ /*...*/
27
+ }
28
+ ```
29
+
30
+ - Properly handle ancestor thrown middleware errors before `next()` on fetcher submissions ([#14517](https://github.com/remix-run/react-router/pull/14517))
31
+
32
+ - Fix issue with splat routes interfering with multiple calls to patchRoutesOnNavigation ([#14487](https://github.com/remix-run/react-router/pull/14487))
33
+
34
+ - Normalize double-slashes in `resolvePath` ([#14529](https://github.com/remix-run/react-router/pull/14529))
35
+
36
+ ## 7.9.5
37
+
38
+ ### Patch Changes
39
+
40
+ - Move RSCHydratedRouter and utils to `/dom` export. ([#14457](https://github.com/remix-run/react-router/pull/14457))
41
+
42
+ - useRoute: return type-safe `handle` ([#14462](https://github.com/remix-run/react-router/pull/14462))
43
+
44
+ For example:
45
+
46
+ ```ts
47
+ // app/routes/admin.tsx
48
+ const handle = { hello: "world" };
49
+ ```
50
+
51
+ ```ts
52
+ // app/routes/some-other-route.tsx
53
+ export default function Component() {
54
+ const admin = useRoute("routes/admin");
55
+ if (!admin) throw new Error("Not nested within 'routes/admin'");
56
+ console.log(admin.handle);
57
+ // ^? { hello: string }
58
+ }
59
+ ```
60
+
61
+ - Ensure action handlers run for routes with middleware even if no loader is present ([#14443](https://github.com/remix-run/react-router/pull/14443))
62
+
63
+ - Add `unstable_instrumentations` API to allow users to add observablity to their apps by instrumenting route loaders, actions, middlewares, lazy, as well as server-side request handlers and client side navigations/fetches ([#14412](https://github.com/remix-run/react-router/pull/14412))
64
+
65
+ - Framework Mode:
66
+ - `entry.server.tsx`: `export const unstable_instrumentations = [...]`
67
+ - `entry.client.tsx`: `<HydratedRouter unstable_instrumentations={[...]} />`
68
+ - Data Mode
69
+ - `createBrowserRouter(routes, { unstable_instrumentations: [...] })`
70
+
71
+ This also adds a new `unstable_pattern` parameter to loaders/actions/middleware which contains the un-interpolated route pattern (i.e., `/blog/:slug`) which is useful for aggregating performance metrics by route
72
+
3
73
  ## 7.9.4
4
74
 
5
75
  ### Patch Changes
@@ -0,0 +1,310 @@
1
+ import * as React from 'react';
2
+ import { L as Location, C as ClientActionFunction, a as ClientLoaderFunction, b as LinksFunction, M as MetaFunction, S as ShouldRevalidateFunction, P as Params, c as RouterContextProvider, A as ActionFunction, H as HeadersFunction, d as LoaderFunction, e as RouterInit } from './instrumentation-Unc20tLk.js';
3
+
4
+ type RSCRouteConfigEntryBase = {
5
+ action?: ActionFunction;
6
+ clientAction?: ClientActionFunction;
7
+ clientLoader?: ClientLoaderFunction;
8
+ ErrorBoundary?: React.ComponentType<any>;
9
+ handle?: any;
10
+ headers?: HeadersFunction;
11
+ HydrateFallback?: React.ComponentType<any>;
12
+ Layout?: React.ComponentType<any>;
13
+ links?: LinksFunction;
14
+ loader?: LoaderFunction;
15
+ meta?: MetaFunction;
16
+ shouldRevalidate?: ShouldRevalidateFunction;
17
+ };
18
+ type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
19
+ id: string;
20
+ path?: string;
21
+ Component?: React.ComponentType<any>;
22
+ lazy?: () => Promise<RSCRouteConfigEntryBase & ({
23
+ default?: React.ComponentType<any>;
24
+ Component?: never;
25
+ } | {
26
+ default?: never;
27
+ Component?: React.ComponentType<any>;
28
+ })>;
29
+ } & ({
30
+ index: true;
31
+ } | {
32
+ children?: RSCRouteConfigEntry[];
33
+ });
34
+ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
35
+ type RSCRouteManifest = {
36
+ clientAction?: ClientActionFunction;
37
+ clientLoader?: ClientLoaderFunction;
38
+ element?: React.ReactElement | false;
39
+ errorElement?: React.ReactElement;
40
+ handle?: any;
41
+ hasAction: boolean;
42
+ hasComponent: boolean;
43
+ hasErrorBoundary: boolean;
44
+ hasLoader: boolean;
45
+ hydrateFallbackElement?: React.ReactElement;
46
+ id: string;
47
+ index?: boolean;
48
+ links?: LinksFunction;
49
+ meta?: MetaFunction;
50
+ parentId?: string;
51
+ path?: string;
52
+ shouldRevalidate?: ShouldRevalidateFunction;
53
+ };
54
+ type RSCRouteMatch = RSCRouteManifest & {
55
+ params: Params;
56
+ pathname: string;
57
+ pathnameBase: string;
58
+ };
59
+ type RSCRenderPayload = {
60
+ type: "render";
61
+ actionData: Record<string, any> | null;
62
+ basename: string | undefined;
63
+ errors: Record<string, any> | null;
64
+ loaderData: Record<string, any>;
65
+ location: Location;
66
+ matches: RSCRouteMatch[];
67
+ patches?: RSCRouteManifest[];
68
+ nonce?: string;
69
+ formState?: unknown;
70
+ };
71
+ type RSCManifestPayload = {
72
+ type: "manifest";
73
+ patches: RSCRouteManifest[];
74
+ };
75
+ type RSCActionPayload = {
76
+ type: "action";
77
+ actionResult: Promise<unknown>;
78
+ rerender?: Promise<RSCRenderPayload | RSCRedirectPayload>;
79
+ };
80
+ type RSCRedirectPayload = {
81
+ type: "redirect";
82
+ status: number;
83
+ location: string;
84
+ replace: boolean;
85
+ reload: boolean;
86
+ actionResult?: Promise<unknown>;
87
+ };
88
+ type RSCPayload = RSCRenderPayload | RSCManifestPayload | RSCActionPayload | RSCRedirectPayload;
89
+ type RSCMatch = {
90
+ statusCode: number;
91
+ headers: Headers;
92
+ payload: RSCPayload;
93
+ };
94
+ type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
95
+ type DecodeFormStateFunction = (result: unknown, formData: FormData) => unknown;
96
+ type DecodeReplyFunction = (reply: FormData | string, { temporaryReferences }: {
97
+ temporaryReferences: unknown;
98
+ }) => Promise<unknown[]>;
99
+ type LoadServerActionFunction = (id: string) => Promise<Function>;
100
+ /**
101
+ * Matches the given routes to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
102
+ * and returns an [RSC](https://react.dev/reference/rsc/server-components)
103
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
104
+ * encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
105
+ * enabled client router.
106
+ *
107
+ * @example
108
+ * import {
109
+ * createTemporaryReferenceSet,
110
+ * decodeAction,
111
+ * decodeReply,
112
+ * loadServerAction,
113
+ * renderToReadableStream,
114
+ * } from "@vitejs/plugin-rsc/rsc";
115
+ * import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
116
+ *
117
+ * matchRSCServerRequest({
118
+ * createTemporaryReferenceSet,
119
+ * decodeAction,
120
+ * decodeFormState,
121
+ * decodeReply,
122
+ * loadServerAction,
123
+ * request,
124
+ * routes: routes(),
125
+ * generateResponse(match) {
126
+ * return new Response(
127
+ * renderToReadableStream(match.payload),
128
+ * {
129
+ * status: match.statusCode,
130
+ * headers: match.headers,
131
+ * }
132
+ * );
133
+ * },
134
+ * });
135
+ *
136
+ * @name unstable_matchRSCServerRequest
137
+ * @public
138
+ * @category RSC
139
+ * @mode data
140
+ * @param opts Options
141
+ * @param opts.basename The basename to use when matching the request.
142
+ * @param opts.createTemporaryReferenceSet A function that returns a temporary
143
+ * reference set for the request, used to track temporary references in the [RSC](https://react.dev/reference/rsc/server-components)
144
+ * stream.
145
+ * @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
146
+ * function, responsible for loading a server action.
147
+ * @param opts.decodeFormState A function responsible for decoding form state for
148
+ * progressively enhanceable forms with React's [`useActionState`](https://react.dev/reference/react/useActionState)
149
+ * using your `react-server-dom-xyz/server`'s `decodeFormState`.
150
+ * @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
151
+ * function, used to decode the server function's arguments and bind them to the
152
+ * implementation for invocation by the router.
153
+ * @param opts.generateResponse A function responsible for using your
154
+ * `renderToReadableStream` to generate a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
155
+ * encoding the {@link unstable_RSCPayload}.
156
+ * @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
157
+ * `loadServerAction` function, used to load a server action by ID.
158
+ * @param opts.onError An optional error handler that will be called with any
159
+ * errors that occur during the request processing.
160
+ * @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
161
+ * to match against.
162
+ * @param opts.requestContext An instance of {@link RouterContextProvider}
163
+ * that should be created per request, to be passed to [`action`](../../start/data/route-object#action)s,
164
+ * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
165
+ * @param opts.routes Your {@link unstable_RSCRouteConfigEntry | route definitions}.
166
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
167
+ * that contains the [RSC](https://react.dev/reference/rsc/server-components)
168
+ * data for hydration.
169
+ */
170
+ declare function matchRSCServerRequest({ createTemporaryReferenceSet, basename, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
171
+ createTemporaryReferenceSet: () => unknown;
172
+ basename?: string;
173
+ decodeReply?: DecodeReplyFunction;
174
+ decodeAction?: DecodeActionFunction;
175
+ decodeFormState?: DecodeFormStateFunction;
176
+ requestContext?: RouterContextProvider;
177
+ loadServerAction?: LoadServerActionFunction;
178
+ onError?: (error: unknown) => void;
179
+ request: Request;
180
+ routes: RSCRouteConfigEntry[];
181
+ generateResponse: (match: RSCMatch, { temporaryReferences, }: {
182
+ temporaryReferences: unknown;
183
+ }) => Response;
184
+ }): Promise<Response>;
185
+
186
+ type BrowserCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>, { temporaryReferences, }: {
187
+ temporaryReferences: unknown;
188
+ }) => Promise<unknown>;
189
+ type EncodeReplyFunction = (args: unknown[], options: {
190
+ temporaryReferences: unknown;
191
+ }) => Promise<BodyInit>;
192
+ /**
193
+ * Create a React `callServer` implementation for React Router.
194
+ *
195
+ * @example
196
+ * import {
197
+ * createFromReadableStream,
198
+ * createTemporaryReferenceSet,
199
+ * encodeReply,
200
+ * setServerCallback,
201
+ * } from "@vitejs/plugin-rsc/browser";
202
+ * import { unstable_createCallServer as createCallServer } from "react-router";
203
+ *
204
+ * setServerCallback(
205
+ * createCallServer({
206
+ * createFromReadableStream,
207
+ * createTemporaryReferenceSet,
208
+ * encodeReply,
209
+ * })
210
+ * );
211
+ *
212
+ * @name unstable_createCallServer
213
+ * @public
214
+ * @category RSC
215
+ * @mode data
216
+ * @param opts Options
217
+ * @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
218
+ * `createFromReadableStream`. Used to decode payloads from the server.
219
+ * @param opts.createTemporaryReferenceSet A function that creates a temporary
220
+ * reference set for the [RSC](https://react.dev/reference/rsc/server-components)
221
+ * payload.
222
+ * @param opts.encodeReply Your `react-server-dom-xyz/client`'s `encodeReply`.
223
+ * Used when sending payloads to the server.
224
+ * @param opts.fetch Optional [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
225
+ * implementation. Defaults to global [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch).
226
+ * @returns A function that can be used to call server actions.
227
+ */
228
+ declare function createCallServer({ createFromReadableStream, createTemporaryReferenceSet, encodeReply, fetch: fetchImplementation, }: {
229
+ createFromReadableStream: BrowserCreateFromReadableStreamFunction;
230
+ createTemporaryReferenceSet: () => unknown;
231
+ encodeReply: EncodeReplyFunction;
232
+ fetch?: (request: Request) => Promise<Response>;
233
+ }): (id: string, args: unknown[]) => Promise<unknown>;
234
+ /**
235
+ * Props for the {@link unstable_RSCHydratedRouter} component.
236
+ *
237
+ * @name unstable_RSCHydratedRouterProps
238
+ * @category Types
239
+ */
240
+ interface RSCHydratedRouterProps {
241
+ /**
242
+ * Your `react-server-dom-xyz/client`'s `createFromReadableStream` function,
243
+ * used to decode payloads from the server.
244
+ */
245
+ createFromReadableStream: BrowserCreateFromReadableStreamFunction;
246
+ /**
247
+ * Optional fetch implementation. Defaults to global [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch).
248
+ */
249
+ fetch?: (request: Request) => Promise<Response>;
250
+ /**
251
+ * The decoded {@link unstable_RSCPayload} to hydrate.
252
+ */
253
+ payload: RSCPayload;
254
+ /**
255
+ * `"eager"` or `"lazy"` - Determines if links are eagerly discovered, or
256
+ * delayed until clicked.
257
+ */
258
+ routeDiscovery?: "eager" | "lazy";
259
+ /**
260
+ * A function that returns an {@link RouterContextProvider} instance
261
+ * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
262
+ * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
263
+ * This function is called to generate a fresh `context` instance on each
264
+ * navigation or fetcher call.
265
+ */
266
+ getContext?: RouterInit["getContext"];
267
+ }
268
+ /**
269
+ * Hydrates a server rendered {@link unstable_RSCPayload} in the browser.
270
+ *
271
+ * @example
272
+ * import { startTransition, StrictMode } from "react";
273
+ * import { hydrateRoot } from "react-dom/client";
274
+ * import {
275
+ * unstable_getRSCStream as getRSCStream,
276
+ * unstable_RSCHydratedRouter as RSCHydratedRouter,
277
+ * } from "react-router";
278
+ * import type { unstable_RSCPayload as RSCPayload } from "react-router";
279
+ *
280
+ * createFromReadableStream(getRSCStream()).then((payload) =>
281
+ * startTransition(async () => {
282
+ * hydrateRoot(
283
+ * document,
284
+ * <StrictMode>
285
+ * <RSCHydratedRouter
286
+ * createFromReadableStream={createFromReadableStream}
287
+ * payload={payload}
288
+ * />
289
+ * </StrictMode>,
290
+ * { formState: await getFormState(payload) },
291
+ * );
292
+ * }),
293
+ * );
294
+ *
295
+ * @name unstable_RSCHydratedRouter
296
+ * @public
297
+ * @category RSC
298
+ * @mode data
299
+ * @param props Props
300
+ * @param {unstable_RSCHydratedRouterProps.createFromReadableStream} props.createFromReadableStream n/a
301
+ * @param {unstable_RSCHydratedRouterProps.fetch} props.fetch n/a
302
+ * @param {unstable_RSCHydratedRouterProps.getContext} props.getContext n/a
303
+ * @param {unstable_RSCHydratedRouterProps.payload} props.payload n/a
304
+ * @param {unstable_RSCHydratedRouterProps.routeDiscovery} props.routeDiscovery n/a
305
+ * @returns A hydrated {@link DataRouter} that can be used to navigate and
306
+ * render routes.
307
+ */
308
+ declare function RSCHydratedRouter({ createFromReadableStream, fetch: fetchImplementation, payload, routeDiscovery, getContext, }: RSCHydratedRouterProps): React.JSX.Element;
309
+
310
+ export { type BrowserCreateFromReadableStreamFunction as B, type DecodeActionFunction as D, type EncodeReplyFunction as E, type LoadServerActionFunction as L, RSCHydratedRouter as R, type DecodeFormStateFunction as a, type DecodeReplyFunction as b, createCallServer as c, type RSCManifestPayload as d, type RSCPayload as e, type RSCRenderPayload as f, type RSCHydratedRouterProps as g, type RSCMatch as h, type RSCRouteManifest as i, type RSCRouteMatch as j, type RSCRouteConfigEntry as k, type RSCRouteConfig as l, matchRSCServerRequest as m };
@@ -0,0 +1,310 @@
1
+ import * as React from 'react';
2
+ import { L as Location, C as ClientActionFunction, a as ClientLoaderFunction, b as LinksFunction, M as MetaFunction, S as ShouldRevalidateFunction, P as Params, c as RouterContextProvider, A as ActionFunction, H as HeadersFunction, d as LoaderFunction, e as RouterInit } from './router-CAvh_Drx.mjs';
3
+
4
+ type RSCRouteConfigEntryBase = {
5
+ action?: ActionFunction;
6
+ clientAction?: ClientActionFunction;
7
+ clientLoader?: ClientLoaderFunction;
8
+ ErrorBoundary?: React.ComponentType<any>;
9
+ handle?: any;
10
+ headers?: HeadersFunction;
11
+ HydrateFallback?: React.ComponentType<any>;
12
+ Layout?: React.ComponentType<any>;
13
+ links?: LinksFunction;
14
+ loader?: LoaderFunction;
15
+ meta?: MetaFunction;
16
+ shouldRevalidate?: ShouldRevalidateFunction;
17
+ };
18
+ type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
19
+ id: string;
20
+ path?: string;
21
+ Component?: React.ComponentType<any>;
22
+ lazy?: () => Promise<RSCRouteConfigEntryBase & ({
23
+ default?: React.ComponentType<any>;
24
+ Component?: never;
25
+ } | {
26
+ default?: never;
27
+ Component?: React.ComponentType<any>;
28
+ })>;
29
+ } & ({
30
+ index: true;
31
+ } | {
32
+ children?: RSCRouteConfigEntry[];
33
+ });
34
+ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
35
+ type RSCRouteManifest = {
36
+ clientAction?: ClientActionFunction;
37
+ clientLoader?: ClientLoaderFunction;
38
+ element?: React.ReactElement | false;
39
+ errorElement?: React.ReactElement;
40
+ handle?: any;
41
+ hasAction: boolean;
42
+ hasComponent: boolean;
43
+ hasErrorBoundary: boolean;
44
+ hasLoader: boolean;
45
+ hydrateFallbackElement?: React.ReactElement;
46
+ id: string;
47
+ index?: boolean;
48
+ links?: LinksFunction;
49
+ meta?: MetaFunction;
50
+ parentId?: string;
51
+ path?: string;
52
+ shouldRevalidate?: ShouldRevalidateFunction;
53
+ };
54
+ type RSCRouteMatch = RSCRouteManifest & {
55
+ params: Params;
56
+ pathname: string;
57
+ pathnameBase: string;
58
+ };
59
+ type RSCRenderPayload = {
60
+ type: "render";
61
+ actionData: Record<string, any> | null;
62
+ basename: string | undefined;
63
+ errors: Record<string, any> | null;
64
+ loaderData: Record<string, any>;
65
+ location: Location;
66
+ matches: RSCRouteMatch[];
67
+ patches?: RSCRouteManifest[];
68
+ nonce?: string;
69
+ formState?: unknown;
70
+ };
71
+ type RSCManifestPayload = {
72
+ type: "manifest";
73
+ patches: RSCRouteManifest[];
74
+ };
75
+ type RSCActionPayload = {
76
+ type: "action";
77
+ actionResult: Promise<unknown>;
78
+ rerender?: Promise<RSCRenderPayload | RSCRedirectPayload>;
79
+ };
80
+ type RSCRedirectPayload = {
81
+ type: "redirect";
82
+ status: number;
83
+ location: string;
84
+ replace: boolean;
85
+ reload: boolean;
86
+ actionResult?: Promise<unknown>;
87
+ };
88
+ type RSCPayload = RSCRenderPayload | RSCManifestPayload | RSCActionPayload | RSCRedirectPayload;
89
+ type RSCMatch = {
90
+ statusCode: number;
91
+ headers: Headers;
92
+ payload: RSCPayload;
93
+ };
94
+ type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
95
+ type DecodeFormStateFunction = (result: unknown, formData: FormData) => unknown;
96
+ type DecodeReplyFunction = (reply: FormData | string, { temporaryReferences }: {
97
+ temporaryReferences: unknown;
98
+ }) => Promise<unknown[]>;
99
+ type LoadServerActionFunction = (id: string) => Promise<Function>;
100
+ /**
101
+ * Matches the given routes to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
102
+ * and returns an [RSC](https://react.dev/reference/rsc/server-components)
103
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
104
+ * encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
105
+ * enabled client router.
106
+ *
107
+ * @example
108
+ * import {
109
+ * createTemporaryReferenceSet,
110
+ * decodeAction,
111
+ * decodeReply,
112
+ * loadServerAction,
113
+ * renderToReadableStream,
114
+ * } from "@vitejs/plugin-rsc/rsc";
115
+ * import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
116
+ *
117
+ * matchRSCServerRequest({
118
+ * createTemporaryReferenceSet,
119
+ * decodeAction,
120
+ * decodeFormState,
121
+ * decodeReply,
122
+ * loadServerAction,
123
+ * request,
124
+ * routes: routes(),
125
+ * generateResponse(match) {
126
+ * return new Response(
127
+ * renderToReadableStream(match.payload),
128
+ * {
129
+ * status: match.statusCode,
130
+ * headers: match.headers,
131
+ * }
132
+ * );
133
+ * },
134
+ * });
135
+ *
136
+ * @name unstable_matchRSCServerRequest
137
+ * @public
138
+ * @category RSC
139
+ * @mode data
140
+ * @param opts Options
141
+ * @param opts.basename The basename to use when matching the request.
142
+ * @param opts.createTemporaryReferenceSet A function that returns a temporary
143
+ * reference set for the request, used to track temporary references in the [RSC](https://react.dev/reference/rsc/server-components)
144
+ * stream.
145
+ * @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
146
+ * function, responsible for loading a server action.
147
+ * @param opts.decodeFormState A function responsible for decoding form state for
148
+ * progressively enhanceable forms with React's [`useActionState`](https://react.dev/reference/react/useActionState)
149
+ * using your `react-server-dom-xyz/server`'s `decodeFormState`.
150
+ * @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
151
+ * function, used to decode the server function's arguments and bind them to the
152
+ * implementation for invocation by the router.
153
+ * @param opts.generateResponse A function responsible for using your
154
+ * `renderToReadableStream` to generate a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
155
+ * encoding the {@link unstable_RSCPayload}.
156
+ * @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
157
+ * `loadServerAction` function, used to load a server action by ID.
158
+ * @param opts.onError An optional error handler that will be called with any
159
+ * errors that occur during the request processing.
160
+ * @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
161
+ * to match against.
162
+ * @param opts.requestContext An instance of {@link RouterContextProvider}
163
+ * that should be created per request, to be passed to [`action`](../../start/data/route-object#action)s,
164
+ * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
165
+ * @param opts.routes Your {@link unstable_RSCRouteConfigEntry | route definitions}.
166
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
167
+ * that contains the [RSC](https://react.dev/reference/rsc/server-components)
168
+ * data for hydration.
169
+ */
170
+ declare function matchRSCServerRequest({ createTemporaryReferenceSet, basename, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
171
+ createTemporaryReferenceSet: () => unknown;
172
+ basename?: string;
173
+ decodeReply?: DecodeReplyFunction;
174
+ decodeAction?: DecodeActionFunction;
175
+ decodeFormState?: DecodeFormStateFunction;
176
+ requestContext?: RouterContextProvider;
177
+ loadServerAction?: LoadServerActionFunction;
178
+ onError?: (error: unknown) => void;
179
+ request: Request;
180
+ routes: RSCRouteConfigEntry[];
181
+ generateResponse: (match: RSCMatch, { temporaryReferences, }: {
182
+ temporaryReferences: unknown;
183
+ }) => Response;
184
+ }): Promise<Response>;
185
+
186
+ type BrowserCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>, { temporaryReferences, }: {
187
+ temporaryReferences: unknown;
188
+ }) => Promise<unknown>;
189
+ type EncodeReplyFunction = (args: unknown[], options: {
190
+ temporaryReferences: unknown;
191
+ }) => Promise<BodyInit>;
192
+ /**
193
+ * Create a React `callServer` implementation for React Router.
194
+ *
195
+ * @example
196
+ * import {
197
+ * createFromReadableStream,
198
+ * createTemporaryReferenceSet,
199
+ * encodeReply,
200
+ * setServerCallback,
201
+ * } from "@vitejs/plugin-rsc/browser";
202
+ * import { unstable_createCallServer as createCallServer } from "react-router";
203
+ *
204
+ * setServerCallback(
205
+ * createCallServer({
206
+ * createFromReadableStream,
207
+ * createTemporaryReferenceSet,
208
+ * encodeReply,
209
+ * })
210
+ * );
211
+ *
212
+ * @name unstable_createCallServer
213
+ * @public
214
+ * @category RSC
215
+ * @mode data
216
+ * @param opts Options
217
+ * @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
218
+ * `createFromReadableStream`. Used to decode payloads from the server.
219
+ * @param opts.createTemporaryReferenceSet A function that creates a temporary
220
+ * reference set for the [RSC](https://react.dev/reference/rsc/server-components)
221
+ * payload.
222
+ * @param opts.encodeReply Your `react-server-dom-xyz/client`'s `encodeReply`.
223
+ * Used when sending payloads to the server.
224
+ * @param opts.fetch Optional [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
225
+ * implementation. Defaults to global [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch).
226
+ * @returns A function that can be used to call server actions.
227
+ */
228
+ declare function createCallServer({ createFromReadableStream, createTemporaryReferenceSet, encodeReply, fetch: fetchImplementation, }: {
229
+ createFromReadableStream: BrowserCreateFromReadableStreamFunction;
230
+ createTemporaryReferenceSet: () => unknown;
231
+ encodeReply: EncodeReplyFunction;
232
+ fetch?: (request: Request) => Promise<Response>;
233
+ }): (id: string, args: unknown[]) => Promise<unknown>;
234
+ /**
235
+ * Props for the {@link unstable_RSCHydratedRouter} component.
236
+ *
237
+ * @name unstable_RSCHydratedRouterProps
238
+ * @category Types
239
+ */
240
+ interface RSCHydratedRouterProps {
241
+ /**
242
+ * Your `react-server-dom-xyz/client`'s `createFromReadableStream` function,
243
+ * used to decode payloads from the server.
244
+ */
245
+ createFromReadableStream: BrowserCreateFromReadableStreamFunction;
246
+ /**
247
+ * Optional fetch implementation. Defaults to global [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch).
248
+ */
249
+ fetch?: (request: Request) => Promise<Response>;
250
+ /**
251
+ * The decoded {@link unstable_RSCPayload} to hydrate.
252
+ */
253
+ payload: RSCPayload;
254
+ /**
255
+ * `"eager"` or `"lazy"` - Determines if links are eagerly discovered, or
256
+ * delayed until clicked.
257
+ */
258
+ routeDiscovery?: "eager" | "lazy";
259
+ /**
260
+ * A function that returns an {@link RouterContextProvider} instance
261
+ * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
262
+ * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
263
+ * This function is called to generate a fresh `context` instance on each
264
+ * navigation or fetcher call.
265
+ */
266
+ getContext?: RouterInit["getContext"];
267
+ }
268
+ /**
269
+ * Hydrates a server rendered {@link unstable_RSCPayload} in the browser.
270
+ *
271
+ * @example
272
+ * import { startTransition, StrictMode } from "react";
273
+ * import { hydrateRoot } from "react-dom/client";
274
+ * import {
275
+ * unstable_getRSCStream as getRSCStream,
276
+ * unstable_RSCHydratedRouter as RSCHydratedRouter,
277
+ * } from "react-router";
278
+ * import type { unstable_RSCPayload as RSCPayload } from "react-router";
279
+ *
280
+ * createFromReadableStream(getRSCStream()).then((payload) =>
281
+ * startTransition(async () => {
282
+ * hydrateRoot(
283
+ * document,
284
+ * <StrictMode>
285
+ * <RSCHydratedRouter
286
+ * createFromReadableStream={createFromReadableStream}
287
+ * payload={payload}
288
+ * />
289
+ * </StrictMode>,
290
+ * { formState: await getFormState(payload) },
291
+ * );
292
+ * }),
293
+ * );
294
+ *
295
+ * @name unstable_RSCHydratedRouter
296
+ * @public
297
+ * @category RSC
298
+ * @mode data
299
+ * @param props Props
300
+ * @param {unstable_RSCHydratedRouterProps.createFromReadableStream} props.createFromReadableStream n/a
301
+ * @param {unstable_RSCHydratedRouterProps.fetch} props.fetch n/a
302
+ * @param {unstable_RSCHydratedRouterProps.getContext} props.getContext n/a
303
+ * @param {unstable_RSCHydratedRouterProps.payload} props.payload n/a
304
+ * @param {unstable_RSCHydratedRouterProps.routeDiscovery} props.routeDiscovery n/a
305
+ * @returns A hydrated {@link DataRouter} that can be used to navigate and
306
+ * render routes.
307
+ */
308
+ declare function RSCHydratedRouter({ createFromReadableStream, fetch: fetchImplementation, payload, routeDiscovery, getContext, }: RSCHydratedRouterProps): React.JSX.Element;
309
+
310
+ export { type BrowserCreateFromReadableStreamFunction as B, type DecodeActionFunction as D, type EncodeReplyFunction as E, type LoadServerActionFunction as L, RSCHydratedRouter as R, type DecodeFormStateFunction as a, type DecodeReplyFunction as b, createCallServer as c, type RSCManifestPayload as d, type RSCPayload as e, type RSCRenderPayload as f, type RSCHydratedRouterProps as g, type RSCMatch as h, type RSCRouteManifest as i, type RSCRouteMatch as j, type RSCRouteConfigEntry as k, type RSCRouteConfig as l, matchRSCServerRequest as m };