File tree 1 file changed +21
-1
lines changed
packages/next/src/server/lib
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -676,7 +676,7 @@ export function createPatchedFetcher(
676
676
// We are dynamically rendering including dev mode. We want to return
677
677
// the response to the caller as soon as possible because it might stream
678
678
// over a very long time.
679
- cloned1
679
+ const cacheSetPromise = cloned1
680
680
. arrayBuffer ( )
681
681
. then ( async ( arrayBuffer ) => {
682
682
const bodyBuffer = Buffer . from ( arrayBuffer )
@@ -710,6 +710,26 @@ export function createPatchedFetcher(
710
710
)
711
711
. finally ( handleUnlock )
712
712
713
+ const pendingRevalidateKey = `cache-set-${ cacheKey } `
714
+ workStore . pendingRevalidates ??= { }
715
+ if ( pendingRevalidateKey in workStore . pendingRevalidates ) {
716
+ // there is already a pending revalidate entry that
717
+ // we need to await to avoid race conditions
718
+ await workStore . pendingRevalidates [ pendingRevalidateKey ]
719
+ }
720
+ workStore . pendingRevalidates [ pendingRevalidateKey ] =
721
+ cacheSetPromise . finally ( ( ) => {
722
+ // If the pending revalidate is not present in the store, then
723
+ // we have nothing to delete.
724
+ if (
725
+ ! workStore . pendingRevalidates ?. [ pendingRevalidateKey ]
726
+ ) {
727
+ return
728
+ }
729
+
730
+ delete workStore . pendingRevalidates [ pendingRevalidateKey ]
731
+ } )
732
+
713
733
return cloned2
714
734
}
715
735
}
You can’t perform that action at this time.
0 commit comments