react-router 7.6.3 → 7.7.0-pre.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 (64) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/development/browser-BSrXyLft.d.mts +157 -0
  3. package/dist/development/chunk-P37AORTA.js +21 -0
  4. package/dist/development/{chunk-QMGIS6GS.mjs → chunk-PUMRC5B5.mjs} +1473 -3024
  5. package/dist/development/chunk-PY5DBM7W.mjs +2695 -0
  6. package/dist/development/chunk-X5ZUQHCD.js +10021 -0
  7. package/dist/development/components-IaVqGBuO.d.mts +816 -0
  8. package/dist/development/dom-export.d.mts +4 -2
  9. package/dist/development/dom-export.js +57 -76
  10. package/dist/development/dom-export.mjs +11 -8
  11. package/dist/development/index-react-server-client-DOK8MfYF.d.mts +1360 -0
  12. package/dist/development/{lib-B33EY9A0.d.mts → index-react-server-client-LrDNRnlX.d.ts} +39 -5
  13. package/dist/development/index-react-server-client.d.mts +4 -0
  14. package/dist/development/index-react-server-client.d.ts +3 -0
  15. package/dist/development/index-react-server-client.js +54 -0
  16. package/dist/development/index-react-server-client.mjs +53 -0
  17. package/dist/development/index-react-server.d.mts +1863 -0
  18. package/dist/development/index-react-server.d.ts +1863 -0
  19. package/dist/development/index-react-server.js +3196 -0
  20. package/dist/development/index-react-server.mjs +3083 -0
  21. package/dist/development/index.d.mts +33 -47
  22. package/dist/development/index.d.ts +195 -2190
  23. package/dist/development/index.js +2596 -11444
  24. package/dist/development/index.mjs +33 -18
  25. package/dist/development/lib/types/internal.d.mts +2 -2
  26. package/dist/development/lib/types/internal.d.ts +2 -1
  27. package/dist/development/lib/types/internal.js +2 -20
  28. package/dist/development/lib/types/internal.mjs +1 -1
  29. package/dist/{production/register-DeIo2iHO.d.mts → development/register-DiOIlEq5.d.mts} +1 -1
  30. package/dist/development/{register-DeIo2iHO.d.mts → register-DiOIlEq5.d.ts} +1 -1
  31. package/dist/development/{route-data-D7Xbr_Ww.d.mts → route-data-7aXBQ4I3.d.ts} +26 -15
  32. package/dist/{production/route-data-D7Xbr_Ww.d.mts → development/route-data-DAw7Esur.d.mts} +16 -5
  33. package/dist/production/browser-BSrXyLft.d.mts +157 -0
  34. package/dist/production/{chunk-S4Z2UWCU.mjs → chunk-5AMJKWMN.mjs} +1473 -3024
  35. package/dist/production/chunk-KWWBKJDT.mjs +2695 -0
  36. package/dist/production/chunk-LKVDO7TU.js +10021 -0
  37. package/dist/production/chunk-P37AORTA.js +21 -0
  38. package/dist/production/components-IaVqGBuO.d.mts +816 -0
  39. package/dist/production/dom-export.d.mts +4 -2
  40. package/dist/production/dom-export.js +57 -76
  41. package/dist/production/dom-export.mjs +11 -8
  42. package/dist/production/index-react-server-client-DOK8MfYF.d.mts +1360 -0
  43. package/dist/production/{lib-B33EY9A0.d.mts → index-react-server-client-LrDNRnlX.d.ts} +39 -5
  44. package/dist/production/index-react-server-client.d.mts +4 -0
  45. package/dist/production/index-react-server-client.d.ts +3 -0
  46. package/dist/production/index-react-server-client.js +54 -0
  47. package/dist/production/index-react-server-client.mjs +53 -0
  48. package/dist/production/index-react-server.d.mts +1863 -0
  49. package/dist/production/index-react-server.d.ts +1863 -0
  50. package/dist/production/index-react-server.js +3196 -0
  51. package/dist/production/index-react-server.mjs +3083 -0
  52. package/dist/production/index.d.mts +33 -47
  53. package/dist/production/index.d.ts +195 -2190
  54. package/dist/production/index.js +2596 -11444
  55. package/dist/production/index.mjs +33 -18
  56. package/dist/production/lib/types/internal.d.mts +2 -2
  57. package/dist/production/lib/types/internal.d.ts +2 -1
  58. package/dist/production/lib/types/internal.js +2 -20
  59. package/dist/production/lib/types/internal.mjs +1 -1
  60. package/dist/production/register-DiOIlEq5.d.mts +24 -0
  61. package/dist/production/register-DiOIlEq5.d.ts +24 -0
  62. package/dist/production/{register-COAKzST_.d.ts → route-data-7aXBQ4I3.d.ts} +26 -38
  63. package/dist/{development/register-COAKzST_.d.ts → production/route-data-DAw7Esur.d.mts} +16 -28
  64. package/package.json +56 -11
