File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
packages/next/src/server/after Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -135,9 +135,18 @@ export function createAfterContext({
135
135
: callback ( ) )
136
136
137
137
// NOTE: if the callback returns a stream, there may still be components that'll execute later,
138
- // which means that more callbacks can be added.
139
- // TODO: can we call onClose lazily?
140
- onClose ( ( ) => runCallbacks ( requestStore ) )
138
+ // which means that more callbacks can be added after this point.
139
+
140
+ // `onClose` is not available in static generation.
141
+ // after() calls will throw and bail out anyway, but streaming can make them happen later,
142
+ // so we don't want to crash here.
143
+ const hasOnClose =
144
+ ! staticGenerationAsyncStorage . getStore ( ) ?. isStaticGeneration
145
+
146
+ if ( hasOnClose ) {
147
+ // TODO: can we call onClose lazily somehow?
148
+ onClose ( ( ) => runCallbacks ( requestStore ) )
149
+ }
141
150
return res
142
151
} finally {
143
152
// if something failed, make sure the request doesn't stay open forever.
You can’t perform that action at this time.
0 commit comments