From f0427c3ae4beb022369402df012ca593570d82b5 Mon Sep 17 00:00:00 2001 From: George Desipris Date: Thu, 26 Oct 2023 22:57:26 +0300 Subject: [PATCH 1/3] fix(backend): Fix for next 14 fetch bind issue --- packages/backend/src/runtime/index.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/runtime/index.ts b/packages/backend/src/runtime/index.ts index f77338cb6d5..d6c1b3d5851 100644 --- a/packages/backend/src/runtime/index.ts +++ b/packages/backend/src/runtime/index.ts @@ -15,17 +15,12 @@ // @ts-ignore - These are package subpaths import crypto from '#crypto'; // @ts-ignore - These are package subpaths +import fetch from '#fetch'; +// @ts-ignore - These are package subpaths import * as fetchApisPolyfill from '#fetch'; -const { - default: fetch, - RuntimeAbortController, - RuntimeBlob, - RuntimeFormData, - RuntimeHeaders, - RuntimeRequest, - RuntimeResponse, -} = fetchApisPolyfill; +const { RuntimeAbortController, RuntimeBlob, RuntimeFormData, RuntimeHeaders, RuntimeRequest, RuntimeResponse } = + fetchApisPolyfill; type Runtime = { crypto: Crypto; From cdb1862a77936d2694bfd7e2a3865e51fe949fd9 Mon Sep 17 00:00:00 2001 From: Nikos Douvlis Date: Thu, 26 Oct 2023 14:03:44 -0700 Subject: [PATCH 2/3] 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: https://github.com/clerkinc/javascript/pull/612 --- packages/backend/src/runtime/browser/fetch.mjs | 1 + packages/backend/src/runtime/index.ts | 15 ++++++++++----- packages/backend/src/runtime/node/fetch.js | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/runtime/browser/fetch.mjs b/packages/backend/src/runtime/browser/fetch.mjs index 86ef402b1ce..3c3e70ae40f 100644 --- a/packages/backend/src/runtime/browser/fetch.mjs +++ b/packages/backend/src/runtime/browser/fetch.mjs @@ -5,3 +5,4 @@ export const RuntimeHeaders = Headers; export const RuntimeRequest = Request; export const RuntimeResponse = Response; export const RuntimeAbortController = AbortController; +export const RuntimeFetch = fetch; diff --git a/packages/backend/src/runtime/index.ts b/packages/backend/src/runtime/index.ts index d6c1b3d5851..89a1d7c1a77 100644 --- a/packages/backend/src/runtime/index.ts +++ b/packages/backend/src/runtime/index.ts @@ -15,12 +15,17 @@ // @ts-ignore - These are package subpaths import crypto from '#crypto'; // @ts-ignore - These are package subpaths -import fetch from '#fetch'; -// @ts-ignore - These are package subpaths import * as fetchApisPolyfill from '#fetch'; -const { RuntimeAbortController, RuntimeBlob, RuntimeFormData, RuntimeHeaders, RuntimeRequest, RuntimeResponse } = - fetchApisPolyfill; +const { + RuntimeFetch, + RuntimeAbortController, + RuntimeBlob, + RuntimeFormData, + RuntimeHeaders, + RuntimeRequest, + RuntimeResponse, +} = fetchApisPolyfill; type Runtime = { crypto: Crypto; @@ -39,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 = { diff --git a/packages/backend/src/runtime/node/fetch.js b/packages/backend/src/runtime/node/fetch.js index 58b33cabadc..38f0e8de6ea 100644 --- a/packages/backend/src/runtime/node/fetch.js +++ b/packages/backend/src/runtime/node/fetch.js @@ -8,3 +8,4 @@ module.exports.RuntimeHeaders = Headers; module.exports.RuntimeRequest = Request; module.exports.RuntimeResponse = Response; module.exports.RuntimeAbortController = AbortController; +module.exports.RuntimeFetch = fetch; From daaf845fdc30272ba4e00f22830e50fa93dee2f6 Mon Sep 17 00:00:00 2001 From: Nikos Douvlis Date: Fri, 27 Oct 2023 00:08:14 +0300 Subject: [PATCH 3/3] Create late-dolphins-peel.md --- .changeset/late-dolphins-peel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/late-dolphins-peel.md diff --git a/.changeset/late-dolphins-peel.md b/.changeset/late-dolphins-peel.md new file mode 100644 index 00000000000..04e3344490e --- /dev/null +++ b/.changeset/late-dolphins-peel.md @@ -0,0 +1,5 @@ +--- +"@clerk/backend": minor +--- + +Add support for NextJS 14