react-router 6.26.2 → 7.0.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 (84) hide show
  1. package/CHANGELOG.md +307 -0
  2. package/README.md +1 -14
  3. package/dist/dom-export.d.ts +3 -0
  4. package/dist/dom-export.mjs +205 -0
  5. package/dist/dom-export.mjs.map +1 -0
  6. package/dist/index.d.ts +74 -29
  7. package/dist/index.mjs +11551 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/lib/components.d.ts +250 -35
  10. package/dist/lib/context.d.ts +20 -7
  11. package/dist/lib/dom/dom.d.ts +123 -0
  12. package/dist/lib/dom/global.d.ts +40 -0
  13. package/dist/lib/dom/lib.d.ts +940 -0
  14. package/dist/lib/dom/server.d.ts +41 -0
  15. package/dist/lib/dom/ssr/components.d.ts +123 -0
  16. package/dist/lib/dom/ssr/data.d.ts +7 -0
  17. package/dist/lib/dom/ssr/entry.d.ts +47 -0
  18. package/dist/lib/dom/ssr/errorBoundaries.d.ts +36 -0
  19. package/dist/lib/dom/ssr/errors.d.ts +2 -0
  20. package/dist/lib/dom/ssr/fallback.d.ts +2 -0
  21. package/dist/lib/dom/ssr/fog-of-war.d.ts +28 -0
  22. package/dist/lib/dom/ssr/invariant.d.ts +2 -0
  23. package/dist/lib/dom/ssr/links.d.ts +25 -0
  24. package/dist/lib/dom/ssr/markup.d.ts +5 -0
  25. package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
  26. package/dist/lib/dom/ssr/routes-test-stub.d.ts +59 -0
  27. package/dist/lib/dom/ssr/routes.d.ts +32 -0
  28. package/dist/lib/dom/ssr/server.d.ts +16 -0
  29. package/dist/lib/dom/ssr/single-fetch.d.ts +37 -0
  30. package/dist/lib/dom-export/dom-router-provider.d.ts +5 -0
  31. package/dist/lib/dom-export/hydrated-router.d.ts +5 -0
  32. package/dist/lib/dom-export.d.ts +3 -0
  33. package/dist/lib/hooks.d.ts +286 -57
  34. package/dist/lib/router/history.d.ts +253 -0
  35. package/dist/lib/router/links.d.ts +104 -0
  36. package/dist/lib/router/router.d.ts +540 -0
  37. package/dist/lib/router/utils.d.ts +505 -0
  38. package/dist/lib/server-runtime/build.d.ts +38 -0
  39. package/dist/lib/server-runtime/cookies.d.ts +62 -0
  40. package/dist/lib/server-runtime/crypto.d.ts +2 -0
  41. package/dist/lib/server-runtime/data.d.ts +15 -0
  42. package/dist/lib/server-runtime/dev.d.ts +8 -0
  43. package/dist/lib/server-runtime/entry.d.ts +3 -0
  44. package/dist/lib/server-runtime/errors.d.ts +51 -0
  45. package/dist/lib/server-runtime/headers.d.ts +3 -0
  46. package/dist/lib/server-runtime/invariant.d.ts +2 -0
  47. package/dist/lib/server-runtime/jsonify.d.ts +33 -0
  48. package/dist/lib/server-runtime/markup.d.ts +1 -0
  49. package/dist/lib/server-runtime/mode.d.ts +9 -0
  50. package/dist/lib/server-runtime/responses.d.ts +37 -0
  51. package/dist/lib/server-runtime/routeMatching.d.ts +8 -0
  52. package/dist/lib/server-runtime/routeModules.d.ts +212 -0
  53. package/dist/lib/server-runtime/routes.d.ts +31 -0
  54. package/dist/lib/server-runtime/server.d.ts +5 -0
  55. package/dist/lib/server-runtime/serverHandoff.d.ts +11 -0
  56. package/dist/lib/server-runtime/sessions/cookieStorage.d.ts +19 -0
  57. package/dist/lib/server-runtime/sessions/memoryStorage.d.ts +17 -0
  58. package/dist/lib/server-runtime/sessions.d.ts +140 -0
  59. package/dist/lib/server-runtime/single-fetch.d.ts +30 -0
  60. package/dist/lib/server-runtime/typecheck.d.ts +4 -0
  61. package/dist/lib/server-runtime/warnings.d.ts +1 -0
  62. package/dist/lib/types.d.ts +71 -0
  63. package/dist/lib/types.mjs +10 -0
  64. package/dist/main-dom-export.js +19 -0
  65. package/dist/main.js +1 -1
  66. package/dist/react-router-dom.development.js +199 -0
  67. package/dist/react-router-dom.development.js.map +1 -0
  68. package/dist/react-router-dom.production.min.js +12 -0
  69. package/dist/react-router-dom.production.min.js.map +1 -0
  70. package/dist/react-router.development.js +12271 -1129
  71. package/dist/react-router.development.js.map +1 -1
  72. package/dist/react-router.production.min.js +2 -2
  73. package/dist/react-router.production.min.js.map +1 -1
  74. package/dist/umd/react-router-dom.development.js +241 -0
  75. package/dist/umd/react-router-dom.development.js.map +1 -0
  76. package/dist/umd/react-router-dom.production.min.js +12 -0
  77. package/dist/umd/react-router-dom.production.min.js.map +1 -0
  78. package/dist/umd/react-router.development.js +12459 -1224
  79. package/dist/umd/react-router.development.js.map +1 -1
  80. package/dist/umd/react-router.production.min.js +2 -2
  81. package/dist/umd/react-router.production.min.js.map +1 -1
  82. package/package.json +35 -6
  83. package/dist/index.js +0 -1467
  84. package/dist/index.js.map +0 -1
