Skip to content

Commit

Permalink
fix(backend,remix): Tweak ClerkRequest initialization to work-around …
Browse files Browse the repository at this point in the history
…edge-runtime and undici limitations (#3129)

* fix(backend,remix): Tweak ClerkRequest initialization to work-around edge-runtime and undici limitations

The usual way to duplicate a request object is to
pass the original request object to the Request constructor
both as the `input` and `init` parameters, eg: super(req, req)
However, this fails in certain environments like Vercel Edge Runtime
when a framework like Remix polyfills the global Request object.
This happens because `undici` performs the following instanceof check
which, instead of testing against the global Request object, tests against
the Request class defined in the same file (local Request class).
For more details, please refer to:
nodejs/undici#2155
https://github.com/nodejs/undici/blob/7153a1c78d51840bbe16576ce353e481c3934701/lib/fetch/request.js#L854

* fix(backend,remix): Tweak ClerkRequest initialization to work-around edge-runtime and undici limitations

The usual way to duplicate a request object is to
pass the original request object to the Request constructor
both as the `input` and `init` parameters, eg: super(req, req)
However, this fails in certain environments like Vercel Edge Runtime
when a framework like Remix polyfills the global Request object.
This happens because `undici` performs the following instanceof check
which, instead of testing against the global Request object, tests against
the Request class defined in the same file (local Request class).
For more details, please refer to:
nodejs/undici#2155
https://github.com/nodejs/undici/blob/7153a1c78d51840bbe16576ce353e481c3934701/lib/fetch/request.js#L854
  • Loading branch information
nikosdouvlis authored Apr 6, 2024
1 parent 4073707 commit 63dfe8d
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 814 deletions.
6 changes: 6 additions & 0 deletions .changeset/lovely-planets-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/backend': patch
'@clerk/remix': patch
---

Resolve Vercel edge-runtime "TypeError: Failed to parse URL" when `@clerk/remix` is used
Loading

0 comments on commit 63dfe8d

Please sign in to comment.