Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/loose-cows-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'next': patch
---

Fix dangling promise in unstable_cache
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