From b2ba5789d9c633044e50f7ab861ef9e006a0b68f Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Fri, 9 Aug 2024 11:16:15 +0200 Subject: [PATCH] Prevent regression of resetting `fetch` --- test/development/app-dir/dev-fetch-hmr/app/layout.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/development/app-dir/dev-fetch-hmr/app/layout.tsx b/test/development/app-dir/dev-fetch-hmr/app/layout.tsx index bc8001d092e80b..2a034e34f48ca7 100644 --- a/test/development/app-dir/dev-fetch-hmr/app/layout.tsx +++ b/test/development/app-dir/dev-fetch-hmr/app/layout.tsx @@ -4,10 +4,16 @@ import { ReactNode } from 'react' const magicNumber = Math.random() const originalFetch = globalThis.fetch -globalThis.fetch = async ( +if (originalFetch.name === 'monkeyPatchedFetch') { + throw new Error( + 'Patching over already patched fetch. This creates a memory leak.' + ) +} + +globalThis.fetch = async function monkeyPatchedFetch( resource: URL | RequestInfo, options?: RequestInit -) => { +) { const request = new Request(resource) if (request.url === 'http://fake.url/secret') {