Skip to content

Commit cc2df21

Browse files
committed
use already existing trackBackgroundWork helper from request context to handle next/after
1 parent 15825be commit cc2df21

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/run/handlers/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import { nextResponseProxy } from '../revalidate.js'
1616

1717
import { createRequestContext, getLogger, getRequestContext } from './request-context.cjs'
1818
import { getTracer } from './tracer.cjs'
19-
import { setWaitUntil } from './wait-until.cjs'
19+
import { setupWaitUntil } from './wait-until.cjs'
2020

2121
const nextImportPromise = import('../next.cjs')
2222

23+
setupWaitUntil()
24+
2325
let nextHandler: WorkerRequestHandler, nextConfig: NextConfigComplete
2426

2527
/**
@@ -53,7 +55,7 @@ interface FutureContext extends Context {
5355

5456
export default async (request: Request, context: FutureContext) => {
5557
const tracer = getTracer()
56-
setWaitUntil(context)
58+
5759
if (!nextHandler) {
5860
await tracer.withActiveSpan('initialize next server', async () => {
5961
// set the server config

src/run/handlers/wait-until.cts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getRequestContext } from './request-context.cjs'
2+
13
/**
24
* @see https://github.com/vercel/next.js/blob/canary/packages/next/src/server/after/builtin-request-context.ts
35
*/
@@ -14,15 +16,11 @@ type GlobalThisWithRequestContext = typeof globalThis & {
1416
/**
1517
* Registers a `waitUntil` to be used by Next.js for next/after
1618
*/
17-
18-
export function setWaitUntil({ waitUntil }: { waitUntil?: (promise: Promise<unknown>) => void }) {
19-
if (!waitUntil) {
20-
return
21-
}
19+
export function setupWaitUntil() {
2220
// eslint-disable-next-line @typescript-eslint/no-extra-semi
2321
;(globalThis as GlobalThisWithRequestContext)[NEXT_REQUEST_CONTEXT_SYMBOL] = {
2422
get() {
25-
return { waitUntil }
23+
return { waitUntil: getRequestContext()?.trackBackgroundWork }
2624
},
2725
}
2826
}

0 commit comments

Comments
 (0)