react-router 7.0.0-pre.0 → 7.0.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -2
- package/dist/dom-export.mjs +11 -3
- package/dist/dom-export.mjs.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +1504 -356
- package/dist/index.mjs.map +1 -1
- package/dist/lib/components.d.ts +6 -6
- package/dist/lib/dom/global.d.ts +1 -1
- package/dist/lib/dom/lib.d.ts +3 -2
- package/dist/lib/dom/ssr/components.d.ts +0 -1
- package/dist/lib/dom/ssr/data.d.ts +0 -5
- package/dist/lib/dom/ssr/entry.d.ts +2 -1
- package/dist/lib/dom/ssr/routeModules.d.ts +64 -22
- package/dist/lib/dom/ssr/routes.d.ts +2 -5
- package/dist/lib/hooks.d.ts +4 -3
- package/dist/lib/router/router.d.ts +4 -0
- package/dist/lib/router/utils.d.ts +1 -9
- package/dist/lib/server-runtime/build.d.ts +1 -1
- package/dist/lib/server-runtime/cookies.d.ts +5 -5
- package/dist/lib/server-runtime/data.d.ts +1 -5
- package/dist/lib/server-runtime/routeModules.d.ts +3 -175
- package/dist/lib/server-runtime/routes.d.ts +2 -22
- package/dist/lib/server-runtime/sessions.d.ts +4 -4
- package/dist/lib/types.d.ts +21 -9
- package/dist/lib/types.mjs +1 -1
- package/dist/main-dom-export.js +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router-dom.development.js +3 -3
- package/dist/react-router-dom.development.js.map +1 -1
- package/dist/react-router-dom.production.min.js +2 -2
- package/dist/react-router-dom.production.min.js.map +1 -1
- package/dist/react-router.development.js +318 -295
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router-dom.development.js +3 -3
- package/dist/umd/react-router-dom.development.js.map +1 -1
- package/dist/umd/react-router-dom.production.min.js +2 -2
- package/dist/umd/react-router-dom.production.min.js.map +1 -1
- package/dist/umd/react-router.development.js +327 -317
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +4 -4
- package/dist/lib/server-runtime/jsonify.d.ts +0 -33
- package/dist/lib/server-runtime/responses.d.ts +0 -37
package/dist/lib/components.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import type { InitialEntry, Location, To } from "./router/history";
|
|
3
3
|
import { Action as NavigationType } from "./router/history";
|
|
4
4
|
import type { FutureConfig, HydrationState, RelativeRoutingType, Router as DataRouter } from "./router/router";
|
|
5
|
-
import type { DataStrategyFunction, LazyRouteFunction
|
|
5
|
+
import type { DataStrategyFunction, LazyRouteFunction } from "./router/utils";
|
|
6
6
|
import type { IndexRouteObject, Navigator, NonIndexRouteObject, PatchRoutesOnNavigationFunction, RouteMatch, RouteObject } from "./context";
|
|
7
7
|
/**
|
|
8
8
|
* @private
|
|
@@ -209,13 +209,13 @@ export interface RoutesProps {
|
|
|
209
209
|
@category Components
|
|
210
210
|
*/
|
|
211
211
|
export declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
|
|
212
|
-
export interface AwaitResolveRenderFunction {
|
|
213
|
-
(data: Awaited<
|
|
212
|
+
export interface AwaitResolveRenderFunction<Resolve = any> {
|
|
213
|
+
(data: Awaited<Resolve>): React.ReactNode;
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* @category Types
|
|
217
217
|
*/
|
|
218
|
-
export interface AwaitProps {
|
|
218
|
+
export interface AwaitProps<Resolve> {
|
|
219
219
|
/**
|
|
220
220
|
When using a function, the resolved value is provided as the parameter.
|
|
221
221
|
|
|
@@ -312,7 +312,7 @@ export interface AwaitProps {
|
|
|
312
312
|
}
|
|
313
313
|
```
|
|
314
314
|
*/
|
|
315
|
-
resolve:
|
|
315
|
+
resolve: Resolve;
|
|
316
316
|
}
|
|
317
317
|
/**
|
|
318
318
|
Used to render promise values with automatic error handling.
|
|
@@ -355,7 +355,7 @@ function Book() {
|
|
|
355
355
|
@category Components
|
|
356
356
|
|
|
357
357
|
*/
|
|
358
|
-
export declare function Await({ children, errorElement, resolve }: AwaitProps): React.JSX.Element;
|
|
358
|
+
export declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
|
|
359
359
|
/**
|
|
360
360
|
* Creates a route config from a React "children" object, which is usually
|
|
361
361
|
* either a `<Route>` element or an array of them. Used internally by
|
package/dist/lib/dom/global.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ declare global {
|
|
|
30
30
|
var __reactRouterContext: WindowReactRouterContext | undefined;
|
|
31
31
|
var __reactRouterManifest: AssetsManifest | undefined;
|
|
32
32
|
var __reactRouterRouteModules: RouteModules | undefined;
|
|
33
|
-
var
|
|
33
|
+
var __reactRouterDataRouter: DataRouter | undefined;
|
|
34
34
|
var __reactRouterHdrActive: boolean;
|
|
35
35
|
var __reactRouterClearCriticalCss: (() => void) | undefined;
|
|
36
36
|
var $RefreshRuntime$: {
|
package/dist/lib/dom/lib.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import "./global";
|
|
|
6
6
|
import type { SubmitOptions, URLSearchParamsInit, SubmitTarget, FetcherSubmitOptions } from "./dom";
|
|
7
7
|
import type { DiscoverBehavior, PrefetchBehavior, ScriptsProps } from "./ssr/components";
|
|
8
8
|
import type { RouteObject, NavigateOptions, PatchRoutesOnNavigationFunction } from "../context";
|
|
9
|
+
import type { SerializeFrom } from "../types";
|
|
9
10
|
interface DOMRouterOpts {
|
|
10
11
|
basename?: string;
|
|
11
12
|
future?: Partial<FutureConfig>;
|
|
@@ -834,7 +835,7 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
|
|
|
834
835
|
|
|
835
836
|
@category Hooks
|
|
836
837
|
*/
|
|
837
|
-
export declare function useFetcher<
|
|
838
|
+
export declare function useFetcher<T = any>({ key, }?: {
|
|
838
839
|
/**
|
|
839
840
|
By default, `useFetcher` generate a unique fetcher scoped to that component. If you want to identify a fetcher with your own key such that you can access it from elsewhere in your app, you can do that with the `key` option:
|
|
840
841
|
|
|
@@ -853,7 +854,7 @@ export declare function useFetcher<TData = any>({ key, }?: {
|
|
|
853
854
|
```
|
|
854
855
|
*/
|
|
855
856
|
key?: string;
|
|
856
|
-
}): FetcherWithComponents<
|
|
857
|
+
}): FetcherWithComponents<SerializeFrom<T>>;
|
|
857
858
|
/**
|
|
858
859
|
Returns an array of all in-flight fetchers. This is useful for components throughout the app that didn't create the fetchers but want to use their submissions to participate in optimistic UI.
|
|
859
860
|
|
|
@@ -2,7 +2,6 @@ import type { FocusEventHandler, MouseEventHandler, TouchEventHandler } from "re
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import type { FrameworkContextObject } from "./entry";
|
|
4
4
|
import type { PageLinkDescriptor } from "../../router/links";
|
|
5
|
-
export type SerializeFrom<D> = D extends () => {} ? Awaited<ReturnType<D>> : D;
|
|
6
5
|
export declare const FrameworkContext: React.Context<FrameworkContextObject | undefined>;
|
|
7
6
|
export declare function useFrameworkContext(): FrameworkContextObject;
|
|
8
7
|
/**
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
import "../global";
|
|
2
|
-
/**
|
|
3
|
-
* Data for a route that was returned from a `loader()`.
|
|
4
|
-
*/
|
|
5
|
-
export type AppData = unknown;
|
|
6
|
-
export declare function isResponse(value: any): value is Response;
|
|
7
2
|
export declare function createRequestInit(request: Request): Promise<RequestInit>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StaticHandlerContext } from "../../router/router";
|
|
2
|
-
import type {
|
|
2
|
+
import type { EntryRoute } from "./routes";
|
|
3
3
|
import type { RouteModules } from "./routeModules";
|
|
4
|
+
import type { RouteManifest } from "../../router/utils";
|
|
4
5
|
type SerializedError = {
|
|
5
6
|
message: string;
|
|
6
7
|
stack?: string;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { ComponentType, ReactElement } from "react";
|
|
2
2
|
import type { Location } from "../../router/history";
|
|
3
|
-
import type { ActionFunction
|
|
4
|
-
import type { SerializeFrom } from "./components";
|
|
5
|
-
import type { AppData } from "./data";
|
|
3
|
+
import type { ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs, Params, ShouldRevalidateFunction } from "../../router/utils";
|
|
6
4
|
import type { EntryRoute } from "./routes";
|
|
7
5
|
import type { DataRouteMatch } from "../../context";
|
|
8
6
|
import type { LinkDescriptor } from "../../router/links";
|
|
7
|
+
import type { SerializeFrom } from "../../types";
|
|
9
8
|
export interface RouteModules {
|
|
10
9
|
[routeId: string]: RouteModule | undefined;
|
|
11
10
|
}
|
|
@@ -24,24 +23,24 @@ export interface RouteModule {
|
|
|
24
23
|
/**
|
|
25
24
|
* A function that handles data mutations for a route on the client
|
|
26
25
|
*/
|
|
27
|
-
export type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<
|
|
26
|
+
export type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
|
|
28
27
|
/**
|
|
29
28
|
* Arguments passed to a route `clientAction` function
|
|
30
29
|
*/
|
|
31
|
-
export type ClientActionFunctionArgs =
|
|
32
|
-
serverAction: <T =
|
|
30
|
+
export type ClientActionFunctionArgs = ActionFunctionArgs<undefined> & {
|
|
31
|
+
serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
|
|
33
32
|
};
|
|
34
33
|
/**
|
|
35
34
|
* A function that loads data for a route on the client
|
|
36
35
|
*/
|
|
37
|
-
export type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<
|
|
36
|
+
export type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
|
|
38
37
|
hydrate?: boolean;
|
|
39
38
|
};
|
|
40
39
|
/**
|
|
41
40
|
* Arguments passed to a route `clientLoader` function
|
|
42
41
|
*/
|
|
43
|
-
export type ClientLoaderFunctionArgs =
|
|
44
|
-
serverLoader: <T =
|
|
42
|
+
export type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
|
|
43
|
+
serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
|
|
45
44
|
};
|
|
46
45
|
/**
|
|
47
46
|
* ErrorBoundary to display for this route
|
|
@@ -69,33 +68,76 @@ export type LayoutComponent = ComponentType<{
|
|
|
69
68
|
export interface LinksFunction {
|
|
70
69
|
(): LinkDescriptor[];
|
|
71
70
|
}
|
|
72
|
-
|
|
73
|
-
context: unknown;
|
|
74
|
-
response?: {
|
|
75
|
-
status: number | undefined;
|
|
76
|
-
headers: Headers;
|
|
77
|
-
};
|
|
78
|
-
}) => ReturnType<RRLoaderFunction>;
|
|
79
|
-
export interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | unknown = unknown> {
|
|
71
|
+
export interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
|
|
80
72
|
id: RouteId;
|
|
81
73
|
pathname: DataRouteMatch["pathname"];
|
|
82
|
-
data: Loader extends LoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
74
|
+
data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
83
75
|
handle?: RouteHandle;
|
|
84
76
|
params: DataRouteMatch["params"];
|
|
85
77
|
meta: MetaDescriptor[];
|
|
86
78
|
error?: unknown;
|
|
87
79
|
}
|
|
88
|
-
export type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> = Array<{
|
|
80
|
+
export type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
|
|
89
81
|
[K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
|
|
90
82
|
}[keyof MatchLoaders]>;
|
|
91
|
-
export interface MetaArgs<Loader extends LoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> {
|
|
92
|
-
data: (Loader extends LoaderFunction ? SerializeFrom<Loader> :
|
|
83
|
+
export interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
|
84
|
+
data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
|
|
93
85
|
params: Params;
|
|
94
86
|
location: Location;
|
|
95
87
|
matches: MetaMatches<MatchLoaders>;
|
|
96
88
|
error?: unknown;
|
|
97
89
|
}
|
|
98
|
-
|
|
90
|
+
/**
|
|
91
|
+
* A function that returns an array of data objects to use for rendering
|
|
92
|
+
* metadata HTML tags in a route. These tags are not rendered on descendant
|
|
93
|
+
* routes in the route hierarchy. In other words, they will only be rendered on
|
|
94
|
+
* the route in which they are exported.
|
|
95
|
+
*
|
|
96
|
+
* @param Loader - The type of the current route's loader function
|
|
97
|
+
* @param MatchLoaders - Mapping from a parent route's filepath to its loader
|
|
98
|
+
* function type
|
|
99
|
+
*
|
|
100
|
+
* Note that parent route filepaths are relative to the `app/` directory.
|
|
101
|
+
*
|
|
102
|
+
* For example, if this meta function is for `/sales/customers/$customerId`:
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* // app/root.tsx
|
|
106
|
+
* const loader = () => ({ hello: "world" })
|
|
107
|
+
* export type Loader = typeof loader
|
|
108
|
+
*
|
|
109
|
+
* // app/routes/sales.tsx
|
|
110
|
+
* const loader = () => ({ salesCount: 1074 })
|
|
111
|
+
* export type Loader = typeof loader
|
|
112
|
+
*
|
|
113
|
+
* // app/routes/sales/customers.tsx
|
|
114
|
+
* const loader = () => ({ customerCount: 74 })
|
|
115
|
+
* export type Loader = typeof loader
|
|
116
|
+
*
|
|
117
|
+
* // app/routes/sales/customers/$customersId.tsx
|
|
118
|
+
* import type { Loader as RootLoader } from "../../../root"
|
|
119
|
+
* import type { Loader as SalesLoader } from "../../sales"
|
|
120
|
+
* import type { Loader as CustomersLoader } from "../../sales/customers"
|
|
121
|
+
*
|
|
122
|
+
* const loader = () => ({ name: "Customer name" })
|
|
123
|
+
*
|
|
124
|
+
* const meta: MetaFunction<typeof loader, {
|
|
125
|
+
* "root": RootLoader,
|
|
126
|
+
* "routes/sales": SalesLoader,
|
|
127
|
+
* "routes/sales/customers": CustomersLoader,
|
|
128
|
+
* }> = ({ data, matches }) => {
|
|
129
|
+
* const { name } = data
|
|
130
|
+
* // ^? string
|
|
131
|
+
* const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
|
|
132
|
+
* // ^? number
|
|
133
|
+
* const { salesCount } = matches.find((match) => match.id === "routes/sales").data
|
|
134
|
+
* // ^? number
|
|
135
|
+
* const { hello } = matches.find((match) => match.id === "root").data
|
|
136
|
+
* // ^? "world"
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
|
99
141
|
(args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
|
|
100
142
|
}
|
|
101
143
|
export type MetaDescriptor = {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { HydrationState } from "../../router/router";
|
|
2
|
+
import type { RouteManifest } from "../../router/utils";
|
|
2
3
|
import type { RouteModule, RouteModules } from "./routeModules";
|
|
3
4
|
import type { FutureConfig } from "./entry";
|
|
4
5
|
import type { DataRouteObject } from "../../context";
|
|
5
|
-
export interface
|
|
6
|
-
[routeId: string]: Route;
|
|
7
|
-
}
|
|
8
|
-
interface Route {
|
|
6
|
+
export interface Route {
|
|
9
7
|
index?: boolean;
|
|
10
8
|
caseSensitive?: boolean;
|
|
11
9
|
id: string;
|
|
@@ -29,4 +27,3 @@ export declare function createServerRoutes(manifest: RouteManifest<EntryRoute>,
|
|
|
29
27
|
export declare function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation: Set<string>, manifest: RouteManifest<EntryRoute>, routeModulesCache: RouteModules, initialState: HydrationState, future: FutureConfig, isSpaMode: boolean): DataRouteObject[];
|
|
30
28
|
export declare function createClientRoutes(manifest: RouteManifest<EntryRoute>, routeModulesCache: RouteModules, initialState: HydrationState | null, isSpaMode: boolean, parentId?: string, routesByParentId?: Record<string, Omit<EntryRoute, "children">[]>, needsRevalidation?: Set<string>): DataRouteObject[];
|
|
31
29
|
export declare function shouldHydrateRouteLoader(route: EntryRoute, routeModule: RouteModule, isSpaMode: boolean): boolean;
|
|
32
|
-
export {};
|
package/dist/lib/hooks.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { Location, Path, To } from "./router/history";
|
|
|
4
4
|
import { Action as NavigationType } from "./router/history";
|
|
5
5
|
import type { Blocker, BlockerFunction, RelativeRoutingType, Router as DataRouter, RevalidationState } from "./router/router";
|
|
6
6
|
import type { ParamParseKey, Params, PathMatch, PathPattern, UIMatch } from "./router/utils";
|
|
7
|
+
import type { SerializeFrom } from "./types";
|
|
7
8
|
/**
|
|
8
9
|
Resolves a URL against the current location.
|
|
9
10
|
|
|
@@ -289,7 +290,7 @@ export declare function useMatches(): UIMatch[];
|
|
|
289
290
|
|
|
290
291
|
@category Hooks
|
|
291
292
|
*/
|
|
292
|
-
export declare function useLoaderData():
|
|
293
|
+
export declare function useLoaderData<T = any>(): SerializeFrom<T>;
|
|
293
294
|
/**
|
|
294
295
|
Returns the loader data for a given route by route ID.
|
|
295
296
|
|
|
@@ -317,7 +318,7 @@ export declare function useLoaderData(): unknown;
|
|
|
317
318
|
|
|
318
319
|
@category Hooks
|
|
319
320
|
*/
|
|
320
|
-
export declare function useRouteLoaderData(routeId: string):
|
|
321
|
+
export declare function useRouteLoaderData<T = any>(routeId: string): SerializeFrom<T> | undefined;
|
|
321
322
|
/**
|
|
322
323
|
Returns the action data from the most recent POST navigation form submission or `undefined` if there hasn't been one.
|
|
323
324
|
|
|
@@ -343,7 +344,7 @@ export declare function useRouteLoaderData(routeId: string): unknown;
|
|
|
343
344
|
|
|
344
345
|
@category Hooks
|
|
345
346
|
*/
|
|
346
|
-
export declare function useActionData():
|
|
347
|
+
export declare function useActionData<T = any>(): SerializeFrom<T> | undefined;
|
|
347
348
|
/**
|
|
348
349
|
Accesses the error thrown during an {@link ActionFunction | action}, {@link LoaderFunction | loader}, or component render to be used in a route module Error Boundary.
|
|
349
350
|
|
|
@@ -516,6 +516,7 @@ export type BlockerFunction = (args: {
|
|
|
516
516
|
nextLocation: Location;
|
|
517
517
|
historyAction: NavigationType;
|
|
518
518
|
}) => boolean;
|
|
519
|
+
export declare const redirectStatusCodes: Set<number>;
|
|
519
520
|
export declare const IDLE_NAVIGATION: NavigationStates["Idle"];
|
|
520
521
|
export declare const IDLE_FETCHER: FetcherStates["Idle"];
|
|
521
522
|
export declare const IDLE_BLOCKER: BlockerUnblocked;
|
|
@@ -537,4 +538,7 @@ export declare function createStaticHandler(routes: AgnosticRouteObject[], opts?
|
|
|
537
538
|
*/
|
|
538
539
|
export declare function getStaticContextFromError(routes: AgnosticDataRouteObject[], context: StaticHandlerContext, error: any): StaticHandlerContext;
|
|
539
540
|
export declare function isDataWithResponseInit(value: any): value is DataWithResponseInit<unknown>;
|
|
541
|
+
export declare function isResponse(value: any): value is Response;
|
|
542
|
+
export declare function isRedirectStatusCode(statusCode: number): boolean;
|
|
543
|
+
export declare function isRedirectResponse(result: any): result is Response;
|
|
540
544
|
export {};
|
|
@@ -251,7 +251,7 @@ export type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
|
|
|
251
251
|
* A data route object, which is just a RouteObject with a required unique ID
|
|
252
252
|
*/
|
|
253
253
|
export type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
|
|
254
|
-
export type RouteManifest = Record<string,
|
|
254
|
+
export type RouteManifest<R = AgnosticDataRouteObject> = Record<string, R | undefined>;
|
|
255
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
256
|
/**
|
|
257
257
|
* Examples:
|
|
@@ -423,14 +423,6 @@ export declare const normalizeSearch: (search: string) => string;
|
|
|
423
423
|
* @private
|
|
424
424
|
*/
|
|
425
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
426
|
export declare class DataWithResponseInit<D> {
|
|
435
427
|
type: string;
|
|
436
428
|
data: D;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActionFunctionArgs, LoaderFunctionArgs } from "
|
|
1
|
+
import type { ActionFunctionArgs, LoaderFunctionArgs } from "../router/utils";
|
|
2
2
|
import type { AssetsManifest, EntryContext, FutureConfig } from "../dom/ssr/entry";
|
|
3
3
|
import type { ServerRouteManifest } from "./routes";
|
|
4
4
|
import type { AppLoadContext } from "./data";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type { CookieParseOptions, CookieSerializeOptions };
|
|
1
|
+
import type { ParseOptions, SerializeOptions } from "cookie";
|
|
2
|
+
export type { ParseOptions as CookieParseOptions, SerializeOptions as CookieSerializeOptions, };
|
|
3
3
|
export interface CookieSignatureOptions {
|
|
4
4
|
/**
|
|
5
5
|
* An array of secrets that may be used to sign/unsign the value of a cookie.
|
|
@@ -11,7 +11,7 @@ export interface CookieSignatureOptions {
|
|
|
11
11
|
*/
|
|
12
12
|
secrets?: string[];
|
|
13
13
|
}
|
|
14
|
-
export type CookieOptions =
|
|
14
|
+
export type CookieOptions = ParseOptions & SerializeOptions & CookieSignatureOptions;
|
|
15
15
|
/**
|
|
16
16
|
* A HTTP cookie.
|
|
17
17
|
*
|
|
@@ -42,12 +42,12 @@ export interface Cookie {
|
|
|
42
42
|
* Parses a raw `Cookie` header and returns the value of this cookie or
|
|
43
43
|
* `null` if it's not present.
|
|
44
44
|
*/
|
|
45
|
-
parse(cookieHeader: string | null, options?:
|
|
45
|
+
parse(cookieHeader: string | null, options?: ParseOptions): Promise<any>;
|
|
46
46
|
/**
|
|
47
47
|
* Serializes the given value to a string and returns the `Set-Cookie`
|
|
48
48
|
* header.
|
|
49
49
|
*/
|
|
50
|
-
serialize(value: any, options?:
|
|
50
|
+
serialize(value: any, options?: SerializeOptions): Promise<string>;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Creates a logical container for managing a browser cookie from the server.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LoaderFunction, ActionFunction, LoaderFunctionArgs, ActionFunctionArgs } from "../router/utils";
|
|
2
2
|
/**
|
|
3
3
|
* An object of unknown type for route loaders and actions provided by the
|
|
4
4
|
* server's `getLoadContext()` function. This is defined as an empty interface
|
|
@@ -8,8 +8,4 @@ import type { ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunction
|
|
|
8
8
|
export interface AppLoadContext {
|
|
9
9
|
[key: string]: unknown;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Data for a route that was returned from a `loader()`.
|
|
13
|
-
*/
|
|
14
|
-
export type AppData = unknown;
|
|
15
11
|
export declare function callRouteHandler(handler: LoaderFunction | ActionFunction, args: LoaderFunctionArgs | ActionFunctionArgs): Promise<{} | Response | null>;
|
|
@@ -1,63 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { AppData, AppLoadContext } from "./data";
|
|
4
|
-
import type { SerializeFrom } from "../dom/ssr/components";
|
|
5
|
-
import type { LinkDescriptor } from "../router/links";
|
|
1
|
+
import type { ActionFunction, LoaderFunction } from "../router/utils";
|
|
2
|
+
import type { ClientActionFunction, ClientLoaderFunction, LinksFunction, MetaFunction } from "../dom/ssr/routeModules";
|
|
6
3
|
export interface RouteModules<RouteModule> {
|
|
7
4
|
[routeId: string]: RouteModule | undefined;
|
|
8
5
|
}
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated Use `LoaderFunctionArgs`/`ActionFunctionArgs` instead
|
|
11
|
-
*/
|
|
12
|
-
export type DataFunctionArgs = RRActionFunctionArgs<AppLoadContext> & RRLoaderFunctionArgs<AppLoadContext> & {
|
|
13
|
-
context: AppLoadContext;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* A function that handles data mutations for a route on the server
|
|
17
|
-
*/
|
|
18
|
-
export type ActionFunction = (args: ActionFunctionArgs) => ReturnType<RRActionFunction>;
|
|
19
|
-
/**
|
|
20
|
-
* Arguments passed to a route `action` function
|
|
21
|
-
*/
|
|
22
|
-
export type ActionFunctionArgs = RRActionFunctionArgs<AppLoadContext> & {
|
|
23
|
-
context: AppLoadContext;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* A function that handles data mutations for a route on the client
|
|
27
|
-
* @private Public API is exported from @react-router/react
|
|
28
|
-
*/
|
|
29
|
-
type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<RRActionFunction>;
|
|
30
|
-
/**
|
|
31
|
-
* Arguments passed to a route `clientAction` function
|
|
32
|
-
* @private Public API is exported from @react-router/react
|
|
33
|
-
*/
|
|
34
|
-
export type ClientActionFunctionArgs = RRActionFunctionArgs<undefined> & {
|
|
35
|
-
serverAction: <T = AppData>() => Promise<SerializeFrom<T>>;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* A function that loads data for a route on the server
|
|
39
|
-
*/
|
|
40
|
-
export type LoaderFunction = (args: LoaderFunctionArgs) => ReturnType<RRLoaderFunction>;
|
|
41
|
-
/**
|
|
42
|
-
* Arguments passed to a route `loader` function
|
|
43
|
-
*/
|
|
44
|
-
export type LoaderFunctionArgs = RRLoaderFunctionArgs<AppLoadContext> & {
|
|
45
|
-
context: AppLoadContext;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* A function that loads data for a route on the client
|
|
49
|
-
* @private Public API is exported from @react-router/react
|
|
50
|
-
*/
|
|
51
|
-
type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<RRLoaderFunction>) & {
|
|
52
|
-
hydrate?: boolean;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Arguments passed to a route `clientLoader` function
|
|
56
|
-
* @private Public API is exported from @react-router/react
|
|
57
|
-
*/
|
|
58
|
-
export type ClientLoaderFunctionArgs = RRLoaderFunctionArgs<undefined> & {
|
|
59
|
-
serverLoader: <T = AppData>() => Promise<SerializeFrom<T>>;
|
|
60
|
-
};
|
|
61
6
|
export type HeadersArgs = {
|
|
62
7
|
loaderHeaders: Headers;
|
|
63
8
|
parentHeaders: Headers;
|
|
@@ -71,122 +16,6 @@ export type HeadersArgs = {
|
|
|
71
16
|
export interface HeadersFunction {
|
|
72
17
|
(args: HeadersArgs): Headers | HeadersInit;
|
|
73
18
|
}
|
|
74
|
-
/**
|
|
75
|
-
* A function that defines `<link>` tags to be inserted into the `<head>` of
|
|
76
|
-
* the document on route transitions.
|
|
77
|
-
*/
|
|
78
|
-
export interface LinksFunction {
|
|
79
|
-
(): LinkDescriptor[];
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* A function that returns an array of data objects to use for rendering
|
|
83
|
-
* metadata HTML tags in a route. These tags are not rendered on descendant
|
|
84
|
-
* routes in the route hierarchy. In other words, they will only be rendered on
|
|
85
|
-
* the route in which they are exported.
|
|
86
|
-
*
|
|
87
|
-
* @param Loader - The type of the current route's loader function
|
|
88
|
-
* @param MatchLoaders - Mapping from a parent route's filepath to its loader
|
|
89
|
-
* function type
|
|
90
|
-
*
|
|
91
|
-
* Note that parent route filepaths are relative to the `app/` directory.
|
|
92
|
-
*
|
|
93
|
-
* For example, if this meta function is for `/sales/customers/$customerId`:
|
|
94
|
-
*
|
|
95
|
-
* ```ts
|
|
96
|
-
* // app/root.tsx
|
|
97
|
-
* const loader = () => {
|
|
98
|
-
* return json({ hello: "world" } as const)
|
|
99
|
-
* }
|
|
100
|
-
* export type Loader = typeof loader
|
|
101
|
-
*
|
|
102
|
-
* // app/routes/sales.tsx
|
|
103
|
-
* const loader = () => {
|
|
104
|
-
* return json({ salesCount: 1074 })
|
|
105
|
-
* }
|
|
106
|
-
* export type Loader = typeof loader
|
|
107
|
-
*
|
|
108
|
-
* // app/routes/sales/customers.tsx
|
|
109
|
-
* const loader = () => {
|
|
110
|
-
* return json({ customerCount: 74 })
|
|
111
|
-
* }
|
|
112
|
-
* export type Loader = typeof loader
|
|
113
|
-
*
|
|
114
|
-
* // app/routes/sales/customers/$customersId.tsx
|
|
115
|
-
* import type { Loader as RootLoader } from "../../../root"
|
|
116
|
-
* import type { Loader as SalesLoader } from "../../sales"
|
|
117
|
-
* import type { Loader as CustomersLoader } from "../../sales/customers"
|
|
118
|
-
*
|
|
119
|
-
* const loader = () => {
|
|
120
|
-
* return json({ name: "Customer name" })
|
|
121
|
-
* }
|
|
122
|
-
*
|
|
123
|
-
* const meta: MetaFunction<typeof loader, {
|
|
124
|
-
* "root": RootLoader,
|
|
125
|
-
* "routes/sales": SalesLoader,
|
|
126
|
-
* "routes/sales/customers": CustomersLoader,
|
|
127
|
-
* }> = ({ data, matches }) => {
|
|
128
|
-
* const { name } = data
|
|
129
|
-
* // ^? string
|
|
130
|
-
* const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
|
|
131
|
-
* // ^? number
|
|
132
|
-
* const { salesCount } = matches.find((match) => match.id === "routes/sales").data
|
|
133
|
-
* // ^? number
|
|
134
|
-
* const { hello } = matches.find((match) => match.id === "root").data
|
|
135
|
-
* // ^? "world"
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
export interface ServerRuntimeMetaFunction<Loader extends LoaderFunction | unknown = unknown, ParentsLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> {
|
|
140
|
-
(args: ServerRuntimeMetaArgs<Loader, ParentsLoaders>): ServerRuntimeMetaDescriptor[];
|
|
141
|
-
}
|
|
142
|
-
interface ServerRuntimeMetaMatch<RouteId extends string = string, Loader extends LoaderFunction | unknown = unknown> {
|
|
143
|
-
id: RouteId;
|
|
144
|
-
pathname: AgnosticRouteMatch["pathname"];
|
|
145
|
-
data: Loader extends LoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
146
|
-
handle?: RouteHandle;
|
|
147
|
-
params: AgnosticRouteMatch["params"];
|
|
148
|
-
meta: ServerRuntimeMetaDescriptor[];
|
|
149
|
-
error?: unknown;
|
|
150
|
-
}
|
|
151
|
-
type ServerRuntimeMetaMatches<MatchLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> = Array<{
|
|
152
|
-
[K in keyof MatchLoaders]: ServerRuntimeMetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
|
|
153
|
-
}[keyof MatchLoaders]>;
|
|
154
|
-
export interface ServerRuntimeMetaArgs<Loader extends LoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> {
|
|
155
|
-
data: (Loader extends LoaderFunction ? SerializeFrom<Loader> : AppData) | undefined;
|
|
156
|
-
params: Params;
|
|
157
|
-
location: Location;
|
|
158
|
-
matches: ServerRuntimeMetaMatches<MatchLoaders>;
|
|
159
|
-
error?: unknown;
|
|
160
|
-
}
|
|
161
|
-
export type ServerRuntimeMetaDescriptor = {
|
|
162
|
-
charSet: "utf-8";
|
|
163
|
-
} | {
|
|
164
|
-
title: string;
|
|
165
|
-
} | {
|
|
166
|
-
name: string;
|
|
167
|
-
content: string;
|
|
168
|
-
} | {
|
|
169
|
-
property: string;
|
|
170
|
-
content: string;
|
|
171
|
-
} | {
|
|
172
|
-
httpEquiv: string;
|
|
173
|
-
content: string;
|
|
174
|
-
} | {
|
|
175
|
-
"script:ld+json": LdJsonObject;
|
|
176
|
-
} | {
|
|
177
|
-
tagName: "meta" | "link";
|
|
178
|
-
[name: string]: string;
|
|
179
|
-
} | {
|
|
180
|
-
[name: string]: unknown;
|
|
181
|
-
};
|
|
182
|
-
type LdJsonObject = {
|
|
183
|
-
[Key in string]: LdJsonValue;
|
|
184
|
-
} & {
|
|
185
|
-
[Key in string]?: LdJsonValue | undefined;
|
|
186
|
-
};
|
|
187
|
-
type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
|
|
188
|
-
type LdJsonPrimitive = string | number | boolean | null;
|
|
189
|
-
type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
190
19
|
/**
|
|
191
20
|
* An arbitrary object that is associated with a route.
|
|
192
21
|
*/
|
|
@@ -200,7 +29,7 @@ export interface EntryRouteModule {
|
|
|
200
29
|
default: any;
|
|
201
30
|
handle?: RouteHandle;
|
|
202
31
|
links?: LinksFunction;
|
|
203
|
-
meta?:
|
|
32
|
+
meta?: MetaFunction;
|
|
204
33
|
}
|
|
205
34
|
export interface ServerRouteModule extends EntryRouteModule {
|
|
206
35
|
action?: ActionFunction;
|
|
@@ -209,4 +38,3 @@ export interface ServerRouteModule extends EntryRouteModule {
|
|
|
209
38
|
};
|
|
210
39
|
loader?: LoaderFunction;
|
|
211
40
|
}
|
|
212
|
-
export {};
|
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
import type { AgnosticDataRouteObject } from "../router/utils";
|
|
1
|
+
import type { AgnosticDataRouteObject, RouteManifest } from "../router/utils";
|
|
2
2
|
import type { FutureConfig } from "../dom/ssr/entry";
|
|
3
|
+
import type { Route } from "../dom/ssr/routes";
|
|
3
4
|
import type { ServerRouteModule } from "./routeModules";
|
|
4
|
-
export interface RouteManifest<Route> {
|
|
5
|
-
[routeId: string]: Route;
|
|
6
|
-
}
|
|
7
5
|
export type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
|
|
8
|
-
export interface Route {
|
|
9
|
-
index?: boolean;
|
|
10
|
-
caseSensitive?: boolean;
|
|
11
|
-
id: string;
|
|
12
|
-
parentId?: string;
|
|
13
|
-
path?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface EntryRoute extends Route {
|
|
16
|
-
hasAction: boolean;
|
|
17
|
-
hasLoader: boolean;
|
|
18
|
-
hasClientAction: boolean;
|
|
19
|
-
hasClientLoader: boolean;
|
|
20
|
-
hasErrorBoundary: boolean;
|
|
21
|
-
imports?: string[];
|
|
22
|
-
css?: string[];
|
|
23
|
-
module: string;
|
|
24
|
-
parentId?: string;
|
|
25
|
-
}
|
|
26
6
|
export interface ServerRoute extends Route {
|
|
27
7
|
children: ServerRoute[];
|
|
28
8
|
module: ServerRouteModule;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParseOptions, SerializeOptions } from "cookie";
|
|
2
2
|
import type { Cookie, CookieOptions } from "./cookies";
|
|
3
3
|
/**
|
|
4
4
|
* An object of name/value pairs to be used in the session.
|
|
@@ -83,17 +83,17 @@ export interface SessionStorage<Data = SessionData, FlashData = Data> {
|
|
|
83
83
|
* Session. If there is no session associated with the cookie, this will
|
|
84
84
|
* return a new Session with no data.
|
|
85
85
|
*/
|
|
86
|
-
getSession: (cookieHeader?: string | null, options?:
|
|
86
|
+
getSession: (cookieHeader?: string | null, options?: ParseOptions) => Promise<Session<Data, FlashData>>;
|
|
87
87
|
/**
|
|
88
88
|
* Stores all data in the Session and returns the Set-Cookie header to be
|
|
89
89
|
* used in the HTTP response.
|
|
90
90
|
*/
|
|
91
|
-
commitSession: (session: Session<Data, FlashData>, options?:
|
|
91
|
+
commitSession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
|
|
92
92
|
/**
|
|
93
93
|
* Deletes all data associated with the Session and returns the Set-Cookie
|
|
94
94
|
* header to be used in the HTTP response.
|
|
95
95
|
*/
|
|
96
|
-
destroySession: (session: Session<Data, FlashData>, options?:
|
|
96
|
+
destroySession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* SessionIdStorageStrategy is designed to allow anyone to easily build their
|