From 317e872bbfbc4a2ee844618364cab1bc6141ed56 Mon Sep 17 00:00:00 2001 From: James Anderson Date: Mon, 6 May 2024 11:11:11 +0100 Subject: [PATCH] fix fetch patch hanging promise by moving symbol to globalThis (#770) --- .changeset/itchy-cheetahs-design.md | 5 +++++ packages/next-on-pages/templates/_worker.js/utils/fetch.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/itchy-cheetahs-design.md diff --git a/.changeset/itchy-cheetahs-design.md b/.changeset/itchy-cheetahs-design.md new file mode 100644 index 000000000..818a68714 --- /dev/null +++ b/.changeset/itchy-cheetahs-design.md @@ -0,0 +1,5 @@ +--- +'@cloudflare/next-on-pages': patch +--- + +Fix hanging promise caused by fetch patch symbol diff --git a/packages/next-on-pages/templates/_worker.js/utils/fetch.ts b/packages/next-on-pages/templates/_worker.js/utils/fetch.ts index da353ceb7..2784189fd 100644 --- a/packages/next-on-pages/templates/_worker.js/utils/fetch.ts +++ b/packages/next-on-pages/templates/_worker.js/utils/fetch.ts @@ -5,13 +5,13 @@ import { handleSuspenseCacheRequest } from './cache'; * to work */ export function patchFetch(): void { - const alreadyPatched = (globalThis.fetch as Fetch)[patchFlagSymbol]; + const alreadyPatched = (globalThis as GlobalWithPatchSymbol)[patchFlagSymbol]; if (alreadyPatched) return; applyPatch(); - (globalThis.fetch as Fetch)[patchFlagSymbol] = true; + (globalThis as GlobalWithPatchSymbol)[patchFlagSymbol] = true; } function applyPatch() { @@ -117,4 +117,4 @@ function setRequestUserAgentIfNeeded( const patchFlagSymbol = Symbol.for('next-on-pages fetch patch'); -type Fetch = typeof globalThis.fetch & { [patchFlagSymbol]: boolean }; +type GlobalWithPatchSymbol = typeof globalThis & { [patchFlagSymbol]: boolean };