Skip to content

Commit 534213a

Browse files
fix(remix-server-runtime): don't use React types (#5713)
Co-authored-by: Matt Brophy <matt@brophy.org>
1 parent 1de6ca4 commit 534213a

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

.changeset/fix-react-types.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/server-runtime": patch
3+
---
4+
5+
Fix typing issues when using React 17 stemming from `@remix/server-runtime` including `@types/react` as a `devDependency` when it doesn't actually do anything React-specific and was just re-exporting `ComponentType` in values such as `CatchBoundaryComponent`/`ErrorBoundaryComponent`/`V2_ErrorBoundaryComponent`. These types are more correctly exported from `@remix-run/react` which is React-aware so that is the correct place to be importing those types from. In order to avoid breaking existing builds, the types in `@remix/server-runtime` have been loosened to `any` and `@deprecated` warnings have been added informing users to switch to the corresponding types in `@remix-run/react`.

.changeset/types-cookie.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/server-runtime": patch
3+
---
4+
5+
Move `@types/cookie` to `dependencies` since we re-export types from there

packages/remix-react/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@remix-run/server-runtime": "1.17.0",
2424
"@testing-library/jest-dom": "^5.16.2",
2525
"@testing-library/react": "^13.3.0",
26+
"@types/react": "^18.0.15",
2627
"abort-controller": "^3.0.0",
2728
"react": "^18.2.0",
2829
"react-dom": "^18.2.0"

packages/remix-server-runtime/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
"module": "dist/esm/index.js",
1818
"dependencies": {
1919
"@remix-run/router": "1.6.3",
20+
"@types/cookie": "^0.4.1",
2021
"@web3-storage/multipart-parser": "^1.0.0",
2122
"cookie": "^0.4.1",
2223
"set-cookie-parser": "^2.4.8",
2324
"source-map": "^0.7.3"
2425
},
2526
"devDependencies": {
2627
"@remix-run/web-file": "^3.0.2",
27-
"@types/cookie": "^0.4.0",
28-
"@types/react": "^18.0.15",
2928
"@types/set-cookie-parser": "^2.4.1"
3029
},
3130
"engines": {

packages/remix-server-runtime/routeModules.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
Params,
55
RouterState,
66
} from "@remix-run/router";
7-
import type { ComponentType } from "react";
87

98
import type { AppLoadContext, AppData } from "./data";
109
import type { LinkDescriptor } from "./links";
@@ -48,23 +47,31 @@ export interface ActionFunction {
4847
/**
4948
* A React component that is rendered when the server throws a Response.
5049
*
51-
* @deprecated Please enable the v2_errorBoundary flag
50+
* @deprecated Please enable the v2_errorBoundary flag to eliminate the need
51+
* for this type. If you are still using this, please use `@remix-run/react`'s
52+
* `CatchBoundaryComponent` type
5253
*/
53-
export type CatchBoundaryComponent = ComponentType;
54+
export type CatchBoundaryComponent = any;
5455

5556
/**
5657
* A React component that is rendered when there is an error on a route.
5758
*
58-
* @deprecated Please enable the v2_errorBoundary flag
59+
* @deprecated Please enable the v2_errorBoundary flag to eliminate the need
60+
* for this type. If you are still using this, please use `@remix-run/react`'s
61+
* `ErrorBoundaryComponent` type
5962
*/
60-
export type ErrorBoundaryComponent = ComponentType<{ error: Error }>;
63+
export type ErrorBoundaryComponent = any;
6164

6265
/**
6366
* V2 version of the ErrorBoundary that eliminates the distinction between
6467
* Error and Catch Boundaries and behaves like RR 6.4 errorElement and captures
6568
* errors with useRouteError()
69+
*
70+
* @deprecated Please enable the v2_errorBoundary flag to eliminate the need
71+
* for this type. If you are still using this, please use `@remix-run/react`'s
72+
* `V2_ErrorBoundaryComponent` type
6673
*/
67-
export type V2_ErrorBoundaryComponent = ComponentType;
74+
export type V2_ErrorBoundaryComponent = any;
6875

6976
export type HeadersArgs = {
7077
loaderHeaders: Headers;
@@ -262,8 +269,10 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
262269

263270
/**
264271
* A React component that is rendered for a route.
272+
*
273+
* @deprecated Please use `@remix-run/react`'s `RouteComponent` type instead
265274
*/
266-
export type RouteComponent = ComponentType<{}>;
275+
export type RouteComponent = any;
267276

268277
/**
269278
* An arbitrary object that is associated with a route.

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,7 @@
29432943
resolved "https://registry.npmjs.org/@types/cookie-signature/-/cookie-signature-1.0.3.tgz"
29442944
integrity sha512-0jpd4oizLaBybWBCew/lx4iAjjNWmCfzbspvnjoppyGEquN51BjShmPCksiH2IXLwtxQ2F/e2PkFy0LL7jpLsw==
29452945

2946-
"@types/cookie@^0.4.0", "@types/cookie@^0.4.1":
2946+
"@types/cookie@^0.4.1":
29472947
version "0.4.1"
29482948
resolved "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz"
29492949
integrity sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==

0 commit comments

Comments
 (0)