@@ -0,0 +1,1863 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import * as React from 'react';
3
+ export { Await, 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';
4
+ import { ParseOptions, SerializeOptions } from 'cookie';
5
+ export { ParseOptions as CookieParseOptions, SerializeOptions as CookieSerializeOptions } from 'cookie';
6
+
7
+ /**
8
+ * Actions represent the type of change to a location value.
9
+ */
10
+ declare enum Action {
11
+ /**
12
+ * A POP indicates a change to an arbitrary index in the history stack, such
13
+ * as a back or forward navigation. It does not describe the direction of the
14
+ * navigation, only that the current index changed.
15
+ *
16
+ * Note: This is the default action for newly created history objects.
17
+ */
18
+ Pop = "POP",
19
+ /**
20
+ * A PUSH indicates a new entry being added to the history stack, such as when
21
+ * a link is clicked and a new page loads. When this happens, all subsequent
22
+ * entries in the stack are lost.
23
+ */
24
+ Push = "PUSH",
25
+ /**
26
+ * A REPLACE indicates the entry at the current index in the history stack
27
+ * being replaced by a new one.
28
+ */
29
+ Replace = "REPLACE"
30
+ }
31
+ /**
32
+ * The pathname, search, and hash values of a URL.
33
+ */
34
+ interface Path {
35
+ /**
36
+ * A URL pathname, beginning with a /.
37
+ */
38
+ pathname: string;
39
+ /**
40
+ * A URL search string, beginning with a ?.
41
+ */
42
+ search: string;
43
+ /**
44
+ * A URL fragment identifier, beginning with a #.
45
+ */
46
+ hash: string;
47
+ }
48
+ /**
49
+ * An entry in a history stack. A location contains information about the
50
+ * URL path, as well as possibly some arbitrary state and a key.
51
+ */
52
+ interface Location<State = any> extends Path {
53
+ /**
54
+ * A value of arbitrary data associated with this location.
55
+ */
56
+ state: State;
57
+ /**
58
+ * A unique string associated with this location. May be used to safely store
59
+ * and retrieve data in some other storage API, like `localStorage`.
60
+ *
61
+ * Note: This value is always "default" on the initial location.
62
+ */
63
+ key: string;
64
+ }
65
+ /**
66
+ * A change to the current location.
67
+ */
68
+ interface Update {
69
+ /**
70
+ * The action that triggered the change.
71
+ */
72
+ action: Action;
73
+ /**
74
+ * The new location.
75
+ */
76
+ location: Location;
77
+ /**
78
+ * The delta between this location and the former location in the history stack
79
+ */
80
+ delta: number | null;
81
+ }
82
+ /**
83
+ * A function that receives notifications about location changes.
84
+ */
85
+ interface Listener {
86
+ (update: Update): void;
87
+ }
88
+ /**
89
+ * Describes a location that is the destination of some navigation used in
90
+ * {@link Link}, {@link useNavigate}, etc.
91
+ */
92
+ type To = string | Partial<Path>;
93
+ /**
94
+ * A history is an interface to the navigation stack. The history serves as the
95
+ * source of truth for the current location, as well as provides a set of
96
+ * methods that may be used to change it.
97
+ *
98
+ * It is similar to the DOM's `window.history` object, but with a smaller, more
99
+ * focused API.
100
+ */
101
+ interface History {
102
+ /**
103
+ * The last action that modified the current location. This will always be
104
+ * Action.Pop when a history instance is first created. This value is mutable.
105
+ */
106
+ readonly action: Action;
107
+ /**
108
+ * The current location. This value is mutable.
109
+ */
110
+ readonly location: Location;
111
+ /**
112
+ * Returns a valid href for the given `to` value that may be used as
113
+ * the value of an <a href> attribute.
114
+ *
115
+ * @param to - The destination URL
116
+ */
117
+ createHref(to: To): string;
118
+ /**
119
+ * Returns a URL for the given `to` value
120
+ *
121
+ * @param to - The destination URL
122
+ */
123
+ createURL(to: To): URL;
124
+ /**
125
+ * Encode a location the same way window.history would do (no-op for memory
126
+ * history) so we ensure our PUSH/REPLACE navigations for data routers
127
+ * behave the same as POP
128
+ *
129
+ * @param to Unencoded path
130
+ */
131
+ encodeLocation(to: To): Path;
132
+ /**
133
+ * Pushes a new location onto the history stack, increasing its length by one.
134
+ * If there were any entries in the stack after the current one, they are
135
+ * lost.
136
+ *
137
+ * @param to - The new URL
138
+ * @param state - Data to associate with the new location
139
+ */
140
+ push(to: To, state?: any): void;
141
+ /**
142
+ * Replaces the current location in the history stack with a new one. The
143
+ * location that was replaced will no longer be available.
144
+ *
145
+ * @param to - The new URL
146
+ * @param state - Data to associate with the new location
147
+ */
148
+ replace(to: To, state?: any): void;
149
+ /**
150
+ * Navigates `n` entries backward/forward in the history stack relative to the
151
+ * current index. For example, a "back" navigation would use go(-1).
152
+ *
153
+ * @param delta - The delta in the stack index
154
+ */
155
+ go(delta: number): void;
156
+ /**
157
+ * Sets up a listener that will be called whenever the current location
158
+ * changes.
159
+ *
160
+ * @param listener - A function that will be called when the location changes
161
+ * @returns unlisten - A function that may be used to stop listening
162
+ */
163
+ listen(listener: Listener): () => void;
164
+ }
165
+
166
+ /**
167
+ * An augmentable interface users can modify in their app-code to opt into
168
+ * future-flag-specific types
169
+ */
170
+ interface Future {
171
+ }
172
+ type MiddlewareEnabled = Future extends {
173
+ unstable_middleware: infer T extends boolean;
174
+ } ? T : false;
175
+
176
+ type MaybePromise<T> = T | Promise<T>;
177
+ /**
178
+ * Map of routeId -> data returned from a loader/action/error
179
+ */
180
+ interface RouteData {
181
+ [routeId: string]: any;
182
+ }
183
+ type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
184
+ type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
185
+ /**
186
+ * Users can specify either lowercase or uppercase form methods on `<Form>`,
187
+ * useSubmit(), `<fetcher.Form>`, etc.
188
+ */
189
+ type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
190
+ /**
191
+ * Active navigation/fetcher form methods are exposed in uppercase on the
192
+ * RouterState. This is to align with the normalization done via fetch().
193
+ */
194
+ type FormMethod = UpperCaseFormMethod;
195
+ type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
196
+ type JsonObject = {
197
+ [Key in string]: JsonValue;
198
+ } & {
199
+ [Key in string]?: JsonValue | undefined;
200
+ };
201
+ type JsonArray = JsonValue[] | readonly JsonValue[];
202
+ type JsonPrimitive = string | number | boolean | null;
203
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
204
+ /**
205
+ * @private
206
+ * Internal interface to pass around for action submissions, not intended for
207
+ * external consumption
208
+ */
209
+ type Submission = {
210
+ formMethod: FormMethod;
211
+ formAction: string;
212
+ formEncType: FormEncType;
213
+ formData: FormData;
214
+ json: undefined;
215
+ text: undefined;
216
+ } | {
217
+ formMethod: FormMethod;
218
+ formAction: string;
219
+ formEncType: FormEncType;
220
+ formData: undefined;
221
+ json: JsonValue;
222
+ text: undefined;
223
+ } | {
224
+ formMethod: FormMethod;
225
+ formAction: string;
226
+ formEncType: FormEncType;
227
+ formData: undefined;
228
+ json: undefined;
229
+ text: string;
230
+ };
231
+ interface unstable_RouterContext<T = unknown> {
232
+ defaultValue?: T;
233
+ }
234
+ /**
235
+ * Creates a context object that may be used to store and retrieve arbitrary values.
236
+ *
237
+ * If a `defaultValue` is provided, it will be returned from `context.get()` when no value has been
238
+ * set for the context. Otherwise reading this context when no value has been set will throw an
239
+ * error.
240
+ *
241
+ * @param defaultValue The default value for the context
242
+ * @returns A context object
243
+ */
244
+ declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
245
+ /**
246
+ * A Map of RouterContext objects to their initial values - used to populate a
247
+ * fresh `context` value per request/navigation/fetch
248
+ */
249
+ type unstable_InitialContext = Map<unstable_RouterContext, unknown>;
250
+ /**
251
+ * Provides methods for writing/reading values in application context in a typesafe way.
252
+ */
253
+ declare class unstable_RouterContextProvider {
254
+ #private;
255
+ constructor(init?: unstable_InitialContext);
256
+ get<T>(context: unstable_RouterContext<T>): T;
257
+ set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
258
+ }
259
+ type DefaultContext = MiddlewareEnabled extends true ? unstable_RouterContextProvider : any;
260
+ /**
261
+ * @private
262
+ * Arguments passed to route loader/action functions. Same for now but we keep
263
+ * this as a private implementation detail in case they diverge in the future.
264
+ */
265
+ interface DataFunctionArgs<Context> {
266
+ /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read headers (like cookies, and {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams URLSearchParams} from the request. */
267
+ request: Request;
268
+ /**
269
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
270
+ * @example
271
+ * // app/routes.ts
272
+ * route("teams/:teamId", "./team.tsx"),
273
+ *
274
+ * // app/team.tsx
275
+ * export function loader({
276
+ * params,
277
+ * }: Route.LoaderArgs) {
278
+ * params.teamId;
279
+ * // ^ string
280
+ * }
281
+ **/
282
+ params: Params;
283
+ /**
284
+ * This is the context passed in to your server adapter's getLoadContext() function.
285
+ * It's a way to bridge the gap between the adapter's request/response API with your React Router app.
286
+ * It is only applicable if you are using a custom server adapter.
287
+ */
288
+ context: Context;
289
+ }
290
+ /**
291
+ * Route middleware `next` function to call downstream handlers and then complete
292
+ * middlewares from the bottom-up
293
+ */
294
+ interface unstable_MiddlewareNextFunction<Result = unknown> {
295
+ (): MaybePromise<Result>;
296
+ }
297
+ /**
298
+ * Route middleware function signature. Receives the same "data" arguments as a
299
+ * `loader`/`action` (`request`, `params`, `context`) as the first parameter and
300
+ * a `next` function as the second parameter which will call downstream handlers
301
+ * and then complete middlewares from the bottom-up
302
+ */
303
+ type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<unstable_RouterContextProvider>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
304
+ /**
305
+ * Arguments passed to loader functions
306
+ */
307
+ interface LoaderFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
308
+ }
309
+ /**
310
+ * Arguments passed to action functions
311
+ */
312
+ interface ActionFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
313
+ }
314
+ /**
315
+ * Loaders and actions can return anything
316
+ */
317
+ type DataFunctionValue = unknown;
318
+ type DataFunctionReturnValue = MaybePromise<DataFunctionValue>;
319
+ /**
320
+ * Route loader function signature
321
+ */
322
+ type LoaderFunction<Context = DefaultContext> = {
323
+ (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
324
+ } & {
325
+ hydrate?: boolean;
326
+ };
327
+ /**
328
+ * Route action function signature
329
+ */
330
+ interface ActionFunction<Context = DefaultContext> {
331
+ (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
332
+ }
333
+ /**
334
+ * Arguments passed to shouldRevalidate function
335
+ */
336
+ interface ShouldRevalidateFunctionArgs {
337
+ /** This is the url the navigation started from. You can compare it with `nextUrl` to decide if you need to revalidate this route's data. */
338
+ currentUrl: URL;
339
+ /** These are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the URL that can be compared to the `nextParams` to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed. */
340
+ currentParams: AgnosticDataRouteMatch["params"];
341
+ /** In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl. */
342
+ nextUrl: URL;
343
+ /** In the case of navigation, these are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams. */
344
+ nextParams: AgnosticDataRouteMatch["params"];
345
+ /** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
346
+ formMethod?: Submission["formMethod"];
347
+ /** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
348
+ formAction?: Submission["formAction"];
349
+ /** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
350
+ formEncType?: Submission["formEncType"];
351
+ /** The form submission data when the form's encType is `text/plain` */
352
+ text?: Submission["text"];
353
+ /** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
354
+ formData?: Submission["formData"];
355
+ /** The form submission data when the form's encType is `application/json` */
356
+ json?: Submission["json"];
357
+ /** The status code of the action response */
358
+ actionStatus?: number;
359
+ /**
360
+ * When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.
361
+ *
362
+ * @example
363
+ * export async function action() {
364
+ * await saveSomeStuff();
365
+ * return { ok: true };
366
+ * }
367
+ *
368
+ * export function shouldRevalidate({
369
+ * actionResult,
370
+ * }) {
371
+ * if (actionResult?.ok) {
372
+ * return false;
373
+ * }
374
+ * return true;
375
+ * }
376
+ */
377
+ actionResult?: any;
378
+ /**
379
+ * By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:
380
+ *
381
+ * /projects/123/tasks/abc
382
+ * /projects/123/tasks/def
383
+ * React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
384
+ *
385
+ * It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.
386
+ */
387
+ defaultShouldRevalidate: boolean;
388
+ }
389
+ /**
390
+ * Route shouldRevalidate function signature. This runs after any submission
391
+ * (navigation or fetcher), so we flatten the navigation/fetcher submission
392
+ * onto the arguments. It shouldn't matter whether it came from a navigation
393
+ * or a fetcher, what really matters is the URLs and the formData since loaders
394
+ * have to re-run based on the data models that were potentially mutated.
395
+ */
396
+ interface ShouldRevalidateFunction {
397
+ (args: ShouldRevalidateFunctionArgs): boolean;
398
+ }
399
+ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
400
+ /**
401
+ * @private
402
+ */
403
+ _lazyPromises?: {
404
+ middleware: Promise<void> | undefined;
405
+ handler: Promise<void> | undefined;
406
+ route: Promise<void> | undefined;
407
+ };
408
+ shouldLoad: boolean;
409
+ unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
410
+ unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
411
+ resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
412
+ }
413
+ interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
414
+ matches: DataStrategyMatch[];
415
+ unstable_runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
416
+ fetcherKey: string | null;
417
+ }
418
+ /**
419
+ * Result from a loader or action called via dataStrategy
420
+ */
421
+ interface DataStrategyResult {
422
+ type: "data" | "error";
423
+ result: unknown;
424
+ }
425
+ interface DataStrategyFunction<Context = DefaultContext> {
426
+ (args: DataStrategyFunctionArgs<Context>): Promise<Record<string, DataStrategyResult>>;
427
+ }
428
+ type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
429
+ signal: AbortSignal;
430
+ path: string;
431
+ matches: M[];
432
+ fetcherKey: string | undefined;
433
+ patch: (routeId: string | null, children: O[]) => void;
434
+ };
435
+ type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => MaybePromise<void>;
436
+ /**
437
+ * Function provided by the framework-aware layers to set any framework-specific
438
+ * properties from framework-agnostic properties
439
+ */
440
+ interface MapRoutePropertiesFunction {
441
+ (route: AgnosticRouteObject): {
442
+ hasErrorBoundary: boolean;
443
+ } & Record<string, any>;
444
+ }
445
+ /**
446
+ * Keys we cannot change from within a lazy object. We spread all other keys
447
+ * onto the route. Either they're meaningful to the router, or they'll get
448
+ * ignored.
449
+ */
450
+ type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
451
+ /**
452
+ * Keys we cannot change from within a lazy() function. We spread all other keys
453
+ * onto the route. Either they're meaningful to the router, or they'll get
454
+ * ignored.
455
+ */
456
+ type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "unstable_middleware";
457
+ /**
458
+ * lazy object to load route properties, which can add non-matching
459
+ * related properties to a route
460
+ */
461
+ type LazyRouteObject<R extends AgnosticRouteObject> = {
462
+ [K in keyof R as K extends UnsupportedLazyRouteObjectKey ? never : K]?: () => Promise<R[K] | null | undefined>;
463
+ };
464
+ /**
465
+ * lazy() function to load a route definition, which can add non-matching
466
+ * related properties to a route
467
+ */
468
+ interface LazyRouteFunction<R extends AgnosticRouteObject> {
469
+ (): Promise<Omit<R, UnsupportedLazyRouteFunctionKey> & Partial<Record<UnsupportedLazyRouteFunctionKey, never>>>;
470
+ }
471
+ type LazyRouteDefinition<R extends AgnosticRouteObject> = LazyRouteObject<R> | LazyRouteFunction<R>;
472
+ /**
473
+ * Base RouteObject with common props shared by all types of routes
474
+ */
475
+ type AgnosticBaseRouteObject = {
476
+ caseSensitive?: boolean;
477
+ path?: string;
478
+ id?: string;
479
+ unstable_middleware?: unstable_MiddlewareFunction[];
480
+ loader?: LoaderFunction | boolean;
481
+ action?: ActionFunction | boolean;
482
+ hasErrorBoundary?: boolean;
483
+ shouldRevalidate?: ShouldRevalidateFunction;
484
+ handle?: any;
485
+ lazy?: LazyRouteDefinition<AgnosticBaseRouteObject>;
486
+ };
487
+ /**
488
+ * Index routes must not have children
489
+ */
490
+ type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
491
+ children?: undefined;
492
+ index: true;
493
+ };
494
+ /**
495
+ * Non-index routes may have children, but cannot have index
496
+ */
497
+ type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
498
+ children?: AgnosticRouteObject[];
499
+ index?: false;
500
+ };
501
+ /**
502
+ * A route object represents a logical route, with (optionally) its child
503
+ * routes organized in a tree-like structure.
504
+ */
505
+ type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
506
+ type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
507
+ id: string;
508
+ };
509
+ type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
510
+ children?: AgnosticDataRouteObject[];
511
+ id: string;
512
+ };
513
+ /**
514
+ * A data route object, which is just a RouteObject with a required unique ID
515
+ */
516
+ type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
517
+ /**
518
+ * The parameters that were parsed from the URL path.
519
+ */
520
+ type Params<Key extends string = string> = {
521
+ readonly [key in Key]: string | undefined;
522
+ };
523
+ /**
524
+ * A RouteMatch contains info about how a route matched a URL.
525
+ */
526
+ interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
527
+ /**
528
+ * The names and values of dynamic parameters in the URL.
529
+ */
530
+ params: Params<ParamKey>;
531
+ /**
532
+ * The portion of the URL pathname that was matched.
533
+ */
534
+ pathname: string;
535
+ /**
536
+ * The portion of the URL pathname that was matched before child routes.
537
+ */
538
+ pathnameBase: string;
539
+ /**
540
+ * The route object that was used to match.
541
+ */
542
+ route: RouteObjectType;
543
+ }
544
+ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
545
+ }
546
+ /**
547
+ * Matches the given routes to a location and returns the match data.
548
+ *
549
+ * @category Utils
550
+ */
551
+ declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
552
+ interface UIMatch<Data = unknown, Handle = unknown> {
553
+ id: string;
554
+ pathname: string;
555
+ /**
556
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
557
+ **/
558
+ params: AgnosticRouteMatch["params"];
559
+ /** The return value from the matched route's loader or clientLoader */
560
+ data: Data;
561
+ /** The {@link https://reactrouter.com/start/framework/route-module#handle handle object} exported from the matched route module */
562
+ handle: Handle;
563
+ }
564
+ declare class DataWithResponseInit<D> {
565
+ type: string;
566
+ data: D;
567
+ init: ResponseInit | null;
568
+ constructor(data: D, init?: ResponseInit);
569
+ }
570
+ /**
571
+ * Create "responses" that contain `status`/`headers` without forcing
572
+ * serialization into an actual `Response` - used by Remix single fetch
573
+ *
574
+ * @category Utils
575
+ */
576
+ declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
577
+ type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
578
+ /**
579
+ * A redirect response. Sets the status code and the `Location` header.
580
+ * Defaults to "302 Found".
581
+ *
582
+ * @category Utils
583
+ */
584
+ declare const redirect$1: RedirectFunction;
585
+ /**
586
+ * A redirect response that will force a document reload to the new location.
587
+ * Sets the status code and the `Location` header.
588
+ * Defaults to "302 Found".
589
+ *
590
+ * @category Utils
591
+ */
592
+ declare const redirectDocument$1: RedirectFunction;
593
+ /**
594
+ * A redirect response that will perform a `history.replaceState` instead of a
595
+ * `history.pushState` for client-side navigation redirects.
596
+ * Sets the status code and the `Location` header.
597
+ * Defaults to "302 Found".
598
+ *
599
+ * @category Utils
600
+ */
601
+ declare const replace$1: RedirectFunction;
602
+
603
+ /**
604
+ * A Router instance manages all navigation and data loading/mutations
605
+ */
606
+ interface Router {
607
+ /**
608
+ * @private
609
+ * PRIVATE - DO NOT USE
610
+ *
611
+ * Return the basename for the router
612
+ */
613
+ get basename(): RouterInit["basename"];
614
+ /**
615
+ * @private
616
+ * PRIVATE - DO NOT USE
617
+ *
618
+ * Return the future config for the router
619
+ */
620
+ get future(): FutureConfig;
621
+ /**
622
+ * @private
623
+ * PRIVATE - DO NOT USE
624
+ *
625
+ * Return the current state of the router
626
+ */
627
+ get state(): RouterState;
628
+ /**
629
+ * @private
630
+ * PRIVATE - DO NOT USE
631
+ *
632
+ * Return the routes for this router instance
633
+ */
634
+ get routes(): AgnosticDataRouteObject[];
635
+ /**
636
+ * @private
637
+ * PRIVATE - DO NOT USE
638
+ *
639
+ * Return the window associated with the router
640
+ */
641
+ get window(): RouterInit["window"];
642
+ /**
643
+ * @private
644
+ * PRIVATE - DO NOT USE
645
+ *
646
+ * Initialize the router, including adding history listeners and kicking off
647
+ * initial data fetches. Returns a function to cleanup listeners and abort
648
+ * any in-progress loads
649
+ */
650
+ initialize(): Router;
651
+ /**
652
+ * @private
653
+ * PRIVATE - DO NOT USE
654
+ *
655
+ * Subscribe to router.state updates
656
+ *
657
+ * @param fn function to call with the new state
658
+ */
659
+ subscribe(fn: RouterSubscriber): () => void;
660
+ /**
661
+ * @private
662
+ * PRIVATE - DO NOT USE
663
+ *
664
+ * Enable scroll restoration behavior in the router
665
+ *
666
+ * @param savedScrollPositions Object that will manage positions, in case
667
+ * it's being restored from sessionStorage
668
+ * @param getScrollPosition Function to get the active Y scroll position
669
+ * @param getKey Function to get the key to use for restoration
670
+ */
671
+ enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
672
+ /**
673
+ * @private
674
+ * PRIVATE - DO NOT USE
675
+ *
676
+ * Navigate forward/backward in the history stack
677
+ * @param to Delta to move in the history stack
678
+ */
679
+ navigate(to: number): Promise<void>;
680
+ /**
681
+ * Navigate to the given path
682
+ * @param to Path to navigate to
683
+ * @param opts Navigation options (method, submission, etc.)
684
+ */
685
+ navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
686
+ /**
687
+ * @private
688
+ * PRIVATE - DO NOT USE
689
+ *
690
+ * Trigger a fetcher load/submission
691
+ *
692
+ * @param key Fetcher key
693
+ * @param routeId Route that owns the fetcher
694
+ * @param href href to fetch
695
+ * @param opts Fetcher options, (method, submission, etc.)
696
+ */
697
+ fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
698
+ /**
699
+ * @private
700
+ * PRIVATE - DO NOT USE
701
+ *
702
+ * Trigger a revalidation of all current route loaders and fetcher loads
703
+ */
704
+ revalidate(): Promise<void>;
705
+ /**
706
+ * @private
707
+ * PRIVATE - DO NOT USE
708
+ *
709
+ * Utility function to create an href for the given location
710
+ * @param location
711
+ */
712
+ createHref(location: Location | URL): string;
713
+ /**
714
+ * @private
715
+ * PRIVATE - DO NOT USE
716
+ *
717
+ * Utility function to URL encode a destination path according to the internal
718
+ * history implementation
719
+ * @param to
720
+ */
721
+ encodeLocation(to: To): Path;
722
+ /**
723
+ * @private
724
+ * PRIVATE - DO NOT USE
725
+ *
726
+ * Get/create a fetcher for the given key
727
+ * @param key
728
+ */
729
+ getFetcher<TData = any>(key: string): Fetcher<TData>;
730
+ /**
731
+ * @private
732
+ * PRIVATE - DO NOT USE
733
+ *
734
+ * Delete the fetcher for a given key
735
+ * @param key
736
+ */
737
+ deleteFetcher(key: string): void;
738
+ /**
739
+ * @private
740
+ * PRIVATE - DO NOT USE
741
+ *
742
+ * Cleanup listeners and abort any in-progress loads
743
+ */
744
+ dispose(): void;
745
+ /**
746
+ * @private
747
+ * PRIVATE - DO NOT USE
748
+ *
749
+ * Get a navigation blocker
750
+ * @param key The identifier for the blocker
751
+ * @param fn The blocker function implementation
752
+ */
753
+ getBlocker(key: string, fn: BlockerFunction): Blocker;
754
+ /**
755
+ * @private
756
+ * PRIVATE - DO NOT USE
757
+ *
758
+ * Delete a navigation blocker
759
+ * @param key The identifier for the blocker
760
+ */
761
+ deleteBlocker(key: string): void;
762
+ /**
763
+ * @private
764
+ * PRIVATE DO NOT USE
765
+ *
766
+ * Patch additional children routes into an existing parent route
767
+ * @param routeId The parent route id or a callback function accepting `patch`
768
+ * to perform batch patching
769
+ * @param children The additional children routes
770
+ * @param unstable_allowElementMutations Allow mutation or route elements on
771
+ * existing routes. Intended for RSC-usage
772
+ * only.
773
+ */
774
+ patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
775
+ /**
776
+ * @private
777
+ * PRIVATE - DO NOT USE
778
+ *
779
+ * HMR needs to pass in-flight route updates to React Router
780
+ * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
781
+ */
782
+ _internalSetRoutes(routes: AgnosticRouteObject[]): void;
783
+ /**
784
+ * @private
785
+ * PRIVATE - DO NOT USE
786
+ *
787
+ * Cause subscribers to re-render. This is used to force a re-render.
788
+ */
789
+ _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
790
+ /**
791
+ * @private
792
+ * PRIVATE - DO NOT USE
793
+ *
794
+ * Internal fetch AbortControllers accessed by unit tests
795
+ */
796
+ _internalFetchControllers: Map<string, AbortController>;
797
+ }
798
+ /**
799
+ * State maintained internally by the router. During a navigation, all states
800
+ * reflect the "old" location unless otherwise noted.
801
+ */
802
+ interface RouterState {
803
+ /**
804
+ * The action of the most recent navigation
805
+ */
806
+ historyAction: Action;
807
+ /**
808
+ * The current location reflected by the router
809
+ */
810
+ location: Location;
811
+ /**
812
+ * The current set of route matches
813
+ */
814
+ matches: AgnosticDataRouteMatch[];
815
+ /**
816
+ * Tracks whether we've completed our initial data load
817
+ */
818
+ initialized: boolean;
819
+ /**
820
+ * Current scroll position we should start at for a new view
821
+ * - number -> scroll position to restore to
822
+ * - false -> do not restore scroll at all (used during submissions/revalidations)
823
+ * - null -> don't have a saved position, scroll to hash or top of page
824
+ */
825
+ restoreScrollPosition: number | false | null;
826
+ /**
827
+ * Indicate whether this navigation should skip resetting the scroll position
828
+ * if we are unable to restore the scroll position
829
+ */
830
+ preventScrollReset: boolean;
831
+ /**
832
+ * Tracks the state of the current navigation
833
+ */
834
+ navigation: Navigation;
835
+ /**
836
+ * Tracks any in-progress revalidations
837
+ */
838
+ revalidation: RevalidationState;
839
+ /**
840
+ * Data from the loaders for the current matches
841
+ */
842
+ loaderData: RouteData;
843
+ /**
844
+ * Data from the action for the current matches
845
+ */
846
+ actionData: RouteData | null;
847
+ /**
848
+ * Errors caught from loaders for the current matches
849
+ */
850
+ errors: RouteData | null;
851
+ /**
852
+ * Map of current fetchers
853
+ */
854
+ fetchers: Map<string, Fetcher>;
855
+ /**
856
+ * Map of current blockers
857
+ */
858
+ blockers: Map<string, Blocker>;
859
+ }
860
+ /**
861
+ * Data that can be passed into hydrate a Router from SSR
862
+ */
863
+ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
864
+ /**
865
+ * Future flags to toggle new feature behavior
866
+ */
867
+ interface FutureConfig {
868
+ unstable_middleware: boolean;
869
+ }
870
+ /**
871
+ * Initialization options for createRouter
872
+ */
873
+ interface RouterInit {
874
+ routes: AgnosticRouteObject[];
875
+ history: History;
876
+ basename?: string;
877
+ unstable_getContext?: () => MaybePromise<unstable_InitialContext>;
878
+ mapRouteProperties?: MapRoutePropertiesFunction;
879
+ future?: Partial<FutureConfig>;
880
+ hydrationRouteProperties?: string[];
881
+ hydrationData?: HydrationState;
882
+ window?: Window;
883
+ dataStrategy?: DataStrategyFunction;
884
+ patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
885
+ }
886
+ /**
887
+ * State returned from a server-side query() call
888
+ */
889
+ interface StaticHandlerContext {
890
+ basename: Router["basename"];
891
+ location: RouterState["location"];
892
+ matches: RouterState["matches"];
893
+ loaderData: RouterState["loaderData"];
894
+ actionData: RouterState["actionData"];
895
+ errors: RouterState["errors"];
896
+ statusCode: number;
897
+ loaderHeaders: Record<string, Headers>;
898
+ actionHeaders: Record<string, Headers>;
899
+ _deepestRenderedBoundaryId?: string | null;
900
+ }
901
+ /**
902
+ * A StaticHandler instance manages a singular SSR navigation/fetch event
903
+ */
904
+ interface StaticHandler {
905
+ dataRoutes: AgnosticDataRouteObject[];
906
+ query(request: Request, opts?: {
907
+ requestContext?: unknown;
908
+ filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
909
+ skipLoaderErrorBubbling?: boolean;
910
+ skipRevalidation?: boolean;
911
+ dataStrategy?: DataStrategyFunction<unknown>;
912
+ unstable_respond?: (staticContext: StaticHandlerContext) => MaybePromise<Response>;
913
+ unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
914
+ }): Promise<StaticHandlerContext | Response>;
915
+ queryRoute(request: Request, opts?: {
916
+ routeId?: string;
917
+ requestContext?: unknown;
918
+ dataStrategy?: DataStrategyFunction<unknown>;
919
+ unstable_respond?: (res: Response) => MaybePromise<Response>;
920
+ }): Promise<any>;
921
+ }
922
+ type ViewTransitionOpts = {
923
+ currentLocation: Location;
924
+ nextLocation: Location;
925
+ };
926
+ /**
927
+ * Subscriber function signature for changes to router state
928
+ */
929
+ interface RouterSubscriber {
930
+ (state: RouterState, opts: {
931
+ deletedFetchers: string[];
932
+ viewTransitionOpts?: ViewTransitionOpts;
933
+ flushSync: boolean;
934
+ }): void;
935
+ }
936
+ /**
937
+ * Function signature for determining the key to be used in scroll restoration
938
+ * for a given location
939
+ */
940
+ interface GetScrollRestorationKeyFunction {
941
+ (location: Location, matches: UIMatch[]): string | null;
942
+ }
943
+ /**
944
+ * Function signature for determining the current scroll position
945
+ */
946
+ interface GetScrollPositionFunction {
947
+ (): number;
948
+ }
949
+ /**
950
+ - "route": relative to the route hierarchy so `..` means remove all segments of the current route even if it has many. For example, a `route("posts/:id")` would have both `:id` and `posts` removed from the url.
951
+ - "path": relative to the pathname so `..` means remove one segment of the pathname. For example, a `route("posts/:id")` would have only `:id` removed from the url.
952
+ */
953
+ type RelativeRoutingType = "route" | "path";
954
+ type BaseNavigateOrFetchOptions = {
955
+ preventScrollReset?: boolean;
956
+ relative?: RelativeRoutingType;
957
+ flushSync?: boolean;
958
+ };
959
+ type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
960
+ replace?: boolean;
961
+ state?: any;
962
+ fromRouteId?: string;
963
+ viewTransition?: boolean;
964
+ };
965
+ type BaseSubmissionOptions = {
966
+ formMethod?: HTMLFormMethod;
967
+ formEncType?: FormEncType;
968
+ } & ({
969
+ formData: FormData;
970
+ body?: undefined;
971
+ } | {
972
+ formData?: undefined;
973
+ body: any;
974
+ });
975
+ /**
976
+ * Options for a navigate() call for a normal (non-submission) navigation
977
+ */
978
+ type LinkNavigateOptions = BaseNavigateOptions;
979
+ /**
980
+ * Options for a navigate() call for a submission navigation
981
+ */
982
+ type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
983
+ /**
984
+ * Options to pass to navigate() for a navigation
985
+ */
986
+ type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
987
+ /**
988
+ * Options for a fetch() load
989
+ */
990
+ type LoadFetchOptions = BaseNavigateOrFetchOptions;
991
+ /**
992
+ * Options for a fetch() submission
993
+ */
994
+ type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
995
+ /**
996
+ * Options to pass to fetch()
997
+ */
998
+ type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
999
+ /**
1000
+ * Potential states for state.navigation
1001
+ */
1002
+ type NavigationStates = {
1003
+ Idle: {
1004
+ state: "idle";
1005
+ location: undefined;
1006
+ formMethod: undefined;
1007
+ formAction: undefined;
1008
+ formEncType: undefined;
1009
+ formData: undefined;
1010
+ json: undefined;
1011
+ text: undefined;
1012
+ };
1013
+ Loading: {
1014
+ state: "loading";
1015
+ location: Location;
1016
+ formMethod: Submission["formMethod"] | undefined;
1017
+ formAction: Submission["formAction"] | undefined;
1018
+ formEncType: Submission["formEncType"] | undefined;
1019
+ formData: Submission["formData"] | undefined;
1020
+ json: Submission["json"] | undefined;
1021
+ text: Submission["text"] | undefined;
1022
+ };
1023
+ Submitting: {
1024
+ state: "submitting";
1025
+ location: Location;
1026
+ formMethod: Submission["formMethod"];
1027
+ formAction: Submission["formAction"];
1028
+ formEncType: Submission["formEncType"];
1029
+ formData: Submission["formData"];
1030
+ json: Submission["json"];
1031
+ text: Submission["text"];
1032
+ };
1033
+ };
1034
+ type Navigation = NavigationStates[keyof NavigationStates];
1035
+ type RevalidationState = "idle" | "loading";
1036
+ /**
1037
+ * Potential states for fetchers
1038
+ */
1039
+ type FetcherStates<TData = any> = {
1040
+ /**
1041
+ * The fetcher is not calling a loader or action
1042
+ *
1043
+ * ```tsx
1044
+ * fetcher.state === "idle"
1045
+ * ```
1046
+ */
1047
+ Idle: {
1048
+ state: "idle";
1049
+ formMethod: undefined;
1050
+ formAction: undefined;
1051
+ formEncType: undefined;
1052
+ text: undefined;
1053
+ formData: undefined;
1054
+ json: undefined;
1055
+ /**
1056
+ * If the fetcher has never been called, this will be undefined.
1057
+ */
1058
+ data: TData | undefined;
1059
+ };
1060
+ /**
1061
+ * The fetcher is loading data from a {@link LoaderFunction | loader} from a
1062
+ * call to {@link FetcherWithComponents.load | `fetcher.load`}.
1063
+ *
1064
+ * ```tsx
1065
+ * // somewhere
1066
+ * <button onClick={() => fetcher.load("/some/route") }>Load</button>
1067
+ *
1068
+ * // the state will update
1069
+ * fetcher.state === "loading"
1070
+ * ```
1071
+ */
1072
+ Loading: {
1073
+ state: "loading";
1074
+ formMethod: Submission["formMethod"] | undefined;
1075
+ formAction: Submission["formAction"] | undefined;
1076
+ formEncType: Submission["formEncType"] | undefined;
1077
+ text: Submission["text"] | undefined;
1078
+ formData: Submission["formData"] | undefined;
1079
+ json: Submission["json"] | undefined;
1080
+ data: TData | undefined;
1081
+ };
1082
+ /**
1083
+ The fetcher is submitting to a {@link LoaderFunction} (GET) or {@link ActionFunction} (POST) from a {@link FetcherWithComponents.Form | `fetcher.Form`} or {@link FetcherWithComponents.submit | `fetcher.submit`}.
1084
+
1085
+ ```tsx
1086
+ // somewhere
1087
+ <input
1088
+ onChange={e => {
1089
+ fetcher.submit(event.currentTarget.form, { method: "post" });
1090
+ }}
1091
+ />
1092
+
1093
+ // the state will update
1094
+ fetcher.state === "submitting"
1095
+
1096
+ // and formData will be available
1097
+ fetcher.formData
1098
+ ```
1099
+ */
1100
+ Submitting: {
1101
+ state: "submitting";
1102
+ formMethod: Submission["formMethod"];
1103
+ formAction: Submission["formAction"];
1104
+ formEncType: Submission["formEncType"];
1105
+ text: Submission["text"];
1106
+ formData: Submission["formData"];
1107
+ json: Submission["json"];
1108
+ data: TData | undefined;
1109
+ };
1110
+ };
1111
+ type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
1112
+ interface BlockerBlocked {
1113
+ state: "blocked";
1114
+ reset: () => void;
1115
+ proceed: () => void;
1116
+ location: Location;
1117
+ }
1118
+ interface BlockerUnblocked {
1119
+ state: "unblocked";
1120
+ reset: undefined;
1121
+ proceed: undefined;
1122
+ location: undefined;
1123
+ }
1124
+ interface BlockerProceeding {
1125
+ state: "proceeding";
1126
+ reset: undefined;
1127
+ proceed: undefined;
1128
+ location: Location;
1129
+ }
1130
+ type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1131
+ type BlockerFunction = (args: {
1132
+ currentLocation: Location;
1133
+ nextLocation: Location;
1134
+ historyAction: Action;
1135
+ }) => boolean;
1136
+ interface CreateStaticHandlerOptions {
1137
+ basename?: string;
1138
+ mapRouteProperties?: MapRoutePropertiesFunction;
1139
+ future?: {};
1140
+ }
1141
+ declare function createStaticHandler(routes: AgnosticRouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
1142
+
1143
+ interface IndexRouteObject {
1144
+ caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
1145
+ path?: AgnosticIndexRouteObject["path"];
1146
+ id?: AgnosticIndexRouteObject["id"];
1147
+ unstable_middleware?: AgnosticIndexRouteObject["unstable_middleware"];
1148
+ loader?: AgnosticIndexRouteObject["loader"];
1149
+ action?: AgnosticIndexRouteObject["action"];
1150
+ hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
1151
+ shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
1152
+ handle?: AgnosticIndexRouteObject["handle"];
1153
+ index: true;
1154
+ children?: undefined;
1155
+ element?: React.ReactNode | null;
1156
+ hydrateFallbackElement?: React.ReactNode | null;
1157
+ errorElement?: React.ReactNode | null;
1158
+ Component?: React.ComponentType | null;
1159
+ HydrateFallback?: React.ComponentType | null;
1160
+ ErrorBoundary?: React.ComponentType | null;
1161
+ lazy?: LazyRouteDefinition<RouteObject>;
1162
+ }
1163
+ interface NonIndexRouteObject {
1164
+ caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
1165
+ path?: AgnosticNonIndexRouteObject["path"];
1166
+ id?: AgnosticNonIndexRouteObject["id"];
1167
+ unstable_middleware?: AgnosticNonIndexRouteObject["unstable_middleware"];
1168
+ loader?: AgnosticNonIndexRouteObject["loader"];
1169
+ action?: AgnosticNonIndexRouteObject["action"];
1170
+ hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
1171
+ shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
1172
+ handle?: AgnosticNonIndexRouteObject["handle"];
1173
+ index?: false;
1174
+ children?: RouteObject[];
1175
+ element?: React.ReactNode | null;
1176
+ hydrateFallbackElement?: React.ReactNode | null;
1177
+ errorElement?: React.ReactNode | null;
1178
+ Component?: React.ComponentType | null;
1179
+ HydrateFallback?: React.ComponentType | null;
1180
+ ErrorBoundary?: React.ComponentType | null;
1181
+ lazy?: LazyRouteDefinition<RouteObject>;
1182
+ }
1183
+ type RouteObject = IndexRouteObject | NonIndexRouteObject;
1184
+ type DataRouteObject = RouteObject & {
1185
+ children?: DataRouteObject[];
1186
+ id: string;
1187
+ };
1188
+ interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
1189
+ }
1190
+ interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
1191
+ }
1192
+
1193
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1194
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1195
+ interface HtmlLinkProps {
1196
+ /**
1197
+ * Address of the hyperlink
1198
+ */
1199
+ href?: string;
1200
+ /**
1201
+ * How the element handles crossorigin requests
1202
+ */
1203
+ crossOrigin?: "anonymous" | "use-credentials";
1204
+ /**
1205
+ * Relationship between the document containing the hyperlink and the destination resource
1206
+ */
1207
+ rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
1208
+ /**
1209
+ * Applicable media: "screen", "print", "(max-width: 764px)"
1210
+ */
1211
+ media?: string;
1212
+ /**
1213
+ * Integrity metadata used in Subresource Integrity checks
1214
+ */
1215
+ integrity?: string;
1216
+ /**
1217
+ * Language of the linked resource
1218
+ */
1219
+ hrefLang?: string;
1220
+ /**
1221
+ * Hint for the type of the referenced resource
1222
+ */
1223
+ type?: string;
1224
+ /**
1225
+ * Referrer policy for fetches initiated by the element
1226
+ */
1227
+ referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
1228
+ /**
1229
+ * Sizes of the icons (for rel="icon")
1230
+ */
1231
+ sizes?: string;
1232
+ /**
1233
+ * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1234
+ */
1235
+ as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
1236
+ /**
1237
+ * Color to use when customizing a site's icon (for rel="mask-icon")
1238
+ */
1239
+ color?: string;
1240
+ /**
1241
+ * Whether the link is disabled
1242
+ */
1243
+ disabled?: boolean;
1244
+ /**
1245
+ * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
1246
+ */
1247
+ title?: string;
1248
+ /**
1249
+ * Images to use in different situations, e.g., high-resolution displays,
1250
+ * small monitors, etc. (for rel="preload")
1251
+ */
1252
+ imageSrcSet?: string;
1253
+ /**
1254
+ * Image sizes for different page layouts (for rel="preload")
1255
+ */
1256
+ imageSizes?: string;
1257
+ }
1258
+ interface HtmlLinkPreloadImage extends HtmlLinkProps {
1259
+ /**
1260
+ * Relationship between the document containing the hyperlink and the destination resource
1261
+ */
1262
+ rel: "preload";
1263
+ /**
1264
+ * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1265
+ */
1266
+ as: "image";
1267
+ /**
1268
+ * Address of the hyperlink
1269
+ */
1270
+ href?: string;
1271
+ /**
1272
+ * Images to use in different situations, e.g., high-resolution displays,
1273
+ * small monitors, etc. (for rel="preload")
1274
+ */
1275
+ imageSrcSet: string;
1276
+ /**
1277
+ * Image sizes for different page layouts (for rel="preload")
1278
+ */
1279
+ imageSizes?: string;
1280
+ }
1281
+ /**
1282
+ * Represents a `<link>` element.
1283
+ *
1284
+ * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
1285
+ */
1286
+ type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
1287
+ imageSizes?: never;
1288
+ });
1289
+ interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1290
+ /**
1291
+ * The absolute path of the page to prefetch.
1292
+ */
1293
+ page: string;
1294
+ }
1295
+ type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1296
+
1297
+ type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1298
+ [key: PropertyKey]: Serializable;
1299
+ } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
1300
+
1301
+ type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
1302
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1303
+ type Func = (...args: any[]) => unknown;
1304
+
1305
+ /**
1306
+ * A brand that can be applied to a type to indicate that it will serialize
1307
+ * to a specific type when transported to the client from a loader.
1308
+ * Only use this if you have additional serialization/deserialization logic
1309
+ * in your application.
1310
+ */
1311
+ type unstable_SerializesTo<T> = {
1312
+ unstable__ReactRouter_SerializesTo: [T];
1313
+ };
1314
+
1315
+ type Serialize<T> = T extends unstable_SerializesTo<infer To> ? To : T extends Serializable ? T : T extends (...args: any[]) => unknown ? undefined : T extends Promise<infer U> ? Promise<Serialize<U>> : T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [Serialize<F>, ...Serialize<R>] : T extends Array<infer U> ? Array<Serialize<U>> : T extends readonly unknown[] ? readonly Serialize<T[number]>[] : T extends Record<any, any> ? {
1316
+ [K in keyof T]: Serialize<T[K]>;
1317
+ } : undefined;
1318
+ type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1319
+ type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1320
+ type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1321
+ type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1322
+ type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1323
+ type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1324
+ type ClientDataFunctionArgs<Params> = {
1325
+ /**
1326
+ * A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
1327
+ *
1328
+ * @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
1329
+ **/
1330
+ request: Request;
1331
+ /**
1332
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
1333
+ * @example
1334
+ * // app/routes.ts
1335
+ * route("teams/:teamId", "./team.tsx"),
1336
+ *
1337
+ * // app/team.tsx
1338
+ * export function clientLoader({
1339
+ * params,
1340
+ * }: Route.ClientLoaderArgs) {
1341
+ * params.teamId;
1342
+ * // ^ string
1343
+ * }
1344
+ **/
1345
+ params: Params;
1346
+ /**
1347
+ * When `future.unstable_middleware` is not enabled, this is undefined.
1348
+ *
1349
+ * When `future.unstable_middleware` is enabled, this is an instance of
1350
+ * `unstable_RouterContextProvider` and can be used to access context values
1351
+ * from your route middlewares. You may pass in initial context values in your
1352
+ * `<HydratedRouter unstable_getContext>` prop
1353
+ */
1354
+ context: unstable_RouterContextProvider;
1355
+ };
1356
+ type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
1357
+ ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
1358
+ ] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1359
+
1360
+ /**
1361
+ * A function that handles data mutations for a route on the client
1362
+ */
1363
+ type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
1364
+ /**
1365
+ * Arguments passed to a route `clientAction` function
1366
+ */
1367
+ type ClientActionFunctionArgs = ActionFunctionArgs & {
1368
+ serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1369
+ };
1370
+ /**
1371
+ * A function that loads data for a route on the client
1372
+ */
1373
+ type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
1374
+ hydrate?: boolean;
1375
+ };
1376
+ /**
1377
+ * Arguments passed to a route `clientLoader` function
1378
+ */
1379
+ type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1380
+ serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1381
+ };
1382
+ type HeadersArgs = {
1383
+ loaderHeaders: Headers;
1384
+ parentHeaders: Headers;
1385
+ actionHeaders: Headers;
1386
+ errorHeaders: Headers | undefined;
1387
+ };
1388
+ /**
1389
+ * A function that returns HTTP headers to be used for a route. These headers
1390
+ * will be merged with (and take precedence over) headers from parent routes.
1391
+ */
1392
+ interface HeadersFunction {
1393
+ (args: HeadersArgs): Headers | HeadersInit;
1394
+ }
1395
+ /**
1396
+ * A function that defines `<link>` tags to be inserted into the `<head>` of
1397
+ * the document on route transitions.
1398
+ *
1399
+ * @see https://remix.run/route/meta
1400
+ */
1401
+ interface LinksFunction {
1402
+ (): LinkDescriptor[];
1403
+ }
1404
+ interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1405
+ id: RouteId;
1406
+ pathname: DataRouteMatch["pathname"];
1407
+ data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1408
+ handle?: RouteHandle;
1409
+ params: DataRouteMatch["params"];
1410
+ meta: MetaDescriptor[];
1411
+ error?: unknown;
1412
+ }
1413
+ type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
1414
+ [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1415
+ }[keyof MatchLoaders]>;
1416
+ interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1417
+ data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1418
+ params: Params;
1419
+ location: Location;
1420
+ matches: MetaMatches<MatchLoaders>;
1421
+ error?: unknown;
1422
+ }
1423
+ /**
1424
+ * A function that returns an array of data objects to use for rendering
1425
+ * metadata HTML tags in a route. These tags are not rendered on descendant
1426
+ * routes in the route hierarchy. In other words, they will only be rendered on
1427
+ * the route in which they are exported.
1428
+ *
1429
+ * @param Loader - The type of the current route's loader function
1430
+ * @param MatchLoaders - Mapping from a parent route's filepath to its loader
1431
+ * function type
1432
+ *
1433
+ * Note that parent route filepaths are relative to the `app/` directory.
1434
+ *
1435
+ * For example, if this meta function is for `/sales/customers/$customerId`:
1436
+ *
1437
+ * ```ts
1438
+ * // app/root.tsx
1439
+ * const loader = () => ({ hello: "world" })
1440
+ * export type Loader = typeof loader
1441
+ *
1442
+ * // app/routes/sales.tsx
1443
+ * const loader = () => ({ salesCount: 1074 })
1444
+ * export type Loader = typeof loader
1445
+ *
1446
+ * // app/routes/sales/customers.tsx
1447
+ * const loader = () => ({ customerCount: 74 })
1448
+ * export type Loader = typeof loader
1449
+ *
1450
+ * // app/routes/sales/customers/$customersId.tsx
1451
+ * import type { Loader as RootLoader } from "../../../root"
1452
+ * import type { Loader as SalesLoader } from "../../sales"
1453
+ * import type { Loader as CustomersLoader } from "../../sales/customers"
1454
+ *
1455
+ * const loader = () => ({ name: "Customer name" })
1456
+ *
1457
+ * const meta: MetaFunction<typeof loader, {
1458
+ * "root": RootLoader,
1459
+ * "routes/sales": SalesLoader,
1460
+ * "routes/sales/customers": CustomersLoader,
1461
+ * }> = ({ data, matches }) => {
1462
+ * const { name } = data
1463
+ * // ^? string
1464
+ * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
1465
+ * // ^? number
1466
+ * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
1467
+ * // ^? number
1468
+ * const { hello } = matches.find((match) => match.id === "root").data
1469
+ * // ^? "world"
1470
+ * }
1471
+ * ```
1472
+ */
1473
+ interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1474
+ (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
1475
+ }
1476
+ type MetaDescriptor = {
1477
+ charSet: "utf-8";
1478
+ } | {
1479
+ title: string;
1480
+ } | {
1481
+ name: string;
1482
+ content: string;
1483
+ } | {
1484
+ property: string;
1485
+ content: string;
1486
+ } | {
1487
+ httpEquiv: string;
1488
+ content: string;
1489
+ } | {
1490
+ "script:ld+json": LdJsonObject;
1491
+ } | {
1492
+ tagName: "meta" | "link";
1493
+ [name: string]: string;
1494
+ } | {
1495
+ [name: string]: unknown;
1496
+ };
1497
+ type LdJsonObject = {
1498
+ [Key in string]: LdJsonValue;
1499
+ } & {
1500
+ [Key in string]?: LdJsonValue | undefined;
1501
+ };
1502
+ type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
1503
+ type LdJsonPrimitive = string | number | boolean | null;
1504
+ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
1505
+ /**
1506
+ * An arbitrary object that is associated with a route.
1507
+ *
1508
+ * @see https://remix.run/route/handle
1509
+ */
1510
+ type RouteHandle = unknown;
1511
+
1512
+ type ServerContext = {
1513
+ redirect?: Response;
1514
+ };
1515
+ declare global {
1516
+ var ___reactRouterServerStorage___: AsyncLocalStorage<ServerContext> | undefined;
1517
+ }
1518
+ declare const redirect: typeof redirect$1;
1519
+ declare const redirectDocument: typeof redirectDocument$1;
1520
+ declare const replace: typeof replace$1;
1521
+ type RSCRouteConfigEntryBase = {
1522
+ action?: ActionFunction;
1523
+ clientAction?: ClientActionFunction;
1524
+ clientLoader?: ClientLoaderFunction;
1525
+ ErrorBoundary?: React.ComponentType<any>;
1526
+ handle?: any;
1527
+ headers?: HeadersFunction;
1528
+ HydrateFallback?: React.ComponentType<any>;
1529
+ Layout?: React.ComponentType<any>;
1530
+ links?: LinksFunction;
1531
+ loader?: LoaderFunction;
1532
+ meta?: MetaFunction;
1533
+ shouldRevalidate?: ShouldRevalidateFunction;
1534
+ };
1535
+ type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
1536
+ id: string;
1537
+ path?: string;
1538
+ Component?: React.ComponentType<any>;
1539
+ lazy?: () => Promise<RSCRouteConfigEntryBase & ({
1540
+ default?: React.ComponentType<any>;
1541
+ Component?: never;
1542
+ } | {
1543
+ default?: never;
1544
+ Component?: React.ComponentType<any>;
1545
+ })>;
1546
+ } & ({
1547
+ index: true;
1548
+ } | {
1549
+ children?: RSCRouteConfigEntry[];
1550
+ });
1551
+ type RSCRouteConfig = Array<RSCRouteConfigEntry>;
1552
+ type RSCRouteManifest = {
1553
+ clientAction?: ClientActionFunction;
1554
+ clientLoader?: ClientLoaderFunction;
1555
+ element?: React.ReactElement | false;
1556
+ errorElement?: React.ReactElement;
1557
+ handle?: any;
1558
+ hasAction: boolean;
1559
+ hasComponent: boolean;
1560
+ hasErrorBoundary: boolean;
1561
+ hasLoader: boolean;
1562
+ hydrateFallbackElement?: React.ReactElement;
1563
+ id: string;
1564
+ index?: boolean;
1565
+ links?: LinksFunction;
1566
+ meta?: MetaFunction;
1567
+ parentId?: string;
1568
+ path?: string;
1569
+ shouldRevalidate?: ShouldRevalidateFunction;
1570
+ };
1571
+ type RSCRouteMatch = RSCRouteManifest & {
1572
+ params: Params;
1573
+ pathname: string;
1574
+ pathnameBase: string;
1575
+ };
1576
+ type RSCRenderPayload = {
1577
+ type: "render";
1578
+ actionData: Record<string, any> | null;
1579
+ basename: string | undefined;
1580
+ errors: Record<string, any> | null;
1581
+ loaderData: Record<string, any>;
1582
+ location: Location;
1583
+ matches: RSCRouteMatch[];
1584
+ patches?: RSCRouteManifest[];
1585
+ nonce?: string;
1586
+ formState?: unknown;
1587
+ };
1588
+ type RSCManifestPayload = {
1589
+ type: "manifest";
1590
+ patches: RSCRouteManifest[];
1591
+ };
1592
+ type RSCActionPayload = {
1593
+ type: "action";
1594
+ actionResult: Promise<unknown>;
1595
+ rerender?: Promise<RSCRenderPayload | RSCRedirectPayload>;
1596
+ };
1597
+ type RSCRedirectPayload = {
1598
+ type: "redirect";
1599
+ status: number;
1600
+ location: string;
1601
+ replace: boolean;
1602
+ reload: boolean;
1603
+ actionResult?: Promise<unknown>;
1604
+ };
1605
+ type RSCPayload = RSCRenderPayload | RSCManifestPayload | RSCActionPayload | RSCRedirectPayload;
1606
+ type RSCMatch = {
1607
+ statusCode: number;
1608
+ headers: Headers;
1609
+ payload: RSCPayload;
1610
+ };
1611
+ type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
1612
+ type DecodeFormStateFunction = (result: unknown, formData: FormData) => unknown;
1613
+ type DecodeReplyFunction = (reply: FormData | string, { temporaryReferences }: {
1614
+ temporaryReferences: unknown;
1615
+ }) => Promise<unknown[]>;
1616
+ type LoadServerActionFunction = (id: string) => Promise<Function>;
1617
+ declare function matchRSCServerRequest({ createTemporaryReferenceSet, basename, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
1618
+ createTemporaryReferenceSet: () => unknown;
1619
+ basename?: string;
1620
+ decodeReply?: DecodeReplyFunction;
1621
+ decodeAction?: DecodeActionFunction;
1622
+ decodeFormState?: DecodeFormStateFunction;
1623
+ requestContext?: unstable_RouterContextProvider;
1624
+ loadServerAction?: LoadServerActionFunction;
1625
+ onError?: (error: unknown) => void;
1626
+ request: Request;
1627
+ routes: RSCRouteConfigEntry[];
1628
+ generateResponse: (match: RSCMatch, { temporaryReferences, }: {
1629
+ temporaryReferences: unknown;
1630
+ }) => Response;
1631
+ }): Promise<Response>;
1632
+
1633
+ interface CookieSignatureOptions {
1634
+ /**
1635
+ * An array of secrets that may be used to sign/unsign the value of a cookie.
1636
+ *
1637
+ * The array makes it easy to rotate secrets. New secrets should be added to
1638
+ * the beginning of the array. `cookie.serialize()` will always use the first
1639
+ * value in the array, but `cookie.parse()` may use any of them so that
1640
+ * cookies that were signed with older secrets still work.
1641
+ */
1642
+ secrets?: string[];
1643
+ }
1644
+ type CookieOptions = ParseOptions & SerializeOptions & CookieSignatureOptions;
1645
+ /**
1646
+ * A HTTP cookie.
1647
+ *
1648
+ * A Cookie is a logical container for metadata about a HTTP cookie; its name
1649
+ * and options. But it doesn't contain a value. Instead, it has `parse()` and
1650
+ * `serialize()` methods that allow a single instance to be reused for
1651
+ * parsing/encoding multiple different values.
1652
+ *
1653
+ * @see https://remix.run/utils/cookies#cookie-api
1654
+ */
1655
+ interface Cookie {
1656
+ /**
1657
+ * The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
1658
+ */
1659
+ readonly name: string;
1660
+ /**
1661
+ * True if this cookie uses one or more secrets for verification.
1662
+ */
1663
+ readonly isSigned: boolean;
1664
+ /**
1665
+ * The Date this cookie expires.
1666
+ *
1667
+ * Note: This is calculated at access time using `maxAge` when no `expires`
1668
+ * option is provided to `createCookie()`.
1669
+ */
1670
+ readonly expires?: Date;
1671
+ /**
1672
+ * Parses a raw `Cookie` header and returns the value of this cookie or
1673
+ * `null` if it's not present.
1674
+ */
1675
+ parse(cookieHeader: string | null, options?: ParseOptions): Promise<any>;
1676
+ /**
1677
+ * Serializes the given value to a string and returns the `Set-Cookie`
1678
+ * header.
1679
+ */
1680
+ serialize(value: any, options?: SerializeOptions): Promise<string>;
1681
+ }
1682
+ /**
1683
+ * Creates a logical container for managing a browser cookie from the server.
1684
+ */
1685
+ declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
1686
+ type IsCookieFunction = (object: any) => object is Cookie;
1687
+ /**
1688
+ * Returns true if an object is a Remix cookie container.
1689
+ *
1690
+ * @see https://remix.run/utils/cookies#iscookie
1691
+ */
1692
+ declare const isCookie: IsCookieFunction;
1693
+
1694
+ /**
1695
+ * An object of name/value pairs to be used in the session.
1696
+ */
1697
+ interface SessionData {
1698
+ [name: string]: any;
1699
+ }
1700
+ /**
1701
+ * Session persists data across HTTP requests.
1702
+ *
1703
+ * @see https://reactrouter.com/explanation/sessions-and-cookies#sessions
1704
+ */
1705
+ interface Session<Data = SessionData, FlashData = Data> {
1706
+ /**
1707
+ * A unique identifier for this session.
1708
+ *
1709
+ * Note: This will be the empty string for newly created sessions and
1710
+ * sessions that are not backed by a database (i.e. cookie-based sessions).
1711
+ */
1712
+ readonly id: string;
1713
+ /**
1714
+ * The raw data contained in this session.
1715
+ *
1716
+ * This is useful mostly for SessionStorage internally to access the raw
1717
+ * session data to persist.
1718
+ */
1719
+ readonly data: FlashSessionData<Data, FlashData>;
1720
+ /**
1721
+ * Returns `true` if the session has a value for the given `name`, `false`
1722
+ * otherwise.
1723
+ */
1724
+ has(name: (keyof Data | keyof FlashData) & string): boolean;
1725
+ /**
1726
+ * Returns the value for the given `name` in this session.
1727
+ */
1728
+ get<Key extends (keyof Data | keyof FlashData) & string>(name: Key): (Key extends keyof Data ? Data[Key] : undefined) | (Key extends keyof FlashData ? FlashData[Key] : undefined) | undefined;
1729
+ /**
1730
+ * Sets a value in the session for the given `name`.
1731
+ */
1732
+ set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
1733
+ /**
1734
+ * Sets a value in the session that is only valid until the next `get()`.
1735
+ * This can be useful for temporary values, like error messages.
1736
+ */
1737
+ flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
1738
+ /**
1739
+ * Removes a value from the session.
1740
+ */
1741
+ unset(name: keyof Data & string): void;
1742
+ }
1743
+ type FlashSessionData<Data, FlashData> = Partial<Data & {
1744
+ [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key];
1745
+ }>;
1746
+ type FlashDataKey<Key extends string> = `__flash_${Key}__`;
1747
+ type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
1748
+ /**
1749
+ * Creates a new Session object.
1750
+ *
1751
+ * Note: This function is typically not invoked directly by application code.
1752
+ * Instead, use a `SessionStorage` object's `getSession` method.
1753
+ */
1754
+ declare const createSession: CreateSessionFunction;
1755
+ type IsSessionFunction = (object: any) => object is Session;
1756
+ /**
1757
+ * Returns true if an object is a React Router session.
1758
+ *
1759
+ * @see https://reactrouter.com/api/utils/isSession
1760
+ */
1761
+ declare const isSession: IsSessionFunction;
1762
+ /**
1763
+ * SessionStorage stores session data between HTTP requests and knows how to
1764
+ * parse and create cookies.
1765
+ *
1766
+ * A SessionStorage creates Session objects using a `Cookie` header as input.
1767
+ * Then, later it generates the `Set-Cookie` header to be used in the response.
1768
+ */
1769
+ interface SessionStorage<Data = SessionData, FlashData = Data> {
1770
+ /**
1771
+ * Parses a Cookie header from a HTTP request and returns the associated
1772
+ * Session. If there is no session associated with the cookie, this will
1773
+ * return a new Session with no data.
1774
+ */
1775
+ getSession: (cookieHeader?: string | null, options?: ParseOptions) => Promise<Session<Data, FlashData>>;
1776
+ /**
1777
+ * Stores all data in the Session and returns the Set-Cookie header to be
1778
+ * used in the HTTP response.
1779
+ */
1780
+ commitSession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
1781
+ /**
1782
+ * Deletes all data associated with the Session and returns the Set-Cookie
1783
+ * header to be used in the HTTP response.
1784
+ */
1785
+ destroySession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
1786
+ }
1787
+ /**
1788
+ * SessionIdStorageStrategy is designed to allow anyone to easily build their
1789
+ * own SessionStorage using `createSessionStorage(strategy)`.
1790
+ *
1791
+ * This strategy describes a common scenario where the session id is stored in
1792
+ * a cookie but the actual session data is stored elsewhere, usually in a
1793
+ * database or on disk. A set of create, read, update, and delete operations
1794
+ * are provided for managing the session data.
1795
+ */
1796
+ interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
1797
+ /**
1798
+ * The Cookie used to store the session id, or options used to automatically
1799
+ * create one.
1800
+ */
1801
+ cookie?: Cookie | (CookieOptions & {
1802
+ name?: string;
1803
+ });
1804
+ /**
1805
+ * Creates a new record with the given data and returns the session id.
1806
+ */
1807
+ createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
1808
+ /**
1809
+ * Returns data for a given session id, or `null` if there isn't any.
1810
+ */
1811
+ readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
1812
+ /**
1813
+ * Updates data for the given session id.
1814
+ */
1815
+ updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
1816
+ /**
1817
+ * Deletes data for a given session id from the data store.
1818
+ */
1819
+ deleteData: (id: string) => Promise<void>;
1820
+ }
1821
+ /**
1822
+ * Creates a SessionStorage object using a SessionIdStorageStrategy.
1823
+ *
1824
+ * Note: This is a low-level API that should only be used if none of the
1825
+ * existing session storage options meet your requirements.
1826
+ */
1827
+ declare function createSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg, createData, readData, updateData, deleteData, }: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
1828
+
1829
+ interface CookieSessionStorageOptions {
1830
+ /**
1831
+ * The Cookie used to store the session data on the client, or options used
1832
+ * to automatically create one.
1833
+ */
1834
+ cookie?: SessionIdStorageStrategy["cookie"];
1835
+ }
1836
+ /**
1837
+ * Creates and returns a SessionStorage object that stores all session data
1838
+ * directly in the session cookie itself.
1839
+ *
1840
+ * This has the advantage that no database or other backend services are
1841
+ * needed, and can help to simplify some load-balanced scenarios. However, it
1842
+ * also has the limitation that serialized session data may not exceed the
1843
+ * browser's maximum cookie size. Trade-offs!
1844
+ */
1845
+ declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg }?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
1846
+
1847
+ interface MemorySessionStorageOptions {
1848
+ /**
1849
+ * The Cookie used to store the session id on the client, or options used
1850
+ * to automatically create one.
1851
+ */
1852
+ cookie?: SessionIdStorageStrategy["cookie"];
1853
+ }
1854
+ /**
1855
+ * Creates and returns a simple in-memory SessionStorage object, mostly useful
1856
+ * for testing and as a reference implementation.
1857
+ *
1858
+ * Note: This storage does not scale beyond a single process, so it is not
1859
+ * suitable for most production scenarios.
1860
+ */
1861
+ declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({ cookie }?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
1862
+
1863
+ export { type Cookie, type CookieOptions, type CookieSignatureOptions, type FlashSessionData, type IsCookieFunction, type IsSessionFunction, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, createStaticHandler, data, isCookie, isSession, matchRoutes, redirect, redirectDocument, replace, type DecodeActionFunction as unstable_DecodeActionFunction, type DecodeFormStateFunction as unstable_DecodeFormStateFunction, type DecodeReplyFunction as unstable_DecodeReplyFunction, type LoadServerActionFunction as unstable_LoadServerActionFunction, type unstable_MiddlewareFunction, type unstable_MiddlewareNextFunction, type RSCManifestPayload as unstable_RSCManifestPayload, type RSCMatch as unstable_RSCMatch, type RSCPayload as unstable_RSCPayload, type RSCRenderPayload as unstable_RSCRenderPayload, type RSCRouteConfig as unstable_RSCRouteConfig, type RSCRouteConfigEntry as unstable_RSCRouteConfigEntry, type RSCRouteManifest as unstable_RSCRouteManifest, type RSCRouteMatch as unstable_RSCRouteMatch, type unstable_RouterContext, unstable_RouterContextProvider, unstable_createContext, matchRSCServerRequest as unstable_matchRSCServerRequest };