From 87003489f166bbd1ac4ae74a973476057659a112 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Wed, 18 Jan 2023 09:45:38 -0500 Subject: [PATCH] Remove instanceof check from isRouteErrorResponse --- .changeset/silver-snails-destroy.md | 5 +++++ packages/router/utils.ts | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .changeset/silver-snails-destroy.md diff --git a/.changeset/silver-snails-destroy.md b/.changeset/silver-snails-destroy.md new file mode 100644 index 0000000000..85b4e8347a --- /dev/null +++ b/.changeset/silver-snails-destroy.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +Remove instanceof check from isRouteErrorResponse to avoid bundling issues on the server diff --git a/packages/router/utils.ts b/packages/router/utils.ts index 1a01048c3a..8506e709a1 100644 --- a/packages/router/utils.ts +++ b/packages/router/utils.ts @@ -1395,8 +1395,14 @@ export class ErrorResponse { /** * Check if the given error is an ErrorResponse generated from a 4xx/5xx - * Response throw from an action/loader + * Response thrown from an action/loader */ -export function isRouteErrorResponse(e: any): e is ErrorResponse { - return e instanceof ErrorResponse; +export function isRouteErrorResponse(error: any): error is ErrorResponse { + return ( + error != null && + typeof error.status === "number" && + typeof error.statusText === "string" && + typeof error.internal === "boolean" && + "data" in error + ); }