Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip copying signal field for revalidate #54533

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions packages/next/src/server/lib/patch-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down