Skip to content

Commit 5ffd5da

Browse files
authored
Dedup route modules types across server-runtime and ssr (#12799)
1 parent 04b1a3b commit 5ffd5da

File tree

5 files changed

+35
-62
lines changed

5 files changed

+35
-62
lines changed

.changeset/eight-monkeys-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Internal reorg to clean up some duplicated route module types

packages/react-router/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ export type {
200200
ClientActionFunctionArgs,
201201
ClientLoaderFunction,
202202
ClientLoaderFunctionArgs,
203+
HeadersArgs,
204+
HeadersFunction,
203205
MetaArgs,
204206
MetaDescriptor,
205207
MetaFunction,
@@ -251,11 +253,6 @@ export type {
251253
LinkDescriptor,
252254
} from "./lib/router/links";
253255

254-
export type {
255-
HeadersArgs,
256-
HeadersFunction,
257-
} from "./lib/server-runtime/routeModules";
258-
259256
export type { RequestHandler } from "./lib/server-runtime/server";
260257

261258
export type {

packages/react-router/lib/dom/ssr/routeModules.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export interface RouteModules {
1818
[routeId: string]: RouteModule | undefined;
1919
}
2020

21+
/**
22+
* The shape of a route module shipped to the client
23+
*/
2124
export interface RouteModule {
2225
clientAction?: ClientActionFunction;
2326
clientLoader?: ClientLoaderFunction;
@@ -31,6 +34,15 @@ export interface RouteModule {
3134
shouldRevalidate?: ShouldRevalidateFunction;
3235
}
3336

37+
/**
38+
* The shape of a route module on the server
39+
*/
40+
export interface ServerRouteModule extends RouteModule {
41+
action?: ActionFunction;
42+
headers?: HeadersFunction | { [name: string]: string };
43+
loader?: LoaderFunction;
44+
}
45+
3446
/**
3547
* A function that handles data mutations for a route on the client
3648
*/
@@ -66,6 +78,21 @@ export type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
6678
*/
6779
export type ErrorBoundaryComponent = ComponentType;
6880

81+
export type HeadersArgs = {
82+
loaderHeaders: Headers;
83+
parentHeaders: Headers;
84+
actionHeaders: Headers;
85+
errorHeaders: Headers | undefined;
86+
};
87+
88+
/**
89+
* A function that returns HTTP headers to be used for a route. These headers
90+
* will be merged with (and take precedence over) headers from parent routes.
91+
*/
92+
export interface HeadersFunction {
93+
(args: HeadersArgs): Headers | HeadersInit;
94+
}
95+
6996
/**
7097
* `<Route HydrateFallback>` component to render on initial loads
7198
* when client loaders are present

packages/react-router/lib/server-runtime/routeModules.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

packages/react-router/lib/server-runtime/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import type {
77
import { callRouteHandler } from "./data";
88
import type { FutureConfig } from "../dom/ssr/entry";
99
import type { Route } from "../dom/ssr/routes";
10-
import type { ServerRouteModule } from "./routeModules";
1110
import type {
1211
SingleFetchResult,
1312
SingleFetchResults,
1413
} from "../dom/ssr/single-fetch";
1514
import { decodeViaTurboStream } from "../dom/ssr/single-fetch";
1615
import invariant from "./invariant";
16+
import type { ServerRouteModule } from "../dom/ssr/routeModules";
1717

1818
export type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
1919

0 commit comments

Comments
 (0)