Skip to content

Commit

Permalink
fix fetch patch hanging promise by moving symbol to globalThis (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-elicx committed May 6, 2024
1 parent f150546 commit 317e872
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-cheetahs-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

Fix hanging promise caused by fetch patch symbol
6 changes: 3 additions & 3 deletions packages/next-on-pages/templates/_worker.js/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 };

0 comments on commit 317e872

Please sign in to comment.