Unverified Commit 887a419d authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

fix: clone response in first handler to prevent race (#70082) (#70649)

This fixes a race where if the body was resolved before the clone
operation, it would clone later, resulting in an error being thrown due
to the body already being consumed.

backports #70082

---------
Co-authored-by: 's avatarWyatt Johnson <accounts+github@wyattjoh.ca>
parent 73f6b7dc
...@@ -738,7 +738,11 @@ function createPatchedFetcher( ...@@ -738,7 +738,11 @@ function createPatchedFetcher(
return res.clone() return res.clone()
} }
return (staticGenerationStore.pendingRevalidates[cacheKey] = return (staticGenerationStore.pendingRevalidates[cacheKey] =
doOriginalFetch(true, cacheReasonOverride).finally(async () => { doOriginalFetch(true, cacheReasonOverride)
.then((res) => {
return res.clone()
})
.finally(async () => {
staticGenerationStore.pendingRevalidates ??= {} staticGenerationStore.pendingRevalidates ??= {}
delete staticGenerationStore.pendingRevalidates[cacheKey || ''] delete staticGenerationStore.pendingRevalidates[cacheKey || '']
await handleUnlock() await handleUnlock()
...@@ -757,7 +761,7 @@ function createPatchedFetcher( ...@@ -757,7 +761,7 @@ function createPatchedFetcher(
patched.__nextGetStaticStore = () => staticGenerationAsyncStorage patched.__nextGetStaticStore = () => staticGenerationAsyncStorage
patched._nextOriginalFetch = originFetch patched._nextOriginalFetch = originFetch
return patched return patched as PatchedFetcher
} }
// we patch fetch to collect cache information used for // we patch fetch to collect cache information used for
......
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