Skip to content
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

feat!: align types with React Router #7319

Merged
merged 10 commits into from
Sep 6, 2023
Next Next commit
Align types with React Router
  • Loading branch information
brophdawg11 committed Aug 31, 2023
commit 77a8b65309e0c592995fc69703f7f2ec8297f249
12 changes: 12 additions & 0 deletions .changeset/align-rr-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@remix-run/cloudflare": major
"@remix-run/deno": major
"@remix-run/node": major
"@remix-run/server-runtime": major
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
---

Remove/Align Remix types with those use din React Router

* Remove Remix definitions of `LoaderFunction`/`ActionFunction` and re-export from React Router
* Remove `LoaderArgs`/`ActionArgs` and re-export `LoaderFunctionArgs`/`ActionFunctionArgs` from React Router
* Change `AppLoadContext` from a keyed object in Remix to the `any` used in React Router to permit users to return anything from `getLoadContext`
4 changes: 2 additions & 2 deletions packages/remix-cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export {
} from "@remix-run/server-runtime";

export type {
ActionArgs,
ActionFunction,
ActionFunctionArgs,
AppData,
AppLoadContext,
Cookie,
Expand All @@ -47,8 +47,8 @@ export type {
JsonFunction,
LinkDescriptor,
LinksFunction,
LoaderArgs,
LoaderFunction,
LoaderFunctionArgs,
MemoryUploadHandlerFilterArgs,
MemoryUploadHandlerOptions,
HandleErrorFunction,
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export {
} from "@remix-run/server-runtime";

export type {
ActionArgs,
ActionFunction,
ActionFunctionArgs,
AppData,
AppLoadContext,
Cookie,
Expand All @@ -51,8 +51,8 @@ export type {
JsonFunction,
LinkDescriptor,
LinksFunction,
LoaderArgs,
LoaderFunction,
LoaderFunctionArgs,
MemoryUploadHandlerFilterArgs,
MemoryUploadHandlerOptions,
PageLinkDescriptor,
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export {
} from "@remix-run/server-runtime";

export type {
ActionArgs,
ActionFunction,
ActionFunctionArgs,
AppData,
AppLoadContext,
Cookie,
Expand All @@ -67,8 +67,8 @@ export type {
JsonFunction,
LinkDescriptor,
LinksFunction,
LoaderArgs,
LoaderFunction,
LoaderFunctionArgs,
MemoryUploadHandlerFilterArgs,
MemoryUploadHandlerOptions,
HandleErrorFunction,
Expand Down
2 changes: 0 additions & 2 deletions packages/remix-react/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {

/**
* Data for a route that was returned from a `loader()`.
*
* Note: This moves to unknown in ReactRouter and eventually likely in Remix
*/
export type AppData = any;

Expand Down
22 changes: 10 additions & 12 deletions packages/remix-server-runtime/data.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import type {
ActionFunction,
ActionFunctionArgs,
LoaderFunction,
LoaderFunctionArgs,
} from "@remix-run/router";

import {
redirect,
json,
isDeferredData,
isResponse,
isRedirectStatusCode,
} from "./responses";
import type {
ActionFunction,
DataFunctionArgs,
LoaderFunction,
} from "./routeModules";

/**
* An object of unknown type for route loaders and actions provided by the
* server's `getLoadContext()` function.
* An unknown type for route loaders and actions provided by the server's
* `getLoadContext()` function.
*/
export interface AppLoadContext {
[key: string]: unknown;
}
export type AppLoadContext = any;

/**
* Data for a route that was returned from a `loader()`.
*
* Note: This moves to unknown in ReactRouter and eventually likely in Remix
*/
export type AppData = any;

Expand Down
4 changes: 2 additions & 2 deletions packages/remix-server-runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export type {

// Remix server runtime packages should re-export these types
export type {
ActionArgs,
ActionFunction,
ActionFunctionArgs,
AppData,
AppLoadContext,
Cookie,
Expand All @@ -53,8 +53,8 @@ export type {
HtmlLinkDescriptor,
LinkDescriptor,
LinksFunction,
LoaderArgs,
LoaderFunction,
LoaderFunctionArgs,
MemoryUploadHandlerFilterArgs,
MemoryUploadHandlerOptions,
HandleErrorFunction,
Expand Down
12 changes: 7 additions & 5 deletions packages/remix-server-runtime/reexport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export type { ErrorResponse } from "@remix-run/router";
export type {
ActionFunction,
ActionFunctionArgs,
ErrorResponse,
LoaderFunction,
LoaderFunctionArgs,
} from "@remix-run/router";

brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
export type {
HandleDataRequestFunction,
Expand Down Expand Up @@ -37,14 +43,10 @@ export type {
export type { TypedDeferredData, TypedResponse } from "./responses";

export type {
ActionArgs,
ActionFunction,
DataFunctionArgs,
HeadersArgs,
HeadersFunction,
LinksFunction,
LoaderArgs,
LoaderFunction,
RouteHandle,
ServerRuntimeMetaArgs,
ServerRuntimeMetaDescriptor,
Expand Down
54 changes: 12 additions & 42 deletions packages/remix-server-runtime/routeModules.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
import type { AgnosticRouteMatch, Location, Params } from "@remix-run/router";

import type { AppLoadContext, AppData } from "./data";
import type {
ActionFunction,
ActionFunctionArgs,
AgnosticRouteMatch,
LoaderFunction,
LoaderFunctionArgs,
Location,
Params,
} from "@remix-run/router";

import type { AppData } from "./data";
import type { LinkDescriptor } from "./links";
import type { SerializeFrom } from "./serialize";

export interface RouteModules<RouteModule> {
[routeId: string]: RouteModule;
}

/**
* The arguments passed to ActionFunction and LoaderFunction.
*
* Note this is almost identical to React Router's version but over there the
* context is optional since it's only there during static handler invocations.
* Keeping Remix's own definition for now so it can differentiate between
* client/server
*/
export interface DataFunctionArgs {
request: Request;
context: AppLoadContext;
params: Params;
}

export type LoaderArgs = DataFunctionArgs;

export type ActionArgs = DataFunctionArgs;

/**
* A function that handles data mutations for a route.
*/
export interface ActionFunction {
(args: DataFunctionArgs):
| Promise<Response>
| Response
| Promise<AppData>
| AppData;
}
export type DataFunctionArgs = LoaderFunctionArgs | ActionFunctionArgs;

export type HeadersArgs = {
loaderHeaders: Headers;
Expand All @@ -60,17 +41,6 @@ export interface LinksFunction {
(): LinkDescriptor[];
}

/**
* A function that loads data for a route.
*/
export interface LoaderFunction {
(args: DataFunctionArgs):
| Promise<Response>
| Response
| Promise<AppData>
| AppData;
}

/**
* A function that returns an array of data objects to use for rendering
* metadata HTML tags in a route. These tags are not rendered on descendant
Expand Down
Loading