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( ...@@ -737,16 +737,28 @@ function createPatchedFetcher(
const res: Response = await pendingRevalidate const res: Response = await pendingRevalidate
return res.clone() return res.clone()
} }
return (staticGenerationStore.pendingRevalidates[cacheKey] = const pendingResponse = doOriginalFetch(true, cacheReasonOverride)
doOriginalFetch(true, cacheReasonOverride) const nextRevalidate = pendingResponse
.then((res) => { .then((res) => res.clone())
return res.clone() .finally(() => {
}) if (cacheKey) {
.finally(async () => { // If the pending revalidate is not present in the store, then
staticGenerationStore.pendingRevalidates ??= {} // we have nothing to delete.
delete staticGenerationStore.pendingRevalidates[cacheKey || ''] if (!staticGenerationStore.pendingRevalidates?.[cacheKey]) {
await handleUnlock() 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 { } else {
return doOriginalFetch(false, cacheReasonOverride).finally( return doOriginalFetch(false, cacheReasonOverride).finally(
handleUnlock 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