From cb55276cce0e29e92230e5c94a6259aba47f671d Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Tue, 30 Jul 2024 13:16:14 +0300 Subject: [PATCH] fix(remix): Fix issue where request body has already been read (#3839) --- .changeset/bright-crabs-speak.md | 5 +++++ packages/remix/src/ssr/utils.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/bright-crabs-speak.md diff --git a/.changeset/bright-crabs-speak.md b/.changeset/bright-crabs-speak.md new file mode 100644 index 00000000000..15b3714a904 --- /dev/null +++ b/.changeset/bright-crabs-speak.md @@ -0,0 +1,5 @@ +--- +"@clerk/remix": patch +--- + +Fixed a bug that was caused when the request body has already been read diff --git a/packages/remix/src/ssr/utils.ts b/packages/remix/src/ssr/utils.ts index d4e8a6f7a14..e1e1f129296 100644 --- a/packages/remix/src/ssr/utils.ts +++ b/packages/remix/src/ssr/utils.ts @@ -125,10 +125,18 @@ export const wrapWithClerkState = (data: any) => { * @internal */ export const patchRequest = (request: Request) => { - const clonedRequest = request.clone(); + const clonedRequest = new Request(request.url, { + headers: request.headers, + method: request.method, + redirect: request.redirect, + cache: request.cache, + signal: request.signal, + }); + // If duplex is not set, set it to 'half' to avoid duplex issues with unidici if (clonedRequest.method !== 'GET' && clonedRequest.body !== null && !('duplex' in clonedRequest)) { (clonedRequest as unknown as { duplex: 'half' }).duplex = 'half'; } + return clonedRequest; };