react-router 0.0.0-experimental-e5dac68cb → 0.0.0-experimental-7a7fadb20

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