Skip to content

Commit

Permalink
Resolve hanging promise when prerendering is aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Jan 14, 2025
1 parent a908bb9 commit 837b7de
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/next/src/server/use-cache/use-cache-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,21 @@ async function generateCacheEntryImpl(

// The encoded arguments might contain hanging promises. In this
// case we don't want to reject with "Error: Connection closed.",
// so we intentionally keep the iterable alive. This is the same
// halting trick that we do for rendering as well.
await new Promise(() => {})
// so we intentionally keep the iterable alive. This is similar to
// the halting trick that we do while rendering.
if (outerWorkUnitStore?.type === 'prerender') {
await new Promise<void>((resolve) => {
if (outerWorkUnitStore.renderSignal.aborted) {
resolve()
} else {
outerWorkUnitStore.renderSignal.addEventListener(
'abort',
() => resolve(),
{ once: true }
)
}
})
}
},
},
getServerModuleMap(),
Expand Down

0 comments on commit 837b7de

Please sign in to comment.