Unverified Commit 4f395f56 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix clone response backport (#71115)

Follow-up to https://github.com/vercel/next.js/pull/70649 this tweaks
the backport to properly clone and return original response so that
pending revalidates aren't sharing an already used response.
parent 737c29e4
......@@ -737,16 +737,28 @@ function createPatchedFetcher(
const res: Response = await pendingRevalidate
return res.clone()
}
return (staticGenerationStore.pendingRevalidates[cacheKey] =
doOriginalFetch(true, cacheReasonOverride)
.then((res) => {
return res.clone()
})
.finally(async () => {
staticGenerationStore.pendingRevalidates ??= {}
delete staticGenerationStore.pendingRevalidates[cacheKey || '']
await handleUnlock()
}))
const pendingResponse = doOriginalFetch(true, cacheReasonOverride)
const nextRevalidate = pendingResponse
.then((res) => res.clone())
.finally(() => {
if (cacheKey) {
// If the pending revalidate is not present in the store, then
// we have nothing to delete.
if (!staticGenerationStore.pendingRevalidates?.[cacheKey]) {
return
}
delete staticGenerationStore.pendingRevalidates[cacheKey]
}
})
// Attach the empty catch here so we don't get a "unhandled promise
// rejection" warning
nextRevalidate.catch(() => {})
staticGenerationStore.pendingRevalidates[cacheKey] = nextRevalidate
return pendingResponse
} else {
return doOriginalFetch(false, cacheReasonOverride).finally(
handleUnlock
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment