Skip to content

Commit

Permalink
Close stream when prerendering is aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Jan 18, 2025
1 parent 1180174 commit 2973c5a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/next/src/server/app-render/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,22 @@ export async function decryptActionBoundArgs(
new ReadableStream({
start(controller) {
controller.enqueue(textEncoder.encode(decrypted))
// Explicitly don't close the stream here so that hanging promises are
// not rejected.

if (workUnitStore?.type === 'prerender') {
// Explicitly don't close the stream here (until prerendering is
// complete) so that hanging promises are not rejected.
if (workUnitStore.renderSignal.aborted) {
controller.close()
} else {
workUnitStore.renderSignal.addEventListener(
'abort',
() => controller.close(),
{ once: true }
)
}
} else {
controller.close()
}
},
}),
{
Expand Down

0 comments on commit 2973c5a

Please sign in to comment.