Skip to content

Commit

Permalink
fix(backend): Support NextJS 14 (#1948)
Browse files Browse the repository at this point in the history
* fix(backend): Fix for next 14 fetch bind issue

* fix(nextjs): Use named imports for fetch runtime polyfill

Next14 seems to have changed the way it handles default exports when using the webpack bundler for some of their build variants when using `npm run dev`. This commit ensures that we no longer use the default export in an effort to improve compat between the different nextjs versions.

 More information can be found here: https://esbuild.github.io/content-types/#default-interop
 and here: #612

* Create late-dolphins-peel.md

---------

Co-authored-by: Nikos Douvlis <[email protected]>
  • Loading branch information
2 people authored and octoper committed Oct 31, 2023
1 parent 9bf530a commit 483ca70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-dolphins-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/backend": minor
---

Add support for NextJS 14
1 change: 1 addition & 0 deletions packages/backend/src/runtime/browser/fetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const RuntimeHeaders = Headers;
export const RuntimeRequest = Request;
export const RuntimeResponse = Response;
export const RuntimeAbortController = AbortController;
export const RuntimeFetch = fetch;
4 changes: 2 additions & 2 deletions packages/backend/src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import crypto from '#crypto';
import * as fetchApisPolyfill from '#fetch';

const {
default: fetch,
RuntimeFetch,
RuntimeAbortController,
RuntimeBlob,
RuntimeFormData,
Expand All @@ -44,7 +44,7 @@ type Runtime = {
// The globalThis object is supported for Node >= 12.0.
//
// https://github.com/supabase/supabase/issues/4417
const globalFetch = fetch.bind(globalThis);
const globalFetch = RuntimeFetch.bind(globalThis);
// DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js
// For more information refer to https://sinonjs.org/how-to/stub-dependency/
const runtime: Runtime = {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/runtime/node/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ module.exports.RuntimeHeaders = Headers;
module.exports.RuntimeRequest = Request;
module.exports.RuntimeResponse = Response;
module.exports.RuntimeAbortController = AbortController;
module.exports.RuntimeFetch = fetch;

0 comments on commit 483ca70

Please sign in to comment.