From daffde4be654f91e07bbeca814e35fff9aeb5071 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 23 Aug 2023 16:51:49 -0400 Subject: [PATCH 1/2] Export ErrorResponse type --- .changeset/error-response-type.md | 9 ++++++ packages/remix-cloudflare/index.ts | 1 + packages/remix-deno/index.ts | 1 + packages/remix-node/index.ts | 1 + packages/remix-react/errors.ts | 4 +-- packages/remix-react/index.tsx | 1 + packages/remix-react/package.json | 4 +-- .../__tests__/handle-error-test.ts | 8 ++--- packages/remix-server-runtime/index.ts | 1 + packages/remix-server-runtime/package.json | 2 +- packages/remix-server-runtime/reexport.ts | 2 ++ packages/remix-testing/package.json | 4 +-- yarn.lock | 30 +++++++++---------- 13 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 .changeset/error-response-type.md diff --git a/.changeset/error-response-type.md b/.changeset/error-response-type.md new file mode 100644 index 00000000000..e605d9c9859 --- /dev/null +++ b/.changeset/error-response-type.md @@ -0,0 +1,9 @@ +--- +"@remix-run/cloudflare": patch +"@remix-run/deno": patch +"@remix-run/node": patch +"@remix-run/react": patch +"@remix-run/server-runtime": patch +--- + +Export proper `ErrorResponse` type for usage alongside `isRouteErrorResponse` diff --git a/packages/remix-cloudflare/index.ts b/packages/remix-cloudflare/index.ts index 3b7e0b9992c..33f0769bd35 100644 --- a/packages/remix-cloudflare/index.ts +++ b/packages/remix-cloudflare/index.ts @@ -38,6 +38,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HeadersArgs, diff --git a/packages/remix-deno/index.ts b/packages/remix-deno/index.ts index bd4b73be0d6..cf121bfb5e0 100644 --- a/packages/remix-deno/index.ts +++ b/packages/remix-deno/index.ts @@ -41,6 +41,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, diff --git a/packages/remix-node/index.ts b/packages/remix-node/index.ts index 7003c1aa54e..c74d8ed25cf 100644 --- a/packages/remix-node/index.ts +++ b/packages/remix-node/index.ts @@ -58,6 +58,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HeadersArgs, diff --git a/packages/remix-react/errors.ts b/packages/remix-react/errors.ts index c2d95c6496a..dd98cbc16e1 100644 --- a/packages/remix-react/errors.ts +++ b/packages/remix-react/errors.ts @@ -1,5 +1,5 @@ import type { Router as RemixRouter } from "@remix-run/router"; -import { ErrorResponse } from "@remix-run/router"; +import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@remix-run/router"; export function deserializeErrors( errors: RemixRouter["state"]["errors"] @@ -11,7 +11,7 @@ export function deserializeErrors( // Hey you! If you change this, please change the corresponding logic in // serializeErrors in remix-server-runtime/errors.ts :) if (val && val.__type === "RouteErrorResponse") { - serialized[key] = new ErrorResponse( + serialized[key] = new ErrorResponseImpl( val.status, val.statusText, val.data, diff --git a/packages/remix-react/index.tsx b/packages/remix-react/index.tsx index c995f615e40..e07c7818693 100644 --- a/packages/remix-react/index.tsx +++ b/packages/remix-react/index.tsx @@ -1,6 +1,7 @@ export type { RemixBrowserProps } from "./browser"; export { RemixBrowser } from "./browser"; export type { + ErrorResponse, Fetcher, FetcherWithComponents, FormEncType, diff --git a/packages/remix-react/package.json b/packages/remix-react/package.json index 445e094e045..0eb8c7a4876 100644 --- a/packages/remix-react/package.json +++ b/packages/remix-react/package.json @@ -16,9 +16,9 @@ "typings": "dist/index.d.ts", "module": "dist/esm/index.js", "dependencies": { - "@remix-run/router": "0.0.0-experimental-4286521e", + "@remix-run/router": "0.0.0-experimental-7b1bbb00", "@remix-run/server-runtime": "1.19.3", - "react-router-dom": "0.0.0-experimental-4286521e" + "react-router-dom": "0.0.0-experimental-7b1bbb00" }, "devDependencies": { "@testing-library/jest-dom": "^5.17.0", diff --git a/packages/remix-server-runtime/__tests__/handle-error-test.ts b/packages/remix-server-runtime/__tests__/handle-error-test.ts index dcc88f0fd64..439823b5bdb 100644 --- a/packages/remix-server-runtime/__tests__/handle-error-test.ts +++ b/packages/remix-server-runtime/__tests__/handle-error-test.ts @@ -1,4 +1,4 @@ -import { ErrorResponse } from "@remix-run/router"; +import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@remix-run/router"; import type { ServerBuild } from "../build"; import { createRequestHandler } from "../server"; @@ -56,7 +56,7 @@ describe("handleError", () => { let request = new Request("http://example.com/", { method: "post" }); await handler(request); expect(handleErrorSpy).toHaveBeenCalledWith( - new ErrorResponse( + new ErrorResponseImpl( 405, "Method Not Allowed", new Error( @@ -126,7 +126,7 @@ describe("handleError", () => { }); await handler(request); expect(handleErrorSpy).toHaveBeenCalledWith( - new ErrorResponse( + new ErrorResponseImpl( 405, "Method Not Allowed", new Error( @@ -182,7 +182,7 @@ describe("handleError", () => { }); await handler(request); expect(handleErrorSpy).toHaveBeenCalledWith( - new ErrorResponse( + new ErrorResponseImpl( 405, "Method Not Allowed", new Error( diff --git a/packages/remix-server-runtime/index.ts b/packages/remix-server-runtime/index.ts index 038b6518e94..78cdc15aa5d 100644 --- a/packages/remix-server-runtime/index.ts +++ b/packages/remix-server-runtime/index.ts @@ -44,6 +44,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, FlashSessionData, HandleDataRequestFunction, HandleDocumentRequestFunction, diff --git a/packages/remix-server-runtime/package.json b/packages/remix-server-runtime/package.json index 90703972579..861045b0e95 100644 --- a/packages/remix-server-runtime/package.json +++ b/packages/remix-server-runtime/package.json @@ -16,7 +16,7 @@ "typings": "dist/index.d.ts", "module": "dist/esm/index.js", "dependencies": { - "@remix-run/router": "0.0.0-experimental-4286521e", + "@remix-run/router": "0.0.0-experimental-7b1bbb00", "@types/cookie": "^0.4.1", "@web3-storage/multipart-parser": "^1.0.0", "cookie": "^0.4.1", diff --git a/packages/remix-server-runtime/reexport.ts b/packages/remix-server-runtime/reexport.ts index db3d948e8b1..3b366baac9c 100644 --- a/packages/remix-server-runtime/reexport.ts +++ b/packages/remix-server-runtime/reexport.ts @@ -1,3 +1,5 @@ +export type { ErrorResponse } from "@remix-run/router"; + export type { HandleDataRequestFunction, HandleDocumentRequestFunction, diff --git a/packages/remix-testing/package.json b/packages/remix-testing/package.json index 557a0561be1..14756c44afa 100644 --- a/packages/remix-testing/package.json +++ b/packages/remix-testing/package.json @@ -18,8 +18,8 @@ "dependencies": { "@remix-run/node": "1.19.3", "@remix-run/react": "1.19.3", - "@remix-run/router": "0.0.0-experimental-4286521e", - "react-router-dom": "0.0.0-experimental-4286521e" + "@remix-run/router": "0.0.0-experimental-7b1bbb00", + "react-router-dom": "0.0.0-experimental-7b1bbb00" }, "devDependencies": { "@types/node": "^18.17.1", diff --git a/yarn.lock b/yarn.lock index f161055e2d5..531de19b2cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2125,10 +2125,10 @@ "@changesets/types" "^5.0.0" dotenv "^8.1.0" -"@remix-run/router@0.0.0-experimental-4286521e": - version "0.0.0-experimental-4286521e" - resolved "https://registry.npmjs.org/@remix-run/router/-/router-0.0.0-experimental-4286521e.tgz#3db770e0b9dc726251add1728c2e647095e476e0" - integrity sha512-tVqZUnmYwcfTMgo9sF4Ny8MdAWzLMeq5NY3Xsw36jmy9i3PQwM+hXlqE8Ilg43WeJQyP3Co5gdegKHdd7aC/zQ== +"@remix-run/router@0.0.0-experimental-7b1bbb00": + version "0.0.0-experimental-7b1bbb00" + resolved "https://registry.npmjs.org/@remix-run/router/-/router-0.0.0-experimental-7b1bbb00.tgz#53e8f0f94d4ae59cc5c96472582b9eed4277fc0c" + integrity sha512-ftRs73TmSs1muFgzrFqglifvRQKL4IXPp+FWpB+Vro9nPrYJrvT9U0zxqPpNOa11LT6zYH2+2YVsWsjfHnbErw== "@remix-run/web-blob@^3.0.5": version "3.0.5" @@ -10121,20 +10121,20 @@ react-refresh@^0.14.0: resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz" integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ== -react-router-dom@0.0.0-experimental-4286521e: - version "0.0.0-experimental-4286521e" - resolved "https://registry.npmjs.org/react-router-dom/-/react-router-dom-0.0.0-experimental-4286521e.tgz#cb55ade67811d252e76b6a9dc675d17005dac70b" - integrity sha512-+ByHVuOeVABXbZe/enX32/QvJ8g47ILx6r7Iu8xqUxrE7vN1Gk4DTuB/s4frLRT8RtDC5xw+xoMTG9Ojzc+H9A== +react-router-dom@0.0.0-experimental-7b1bbb00: + version "0.0.0-experimental-7b1bbb00" + resolved "https://registry.npmjs.org/react-router-dom/-/react-router-dom-0.0.0-experimental-7b1bbb00.tgz#ac53ec77036ec4de08719677370b0dbd6a94a976" + integrity sha512-fGWVuY0LVaSM+FloQ9urDy1e1a9fX5Pq/lNP1dSnA2az2+M9qAkOeadSOdR0IMJmJU3l8rsh688Arhg/j3QAPQ== dependencies: - "@remix-run/router" "0.0.0-experimental-4286521e" - react-router "0.0.0-experimental-4286521e" + "@remix-run/router" "0.0.0-experimental-7b1bbb00" + react-router "0.0.0-experimental-7b1bbb00" -react-router@0.0.0-experimental-4286521e: - version "0.0.0-experimental-4286521e" - resolved "https://registry.npmjs.org/react-router/-/react-router-0.0.0-experimental-4286521e.tgz#0a78a34b1322d016956af796762e84bc2948e64c" - integrity sha512-hLyGDdQOVLEMnJ0xflGtLmCPX10cI7dLBJKnPq5BGG8dixE5L+Av9imM8j9rU7Qm67NDHrp1xcPkVLS9oCFuvg== +react-router@0.0.0-experimental-7b1bbb00: + version "0.0.0-experimental-7b1bbb00" + resolved "https://registry.npmjs.org/react-router/-/react-router-0.0.0-experimental-7b1bbb00.tgz#eae87bbfba7d28265ea55287b97c95eb147f7e91" + integrity sha512-7fdfoYJKv73CqivkA8VwXpkF+juw6GflK3HSXVQ+5wC/49for/+2mxk3Y/294C17xRSqiLeTb4mHC/olwNeZeQ== dependencies: - "@remix-run/router" "0.0.0-experimental-4286521e" + "@remix-run/router" "0.0.0-experimental-7b1bbb00" react@^18.2.0: version "18.2.0" From 54e445f9bfcce0ccb83ff65f759fc77c19f310a9 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Thu, 24 Aug 2023 10:45:40 -0400 Subject: [PATCH 2/2] Fix TS error --- packages/remix-server-runtime/server.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index 227f5bd0627..de63313644f 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -51,7 +51,10 @@ export const createRequestHandler: CreateRequestHandlerFunction = ( build.entry.module.handleError || ((error, { request }) => { if (serverMode !== ServerMode.Test && !request.signal.aborted) { - console.error(isRouteErrorResponse(error) ? error.error : error); + console.error( + // @ts-expect-error This is "private" from users but intended for internal use + isRouteErrorResponse(error) && error.error ? error.error : error + ); } }); @@ -225,6 +228,7 @@ async function handleDocumentRequestRR( // Sanitize errors outside of development environments if (context.errors) { Object.values(context.errors).forEach((err) => { + // @ts-expect-error This is "private" from users but intended for internal use if (!isRouteErrorResponse(err) || err.error) { handleError(err); } @@ -353,6 +357,7 @@ function errorResponseToJson( ): Response { return routerJson( serializeError( + // @ts-expect-error This is "private" from users but intended for internal use errorResponse.error || new Error("Unexpected Server Error"), serverMode ),