Skip to content

Commit

Permalink
Dedup route modules types across server-runtime and ssr (#12799)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Jan 21, 2025
1 parent 04b1a3b commit 5ffd5da
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 62 deletions.
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

0 comments on commit 5ffd5da

Please sign in to comment.