Skip to content

Commit

Permalink
fix: patch fetch in the fetch handler instead of global scope (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-elicx authored Nov 11, 2023
1 parent 500edef commit ee237f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-eggs-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

Patch the fetch function inside the fetch handler, instead of in the global scope.
4 changes: 2 additions & 2 deletions packages/next-on-pages/templates/_worker.js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ declare const __BUILD_OUTPUT__: VercelBuildOutput;

declare const __ENV_ALS_PROMISE__: Promise<null | AsyncLocalStorage<unknown>>;

patchFetch();

export default {
async fetch(request, env, ctx) {
patchFetch();

const envAsyncLocalStorage = await __ENV_ALS_PROMISE__;
if (!envAsyncLocalStorage) {
const reqUrl = new URL(request.url);
Expand Down

0 comments on commit ee237f3

Please sign in to comment.