Skip to content

Commit

Permalink
don't call onClose in static generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Apr 26, 2024
1 parent 7e80ced commit cf97e74
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/next/src/server/after/after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,18 @@ export function createAfterContext({
: callback())

// NOTE: if the callback returns a stream, there may still be components that'll execute later,
// which means that more callbacks can be added.
// TODO: can we call onClose lazily?
onClose(() => runCallbacks(requestStore))
// which means that more callbacks can be added after this point.

// `onClose` is not available in static generation.
// after() calls will throw and bail out anyway, but streaming can make them happen later,
// so we don't want to crash here.
const hasOnClose =
!staticGenerationAsyncStorage.getStore()?.isStaticGeneration

if (hasOnClose) {
// TODO: can we call onClose lazily somehow?
onClose(() => runCallbacks(requestStore))
}
return res
} finally {
// if something failed, make sure the request doesn't stay open forever.
Expand Down

0 comments on commit cf97e74

Please sign in to comment.