Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/next/src/server/web/spec-extension/unstable-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,14 @@ export function unstable_cache<T extends Callback>(
)

if (!workStore.isDraftMode) {
cacheNewResult(
if (!workStore.pendingRevalidates) {
workStore.pendingRevalidates = {}
}

// We need to push the cache result promise to pending
// revalidates otherwise it won't be awaited and is just
// dangling
workStore.pendingRevalidates[invocationKey] = cacheNewResult(
result,
incrementalCache,
cacheKey,
Expand Down Expand Up @@ -330,7 +337,11 @@ export function unstable_cache<T extends Callback>(
cb,
...args
)
cacheNewResult(

// we need to wait setting the new cache result here as
// we don't have pending revalidates on workStore to
// push to and we can't have a dangling promise
await cacheNewResult(
result,
incrementalCache,
cacheKey,
Expand Down