|
1 | 1 | import type { MetaDescriptor } from "../dom/ssr/routeModules";
|
2 | 2 | import type { Location } from "../router/history";
|
3 | 3 | import type { LinkDescriptor } from "../router/links";
|
4 |
| -import type { |
5 |
| - unstable_MiddlewareNextFunction, |
6 |
| - unstable_RouterContextProvider, |
7 |
| -} from "../router/utils"; |
8 |
| -import type { AppLoadContext } from "../server-runtime/data"; |
9 |
| -import type { MiddlewareEnabled } from "./future"; |
| 4 | +import type { unstable_MiddlewareNextFunction } from "../router/utils"; |
10 | 5 |
|
11 |
| -import type { GetLoaderData, ServerDataFrom } from "./route-data"; |
| 6 | +import type { |
| 7 | + ClientDataFunctionArgs, |
| 8 | + GetLoaderData, |
| 9 | + ServerDataFrom, |
| 10 | + ServerDataFunctionArgs, |
| 11 | +} from "./route-data"; |
12 | 12 | import type { RouteModule } from "./route-module";
|
13 | 13 | import type { Pretty } from "./utils";
|
14 | 14 |
|
@@ -67,94 +67,34 @@ type HeadersArgs = {
|
67 | 67 | errorHeaders: Headers | undefined;
|
68 | 68 | };
|
69 | 69 |
|
70 |
| -type ClientDataFunctionArgs<T extends RouteInfo> = { |
71 |
| - /** |
72 |
| - * 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. |
73 |
| - * |
74 |
| - * @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. |
75 |
| - **/ |
76 |
| - request: Request; |
77 |
| - /** |
78 |
| - * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. |
79 |
| - * @example |
80 |
| - * // app/routes.ts |
81 |
| - * route("teams/:teamId", "./team.tsx"), |
82 |
| - * |
83 |
| - * // app/team.tsx |
84 |
| - * export function clientLoader({ |
85 |
| - * params, |
86 |
| - * }: Route.ClientLoaderArgs) { |
87 |
| - * params.teamId; |
88 |
| - * // ^ string |
89 |
| - * } |
90 |
| - **/ |
91 |
| - params: T["params"]; |
92 |
| - /** |
93 |
| - * When `future.unstable_middleware` is not enabled, this is undefined. |
94 |
| - * |
95 |
| - * When `future.unstable_middleware` is enabled, this is an instance of |
96 |
| - * `unstable_RouterContextProvider` and can be used to access context values |
97 |
| - * from your route middlewares. You may pass in initial context values in your |
98 |
| - * `<HydratedRouter unstable_getContext>` prop |
99 |
| - */ |
100 |
| - context: unstable_RouterContextProvider; |
101 |
| -}; |
102 |
| - |
103 |
| -type ServerDataFunctionArgs<T extends RouteInfo> = { |
104 |
| - /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the url, method, headers (such as cookies), and request body from the request. */ |
105 |
| - request: Request; |
106 |
| - /** |
107 |
| - * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. |
108 |
| - * @example |
109 |
| - * // app/routes.ts |
110 |
| - * route("teams/:teamId", "./team.tsx"), |
111 |
| - * |
112 |
| - * // app/team.tsx |
113 |
| - * export function loader({ |
114 |
| - * params, |
115 |
| - * }: Route.LoaderArgs) { |
116 |
| - * params.teamId; |
117 |
| - * // ^ string |
118 |
| - * } |
119 |
| - **/ |
120 |
| - params: T["params"]; |
121 |
| - /** |
122 |
| - * Without `future.unstable_middleware` enabled, this is the context passed in |
123 |
| - * to your server adapter's `getLoadContext` function. It's a way to bridge the |
124 |
| - * gap between the adapter's request/response API with your React Router app. |
125 |
| - * It is only applicable if you are using a custom server adapter. |
126 |
| - * |
127 |
| - * With `future.unstable_middleware` enabled, this is an instance of |
128 |
| - * `unstable_RouterContextProvider` and can be used for type-safe access to |
129 |
| - * context value set in your route middlewares. If you are using a custom |
130 |
| - * server adapter, you may provide an initial set of context values from your |
131 |
| - * `getLoadContext` function. |
132 |
| - */ |
133 |
| - context: MiddlewareEnabled extends true |
134 |
| - ? unstable_RouterContextProvider |
135 |
| - : AppLoadContext; |
136 |
| -}; |
137 |
| - |
138 | 70 | type CreateServerMiddlewareFunction<T extends RouteInfo> = (
|
139 |
| - args: ServerDataFunctionArgs<T>, |
| 71 | + args: ServerDataFunctionArgs<T["params"]>, |
140 | 72 | next: unstable_MiddlewareNextFunction<Response>
|
141 | 73 | ) => MaybePromise<Response | void>;
|
142 | 74 |
|
143 | 75 | type CreateClientMiddlewareFunction<T extends RouteInfo> = (
|
144 |
| - args: ClientDataFunctionArgs<T>, |
| 76 | + args: ClientDataFunctionArgs<T["params"]>, |
145 | 77 | next: unstable_MiddlewareNextFunction<undefined>
|
146 | 78 | ) => MaybePromise<void>;
|
147 | 79 |
|
148 |
| -type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>; |
| 80 | +type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs< |
| 81 | + T["params"] |
| 82 | +>; |
149 | 83 |
|
150 |
| -type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & { |
| 84 | +type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs< |
| 85 | + T["params"] |
| 86 | +> & { |
151 | 87 | /** This is an asynchronous function to get the data from the server loader for this route. On client-side navigations, this will make a {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server loader. If you opt-into running your clientLoader on hydration, then this function will return the data that was already loaded on the server (via Promise.resolve). */
|
152 | 88 | serverLoader: () => Promise<ServerDataFrom<T["module"]["loader"]>>;
|
153 | 89 | };
|
154 | 90 |
|
155 |
| -type CreateServerActionArgs<T extends RouteInfo> = ServerDataFunctionArgs<T>; |
| 91 | +type CreateServerActionArgs<T extends RouteInfo> = ServerDataFunctionArgs< |
| 92 | + T["params"] |
| 93 | +>; |
156 | 94 |
|
157 |
| -type CreateClientActionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T> & { |
| 95 | +type CreateClientActionArgs<T extends RouteInfo> = ClientDataFunctionArgs< |
| 96 | + T["params"] |
| 97 | +> & { |
158 | 98 | /** This is an asynchronous function that makes the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server action for this route. */
|
159 | 99 | serverAction: () => Promise<ServerDataFrom<T["module"]["action"]>>;
|
160 | 100 | };
|
|
0 commit comments