Skip to content

Commit

Permalink
fix: propagate waitUntil from edge runtime sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Jul 18, 2024
1 parent af4c681 commit fbe2fe9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ export default abstract class Server<
)
}

private getWaitUntil(): WaitUntil | undefined {
protected getWaitUntil(): WaitUntil | undefined {
const builtinRequestContext = getBuiltinRequestContext()
if (builtinRequestContext) {
// the platform provided a request context.
Expand Down
14 changes: 12 additions & 2 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,6 @@ export default class NextNodeServer extends BaseServer<
delete query._nextBubbleNoFallback
delete query[NEXT_RSC_UNION_QUERY]

// If we handled the request, we can return early.
// For api routes edge runtime
try {
const handled = await this.runEdgeFunction({
Expand All @@ -987,7 +986,13 @@ export default class NextNodeServer extends BaseServer<
match,
appPaths: null,
})
if (handled) return true
// If we handled the request, we can return early.
if (handled) {
const waitUntil = this.getWaitUntil()
waitUntil?.(handled.waitUntil)

return true
}
} catch (apiError) {
await this.instrumentationOnRequestError(apiError, req, {
routePath: match.definition.page,
Expand Down Expand Up @@ -1947,6 +1952,11 @@ export default class NextNodeServer extends BaseServer<
}
})

const waitUntil = this.getWaitUntil()
if (waitUntil) {
waitUntil(result.waitUntil)
}

const { originalResponse } = params.res
if (result.response.body) {
await pipeToNodeResponse(result.response.body, originalResponse)
Expand Down

0 comments on commit fbe2fe9

Please sign in to comment.