diff --git a/packages/next/src/server/lib/patch-fetch.ts b/packages/next/src/server/lib/patch-fetch.ts index fa904881c5d3b..29cac001b617c 100644 --- a/packages/next/src/server/lib/patch-fetch.ts +++ b/packages/next/src/server/lib/patch-fetch.ts @@ -306,43 +306,6 @@ export function patchFetch({ console.error(`Failed to generate cache key for`, input) } } - const requestInputFields = [ - 'cache', - 'credentials', - 'headers', - 'integrity', - 'keepalive', - 'method', - 'mode', - 'redirect', - 'referrer', - 'referrerPolicy', - 'signal', - 'window', - 'duplex', - ] - - if (isRequestInput) { - const reqInput: Request = input as any - const reqOptions: RequestInit = { - body: (reqInput as any)._ogBody || reqInput.body, - } - - for (const field of requestInputFields) { - // @ts-expect-error custom fields - reqOptions[field] = reqInput[field] - } - input = new Request(reqInput.url, reqOptions) - } else if (init) { - const initialInit = init - init = { - body: (init as any)._ogBody || init.body, - } - for (const field of requestInputFields) { - // @ts-expect-error custom fields - init[field] = initialInit[field] - } - } const fetchIdx = staticGenerationStore.nextFetchId ?? 1 staticGenerationStore.nextFetchId = fetchIdx + 1 @@ -354,6 +317,46 @@ export function patchFetch({ isStale?: boolean, cacheReasonOverride?: string ) => { + const requestInputFields = [ + 'cache', + 'credentials', + 'headers', + 'integrity', + 'keepalive', + 'method', + 'mode', + 'redirect', + 'referrer', + 'referrerPolicy', + 'window', + 'duplex', + + // don't pass through signal when revalidating + ...(isStale ? [] : ['signal']), + ] + + if (isRequestInput) { + const reqInput: Request = input as any + const reqOptions: RequestInit = { + body: (reqInput as any)._ogBody || reqInput.body, + } + + for (const field of requestInputFields) { + // @ts-expect-error custom fields + reqOptions[field] = reqInput[field] + } + input = new Request(reqInput.url, reqOptions) + } else if (init) { + const initialInit = init + init = { + body: (init as any)._ogBody || init.body, + } + for (const field of requestInputFields) { + // @ts-expect-error custom fields + init[field] = initialInit[field] + } + } + // add metadata to init without editing the original const clonedInit = { ...init,