@@ -0,0 +1,505 @@
1
+ import type { Location, Path, To } from "./history";
2
+ /**
3
+ * Map of routeId -> data returned from a loader/action/error
4
+ */
5
+ export interface RouteData {
6
+ [routeId: string]: any;
7
+ }
8
+ export declare enum ResultType {
9
+ data = "data",
10
+ redirect = "redirect",
11
+ error = "error"
12
+ }
13
+ /**
14
+ * Successful result from a loader or action
15
+ */
16
+ export interface SuccessResult {
17
+ type: ResultType.data;
18
+ data: unknown;
19
+ statusCode?: number;
20
+ headers?: Headers;
21
+ }
22
+ /**
23
+ * Redirect result from a loader or action
24
+ */
25
+ export interface RedirectResult {
26
+ type: ResultType.redirect;
27
+ response: Response;
28
+ }
29
+ /**
30
+ * Unsuccessful result from a loader or action
31
+ */
32
+ export interface ErrorResult {
33
+ type: ResultType.error;
34
+ error: unknown;
35
+ statusCode?: number;
36
+ headers?: Headers;
37
+ }
38
+ /**
39
+ * Result from a loader or action - potentially successful or unsuccessful
40
+ */
41
+ export type DataResult = SuccessResult | RedirectResult | ErrorResult;
42
+ export type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
43
+ export type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
44
+ /**
45
+ * Users can specify either lowercase or uppercase form methods on `<Form>`,
46
+ * useSubmit(), `<fetcher.Form>`, etc.
47
+ */
48
+ export type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
49
+ /**
50
+ * Active navigation/fetcher form methods are exposed in uppercase on the
51
+ * RouterState. This is to align with the normalization done via fetch().
52
+ */
53
+ export type FormMethod = UpperCaseFormMethod;
54
+ export type MutationFormMethod = Exclude<FormMethod, "GET">;
55
+ export type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
56
+ type JsonObject = {
57
+ [Key in string]: JsonValue;
58
+ } & {
59
+ [Key in string]?: JsonValue | undefined;
60
+ };
61
+ type JsonArray = JsonValue[] | readonly JsonValue[];
62
+ type JsonPrimitive = string | number | boolean | null;
63
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
64
+ /**
65
+ * @private
66
+ * Internal interface to pass around for action submissions, not intended for
67
+ * external consumption
68
+ */
69
+ export type Submission = {
70
+ formMethod: FormMethod;
71
+ formAction: string;
72
+ formEncType: FormEncType;
73
+ formData: FormData;
74
+ json: undefined;
75
+ text: undefined;
76
+ } | {
77
+ formMethod: FormMethod;
78
+ formAction: string;
79
+ formEncType: FormEncType;
80
+ formData: undefined;
81
+ json: JsonValue;
82
+ text: undefined;
83
+ } | {
84
+ formMethod: FormMethod;
85
+ formAction: string;
86
+ formEncType: FormEncType;
87
+ formData: undefined;
88
+ json: undefined;
89
+ text: string;
90
+ };
91
+ /**
92
+ * @private
93
+ * Arguments passed to route loader/action functions. Same for now but we keep
94
+ * this as a private implementation detail in case they diverge in the future.
95
+ */
96
+ interface DataFunctionArgs<Context> {
97
+ request: Request;
98
+ params: Params;
99
+ context?: Context;
100
+ }
101
+ /**
102
+ * Arguments passed to loader functions
103
+ */
104
+ export interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
105
+ }
106
+ /**
107
+ * Arguments passed to action functions
108
+ */
109
+ export interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
110
+ }
111
+ /**
112
+ * Loaders and actions can return anything except `undefined` (`null` is a
113
+ * valid return value if there is no data to return). Responses are preferred
114
+ * and will ease any future migration to Remix
115
+ */
116
+ type DataFunctionValue = Response | NonNullable<unknown> | null;
117
+ type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
118
+ /**
119
+ * Route loader function signature
120
+ */
121
+ export type LoaderFunction<Context = any> = {
122
+ (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
123
+ } & {
124
+ hydrate?: boolean;
125
+ };
126
+ /**
127
+ * Route action function signature
128
+ */
129
+ export interface ActionFunction<Context = any> {
130
+ (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
131
+ }
132
+ /**
133
+ * Arguments passed to shouldRevalidate function
134
+ */
135
+ export interface ShouldRevalidateFunctionArgs {
136
+ currentUrl: URL;
137
+ currentParams: AgnosticDataRouteMatch["params"];
138
+ nextUrl: URL;
139
+ nextParams: AgnosticDataRouteMatch["params"];
140
+ formMethod?: Submission["formMethod"];
141
+ formAction?: Submission["formAction"];
142
+ formEncType?: Submission["formEncType"];
143
+ text?: Submission["text"];
144
+ formData?: Submission["formData"];
145
+ json?: Submission["json"];
146
+ actionStatus?: number;
147
+ actionResult?: any;
148
+ defaultShouldRevalidate: boolean;
149
+ }
150
+ /**
151
+ * Route shouldRevalidate function signature. This runs after any submission
152
+ * (navigation or fetcher), so we flatten the navigation/fetcher submission
153
+ * onto the arguments. It shouldn't matter whether it came from a navigation
154
+ * or a fetcher, what really matters is the URLs and the formData since loaders
155
+ * have to re-run based on the data models that were potentially mutated.
156
+ */
157
+ export interface ShouldRevalidateFunction {
158
+ (args: ShouldRevalidateFunctionArgs): boolean;
159
+ }
160
+ export interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
161
+ shouldLoad: boolean;
162
+ resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
163
+ }
164
+ export interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
165
+ matches: DataStrategyMatch[];
166
+ fetcherKey: string | null;
167
+ }
168
+ /**
169
+ * Result from a loader or action called via dataStrategy
170
+ */
171
+ export interface DataStrategyResult {
172
+ type: "data" | "error";
173
+ result: unknown;
174
+ }
175
+ export interface DataStrategyFunction {
176
+ (args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
177
+ }
178
+ export type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
179
+ path: string;
180
+ matches: M[];
181
+ patch: (routeId: string | null, children: O[]) => void;
182
+ };
183
+ export type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => void | Promise<void>;
184
+ /**
185
+ * Function provided by the framework-aware layers to set any framework-specific
186
+ * properties from framework-agnostic properties
187
+ */
188
+ export interface MapRoutePropertiesFunction {
189
+ (route: AgnosticRouteObject): {
190
+ hasErrorBoundary: boolean;
191
+ } & Record<string, any>;
192
+ }
193
+ /**
194
+ * Keys we cannot change from within a lazy() function. We spread all other keys
195
+ * onto the route. Either they're meaningful to the router, or they'll get
196
+ * ignored.
197
+ */
198
+ export type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
199
+ export declare const immutableRouteKeys: Set<ImmutableRouteKey>;
200
+ type RequireOne<T, Key = keyof T> = Exclude<{
201
+ [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
202
+ }[keyof T], undefined>;
203
+ /**
204
+ * lazy() function to load a route definition, which can add non-matching
205
+ * related properties to a route
206
+ */
207
+ export interface LazyRouteFunction<R extends AgnosticRouteObject> {
208
+ (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
209
+ }
210
+ /**
211
+ * Base RouteObject with common props shared by all types of routes
212
+ */
213
+ type AgnosticBaseRouteObject = {
214
+ caseSensitive?: boolean;
215
+ path?: string;
216
+ id?: string;
217
+ loader?: LoaderFunction | boolean;
218
+ action?: ActionFunction | boolean;
219
+ hasErrorBoundary?: boolean;
220
+ shouldRevalidate?: ShouldRevalidateFunction;
221
+ handle?: any;
222
+ lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
223
+ };
224
+ /**
225
+ * Index routes must not have children
226
+ */
227
+ export type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
228
+ children?: undefined;
229
+ index: true;
230
+ };
231
+ /**
232
+ * Non-index routes may have children, but cannot have index
233
+ */
234
+ export type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
235
+ children?: AgnosticRouteObject[];
236
+ index?: false;
237
+ };
238
+ /**
239
+ * A route object represents a logical route, with (optionally) its child
240
+ * routes organized in a tree-like structure.
241
+ */
242
+ export type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
243
+ export type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
244
+ id: string;
245
+ };
246
+ export type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
247
+ children?: AgnosticDataRouteObject[];
248
+ id: string;
249
+ };
250
+ /**
251
+ * A data route object, which is just a RouteObject with a required unique ID
252
+ */
253
+ export type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
254
+ export type RouteManifest = Record<string, AgnosticDataRouteObject | undefined>;
255
+ type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?` ? Optional : Param : never;
256
+ /**
257
+ * Examples:
258
+ * "/a/b/*" -> "*"
259
+ * ":a" -> "a"
260
+ * "/a/:b" -> "b"
261
+ * "/a/blahblahblah:b" -> "b"
262
+ * "/:a/:b" -> "a" | "b"
263
+ * "/:a/b/:c/*" -> "a" | "c" | "*"
264
+ */
265
+ export type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
266
+ export type ParamParseKey<Segment extends string> = [
267
+ PathParam<Segment>
268
+ ] extends [never] ? string : PathParam<Segment>;
269
+ /**
270
+ * The parameters that were parsed from the URL path.
271
+ */
272
+ export type Params<Key extends string = string> = {
273
+ readonly [key in Key]: string | undefined;
274
+ };
275
+ /**
276
+ * A RouteMatch contains info about how a route matched a URL.
277
+ */
278
+ export interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
279
+ /**
280
+ * The names and values of dynamic parameters in the URL.
281
+ */
282
+ params: Params<ParamKey>;
283
+ /**
284
+ * The portion of the URL pathname that was matched.
285
+ */
286
+ pathname: string;
287
+ /**
288
+ * The portion of the URL pathname that was matched before child routes.
289
+ */
290
+ pathnameBase: string;
291
+ /**
292
+ * The route object that was used to match.
293
+ */
294
+ route: RouteObjectType;
295
+ }
296
+ export interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
297
+ }
298
+ export declare function convertRoutesToDataRoutes(routes: AgnosticRouteObject[], mapRouteProperties: MapRoutePropertiesFunction, parentPath?: string[], manifest?: RouteManifest): AgnosticDataRouteObject[];
299
+ /**
300
+ * Matches the given routes to a location and returns the match data.
301
+ *
302
+ * @category Utils
303
+ */
304
+ export declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
305
+ export declare function matchRoutesImpl<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename: string, allowPartial: boolean): AgnosticRouteMatch<string, RouteObjectType>[] | null;
306
+ export interface UIMatch<Data = unknown, Handle = unknown> {
307
+ id: string;
308
+ pathname: string;
309
+ params: AgnosticRouteMatch["params"];
310
+ data: Data;
311
+ handle: Handle;
312
+ }
313
+ export declare function convertRouteMatchToUiMatch(match: AgnosticDataRouteMatch, loaderData: RouteData): UIMatch;
314
+ /**
315
+ * Returns a path with params interpolated.
316
+ *
317
+ * @category Utils
318
+ */
319
+ export declare function generatePath<Path extends string>(originalPath: Path, params?: {
320
+ [key in PathParam<Path>]: string | null;
321
+ }): string;
322
+ /**
323
+ * A PathPattern is used to match on some portion of a URL pathname.
324
+ */
325
+ export interface PathPattern<Path extends string = string> {
326
+ /**
327
+ * A string to match against a URL pathname. May contain `:id`-style segments
328
+ * to indicate placeholders for dynamic parameters. May also end with `/*` to
329
+ * indicate matching the rest of the URL pathname.
330
+ */
331
+ path: Path;
332
+ /**
333
+ * Should be `true` if the static portions of the `path` should be matched in
334
+ * the same case.
335
+ */
336
+ caseSensitive?: boolean;
337
+ /**
338
+ * Should be `true` if this pattern should match the entire URL pathname.
339
+ */
340
+ end?: boolean;
341
+ }
342
+ /**
343
+ * A PathMatch contains info about how a PathPattern matched on a URL pathname.
344
+ */
345
+ export interface PathMatch<ParamKey extends string = string> {
346
+ /**
347
+ * The names and values of dynamic parameters in the URL.
348
+ */
349
+ params: Params<ParamKey>;
350
+ /**
351
+ * The portion of the URL pathname that was matched.
352
+ */
353
+ pathname: string;
354
+ /**
355
+ * The portion of the URL pathname that was matched before child routes.
356
+ */
357
+ pathnameBase: string;
358
+ /**
359
+ * The pattern that was used to match.
360
+ */
361
+ pattern: PathPattern;
362
+ }
363
+ /**
364
+ * Performs pattern matching on a URL pathname and returns information about
365
+ * the match.
366
+ *
367
+ * @category Utils
368
+ */
369
+ export declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
370
+ export declare function decodePath(value: string): string;
371
+ /**
372
+ * @private
373
+ */
374
+ export declare function stripBasename(pathname: string, basename: string): string | null;
375
+ /**
376
+ * Returns a resolved path object relative to the given pathname.
377
+ *
378
+ * @category Utils
379
+ */
380
+ export declare function resolvePath(to: To, fromPathname?: string): Path;
381
+ /**
382
+ * @private
383
+ *
384
+ * When processing relative navigation we want to ignore ancestor routes that
385
+ * do not contribute to the path, such that index/pathless layout routes don't
386
+ * interfere.
387
+ *
388
+ * For example, when moving a route element into an index route and/or a
389
+ * pathless layout route, relative link behavior contained within should stay
390
+ * the same. Both of the following examples should link back to the root:
391
+ *
392
+ * <Route path="/">
393
+ * <Route path="accounts" element={<Link to=".."}>
394
+ * </Route>
395
+ *
396
+ * <Route path="/">
397
+ * <Route path="accounts">
398
+ * <Route element={<AccountsLayout />}> // <-- Does not contribute
399
+ * <Route index element={<Link to=".."} /> // <-- Does not contribute
400
+ * </Route
401
+ * </Route>
402
+ * </Route>
403
+ */
404
+ export declare function getPathContributingMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): T[];
405
+ export declare function getResolveToMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): string[];
406
+ /**
407
+ * @private
408
+ */
409
+ export declare function resolveTo(toArg: To, routePathnames: string[], locationPathname: string, isPathRelative?: boolean): Path;
410
+ /**
411
+ * @private
412
+ */
413
+ export declare const joinPaths: (paths: string[]) => string;
414
+ /**
415
+ * @private
416
+ */
417
+ export declare const normalizePathname: (pathname: string) => string;
418
+ /**
419
+ * @private
420
+ */
421
+ export declare const normalizeSearch: (search: string) => string;
422
+ /**
423
+ * @private
424
+ */
425
+ export declare const normalizeHash: (hash: string) => string;
426
+ export type JsonFunction = <Data>(data: Data, init?: number | ResponseInit) => Response;
427
+ /**
428
+ * This is a shortcut for creating `application/json` responses. Converts `data`
429
+ * to JSON and sets the `Content-Type` header.
430
+ *
431
+ * @category Utils
432
+ */
433
+ export declare const json: JsonFunction;
434
+ export declare class DataWithResponseInit<D> {
435
+ type: string;
436
+ data: D;
437
+ init: ResponseInit | null;
438
+ constructor(data: D, init?: ResponseInit);
439
+ }
440
+ /**
441
+ * Create "responses" that contain `status`/`headers` without forcing
442
+ * serialization into an actual `Response` - used by Remix single fetch
443
+ *
444
+ * @category Utils
445
+ */
446
+ export declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
447
+ export interface TrackedPromise extends Promise<any> {
448
+ _tracked?: boolean;
449
+ _data?: any;
450
+ _error?: any;
451
+ }
452
+ export type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
453
+ /**
454
+ * A redirect response. Sets the status code and the `Location` header.
455
+ * Defaults to "302 Found".
456
+ *
457
+ * @category Utils
458
+ */
459
+ export declare const redirect: RedirectFunction;
460
+ /**
461
+ * A redirect response that will force a document reload to the new location.
462
+ * Sets the status code and the `Location` header.
463
+ * Defaults to "302 Found".
464
+ *
465
+ * @category Utils
466
+ */
467
+ export declare const redirectDocument: RedirectFunction;
468
+ /**
469
+ * A redirect response that will perform a `history.replaceState` instead of a
470
+ * `history.pushState` for client-side navigation redirects.
471
+ * Sets the status code and the `Location` header.
472
+ * Defaults to "302 Found".
473
+ *
474
+ * @category Utils
475
+ */
476
+ export declare const replace: RedirectFunction;
477
+ export type ErrorResponse = {
478
+ status: number;
479
+ statusText: string;
480
+ data: any;
481
+ };
482
+ /**
483
+ * @private
484
+ * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
485
+ *
486
+ * We don't export the class for public use since it's an implementation
487
+ * detail, but we export the interface above so folks can build their own
488
+ * abstractions around instances via isRouteErrorResponse()
489
+ */
490
+ export declare class ErrorResponseImpl implements ErrorResponse {
491
+ status: number;
492
+ statusText: string;
493
+ data: any;
494
+ private error?;
495
+ private internal;
496
+ constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
497
+ }
498
+ /**
499
+ * Check if the given error is an ErrorResponse generated from a 4xx/5xx
500
+ * Response thrown from an action/loader
501
+ *
502
+ * @category Utils
503
+ */
504
+ export declare function isRouteErrorResponse(error: any): error is ErrorResponse;
505
+ export {};
@@ -0,0 +1,38 @@
1
+ import type { ActionFunctionArgs, LoaderFunctionArgs } from "./routeModules";
2
+ import type { AssetsManifest, EntryContext, FutureConfig } from "../dom/ssr/entry";
3
+ import type { ServerRouteManifest } from "./routes";
4
+ import type { AppLoadContext } from "./data";
5
+ /**
6
+ * The output of the compiler for the server build.
7
+ */
8
+ export interface ServerBuild {
9
+ entry: {
10
+ module: ServerEntryModule;
11
+ };
12
+ routes: ServerRouteManifest;
13
+ assets: AssetsManifest;
14
+ basename?: string;
15
+ publicPath: string;
16
+ assetsBuildDirectory: string;
17
+ future: FutureConfig;
18
+ isSpaMode: boolean;
19
+ }
20
+ export interface HandleDocumentRequestFunction {
21
+ (request: Request, responseStatusCode: number, responseHeaders: Headers, context: EntryContext, loadContext: AppLoadContext): Promise<Response> | Response;
22
+ }
23
+ export interface HandleDataRequestFunction {
24
+ (response: Response, args: LoaderFunctionArgs | ActionFunctionArgs): Promise<Response> | Response;
25
+ }
26
+ export interface HandleErrorFunction {
27
+ (error: unknown, args: LoaderFunctionArgs | ActionFunctionArgs): void;
28
+ }
29
+ /**
30
+ * A module that serves as the entry point for a Remix app during server
31
+ * rendering.
32
+ */
33
+ export interface ServerEntryModule {
34
+ default: HandleDocumentRequestFunction;
35
+ handleDataRequest?: HandleDataRequestFunction;
36
+ handleError?: HandleErrorFunction;
37
+ streamTimeout?: number;
38
+ }
@@ -0,0 +1,62 @@
1
+ import type { CookieParseOptions, CookieSerializeOptions } from "cookie";
2
+ export type { CookieParseOptions, CookieSerializeOptions };
3
+ export interface CookieSignatureOptions {
4
+ /**
5
+ * An array of secrets that may be used to sign/unsign the value of a cookie.
6
+ *
7
+ * The array makes it easy to rotate secrets. New secrets should be added to
8
+ * the beginning of the array. `cookie.serialize()` will always use the first
9
+ * value in the array, but `cookie.parse()` may use any of them so that
10
+ * cookies that were signed with older secrets still work.
11
+ */
12
+ secrets?: string[];
13
+ }
14
+ export type CookieOptions = CookieParseOptions & CookieSerializeOptions & CookieSignatureOptions;
15
+ /**
16
+ * A HTTP cookie.
17
+ *
18
+ * A Cookie is a logical container for metadata about a HTTP cookie; its name
19
+ * and options. But it doesn't contain a value. Instead, it has `parse()` and
20
+ * `serialize()` methods that allow a single instance to be reused for
21
+ * parsing/encoding multiple different values.
22
+ *
23
+ * @see https://remix.run/utils/cookies#cookie-api
24
+ */
25
+ export interface Cookie {
26
+ /**
27
+ * The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
28
+ */
29
+ readonly name: string;
30
+ /**
31
+ * True if this cookie uses one or more secrets for verification.
32
+ */
33
+ readonly isSigned: boolean;
34
+ /**
35
+ * The Date this cookie expires.
36
+ *
37
+ * Note: This is calculated at access time using `maxAge` when no `expires`
38
+ * option is provided to `createCookie()`.
39
+ */
40
+ readonly expires?: Date;
41
+ /**
42
+ * Parses a raw `Cookie` header and returns the value of this cookie or
43
+ * `null` if it's not present.
44
+ */
45
+ parse(cookieHeader: string | null, options?: CookieParseOptions): Promise<any>;
46
+ /**
47
+ * Serializes the given value to a string and returns the `Set-Cookie`
48
+ * header.
49
+ */
50
+ serialize(value: any, options?: CookieSerializeOptions): Promise<string>;
51
+ }
52
+ /**
53
+ * Creates a logical container for managing a browser cookie from the server.
54
+ */
55
+ export declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
56
+ export type IsCookieFunction = (object: any) => object is Cookie;
57
+ /**
58
+ * Returns true if an object is a Remix cookie container.
59
+ *
60
+ * @see https://remix.run/utils/cookies#iscookie
61
+ */
62
+ export declare const isCookie: IsCookieFunction;
@@ -0,0 +1,2 @@
1
+ export declare const sign: (value: string, secret: string) => Promise<string>;
2
+ export declare const unsign: (cookie: string, secret: string) => Promise<string | false>;
@@ -0,0 +1,15 @@
1
+ import type { ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs } from "./routeModules";
2
+ /**
3
+ * An object of unknown type for route loaders and actions provided by the
4
+ * server's `getLoadContext()` function. This is defined as an empty interface
5
+ * specifically so apps can leverage declaration merging to augment this type
6
+ * globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
7
+ */
8
+ export interface AppLoadContext {
9
+ [key: string]: unknown;
10
+ }
11
+ /**
12
+ * Data for a route that was returned from a `loader()`.
13
+ */
14
+ export type AppData = unknown;
15
+ export declare function callRouteHandler(handler: LoaderFunction | ActionFunction, args: LoaderFunctionArgs | ActionFunctionArgs): Promise<{} | Response | null>;
@@ -0,0 +1,8 @@
1
+ import type { ServerBuild } from "./build";
2
+ type DevServerHooks = {
3
+ getCriticalCss?: (build: ServerBuild, pathname: string) => Promise<string | undefined>;
4
+ processRequestError?: (error: unknown) => void;
5
+ };
6
+ export declare function setDevServerHooks(devServerHooks: DevServerHooks): void;
7
+ export declare function getDevServerHooks(): DevServerHooks | undefined;
8
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ServerRouteManifest } from "./routes";
2
+ import type { RouteModules, EntryRouteModule } from "./routeModules";
3
+ export declare function createEntryRouteModules(manifest: ServerRouteManifest): RouteModules<EntryRouteModule>;
@@ -0,0 +1,51 @@
1
+ import type { StaticHandlerContext } from "../router/router";
2
+ import { ServerMode } from "./mode";
3
+ /**
4
+ * This thing probably warrants some explanation.
5
+ *
6
+ * The whole point here is to emulate componentDidCatch for server rendering and
7
+ * data loading. It can get tricky. React can do this on component boundaries
8
+ * but doesn't support it for server rendering or data loading. We know enough
9
+ * with nested routes to be able to emulate the behavior (because we know them
10
+ * statically before rendering.)
11
+ *
12
+ * Each route can export an `ErrorBoundary`.
13
+ *
14
+ * - When rendering throws an error, the nearest error boundary will render
15
+ * (normal react componentDidCatch). This will be the route's own boundary, but
16
+ * if none is provided, it will bubble up to the parents.
17
+ * - When data loading throws an error, the nearest error boundary will render
18
+ * - When performing an action, the nearest error boundary for the action's
19
+ * route tree will render (no redirect happens)
20
+ *
21
+ * During normal react rendering, we do nothing special, just normal
22
+ * componentDidCatch.
23
+ *
24
+ * For server rendering, we mutate `renderBoundaryRouteId` to know the last
25
+ * layout that has an error boundary that tried to render. This emulates which
26
+ * layout would catch a thrown error. If the rendering fails, we catch the error
27
+ * on the server, and go again a second time with the emulator holding on to the
28
+ * information it needs to render the same error boundary as a dynamically
29
+ * thrown render error.
30
+ *
31
+ * When data loading, server or client side, we use the emulator to likewise
32
+ * hang on to the error and re-render at the appropriate layout (where a thrown
33
+ * error would have been caught by cDC).
34
+ *
35
+ * When actions throw, it all works the same. There's an edge case to be aware
36
+ * of though. Actions normally are required to redirect, but in the case of
37
+ * errors, we render the action's route with the emulator holding on to the
38
+ * error. If during this render a parent route/loader throws we ignore that new
39
+ * error and render the action's original error as deeply as possible. In other
40
+ * words, we simply ignore the new error and use the action's error in place
41
+ * because it came first, and that just wouldn't be fair to let errors cut in
42
+ * line.
43
+ */
44
+ export declare function sanitizeError<T = unknown>(error: T, serverMode: ServerMode): Error | T;
45
+ export declare function sanitizeErrors(errors: NonNullable<StaticHandlerContext["errors"]>, serverMode: ServerMode): {};
46
+ export type SerializedError = {
47
+ message: string;
48
+ stack?: string;
49
+ };
50
+ export declare function serializeError(error: Error, serverMode: ServerMode): SerializedError;
51
+ export declare function serializeErrors(errors: StaticHandlerContext["errors"], serverMode: ServerMode): StaticHandlerContext["errors"];