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,11 +738,15 @@ function createPatchedFetcher(
return res.clone()
}
return (staticGenerationStore.pendingRevalidates[cacheKey] =
doOriginalFetch(true, cacheReasonOverride).finally(async () => {
staticGenerationStore.pendingRevalidates ??= {}
delete staticGenerationStore.pendingRevalidates[cacheKey || '']
await handleUnlock()
}))
doOriginalFetch(true, cacheReasonOverride)
.then((res) => {
return res.clone()
})
.finally(async () => {
staticGenerationStore.pendingRevalidates ??= {}
delete staticGenerationStore.pendingRevalidates[cacheKey || '']
await handleUnlock()
}))
} else {
return doOriginalFetch(false, cacheReasonOverride).finally(
handleUnlock
......@@ -757,7 +761,7 @@ function createPatchedFetcher(
patched.__nextGetStaticStore = () => staticGenerationAsyncStorage
patched._nextOriginalFetch = originFetch
return patched
return patched as PatchedFetcher
}
// 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