Skip to content

Commit

Permalink
fix(remix): Fix issue where request body has already been read (#3839)
Browse files Browse the repository at this point in the history
  • Loading branch information
octoper authored and wobsoriano committed Aug 1, 2024
1 parent 3b35bb3 commit cb55276
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/bright-crabs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/remix": patch
---

Fixed a bug that was caused when the request body has already been read
10 changes: 9 additions & 1 deletion packages/remix/src/ssr/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit cb55276

Please sign in to comment.