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 4, 2024
1 parent 849df1c commit 2fb843f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 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 @@ -1680,7 +1680,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
12 changes: 11 additions & 1 deletion packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,12 @@ export default class NextNodeServer extends BaseServer<
})

// If we handled the request, we can return early.
if (handled) return true
if (handled) {
const waitUntil = this.getWaitUntil()
waitUntil?.(handled.waitUntil)

return true
}
}

// If the route was detected as being a Pages API route, then handle
Expand Down Expand Up @@ -1931,6 +1936,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 2fb843f

Please sign in to comment.