Skip to content

Dedup route modules types across server-runtime and ssr #12799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-monkeys-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": patch
---

Internal reorg to clean up some duplicated route module types
7 changes: 2 additions & 5 deletions packages/react-router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ export type {
ClientActionFunctionArgs,
ClientLoaderFunction,
ClientLoaderFunctionArgs,
HeadersArgs,
HeadersFunction,
MetaArgs,
MetaDescriptor,
MetaFunction,
Expand Down Expand Up @@ -251,11 +253,6 @@ export type {
LinkDescriptor,
} from "./lib/router/links";

export type {
HeadersArgs,
HeadersFunction,
} from "./lib/server-runtime/routeModules";

export type { RequestHandler } from "./lib/server-runtime/server";

export type {
Expand Down
27 changes: 27 additions & 0 deletions packages/react-router/lib/dom/ssr/routeModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export interface RouteModules {
[routeId: string]: RouteModule | undefined;
}

/**
* The shape of a route module shipped to the client
*/
export interface RouteModule {
clientAction?: ClientActionFunction;
clientLoader?: ClientLoaderFunction;
Expand All @@ -31,6 +34,15 @@ export interface RouteModule {
shouldRevalidate?: ShouldRevalidateFunction;
}

/**
* The shape of a route module on the server
*/
export interface ServerRouteModule extends RouteModule {
action?: ActionFunction;
headers?: HeadersFunction | { [name: string]: string };
loader?: LoaderFunction;
}

/**
* A function that handles data mutations for a route on the client
*/
Expand Down Expand Up @@ -66,6 +78,21 @@ export type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
*/
export type ErrorBoundaryComponent = ComponentType;

export type HeadersArgs = {
loaderHeaders: Headers;
parentHeaders: Headers;
actionHeaders: Headers;
errorHeaders: Headers | undefined;
};

/**
* A function that returns HTTP headers to be used for a route. These headers
* will be merged with (and take precedence over) headers from parent routes.
*/
export interface HeadersFunction {
(args: HeadersArgs): Headers | HeadersInit;
}

/**
* `<Route HydrateFallback>` component to render on initial loads
* when client loaders are present
Expand Down
56 changes: 0 additions & 56 deletions packages/react-router/lib/server-runtime/routeModules.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react-router/lib/server-runtime/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import type {
import { callRouteHandler } from "./data";
import type { FutureConfig } from "../dom/ssr/entry";
import type { Route } from "../dom/ssr/routes";
import type { ServerRouteModule } from "./routeModules";
import type {
SingleFetchResult,
SingleFetchResults,
} from "../dom/ssr/single-fetch";
import { decodeViaTurboStream } from "../dom/ssr/single-fetch";
import invariant from "./invariant";
import type { ServerRouteModule } from "../dom/ssr/routeModules";

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

Expand Down
Loading