File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { nextResponseProxy } from '../revalidate.js'
1616
1717import { createRequestContext , getLogger , getRequestContext } from './request-context.cjs'
1818import { getTracer } from './tracer.cjs'
19+ import { setWaitUntil } from './wait-until.cjs'
1920
2021const nextImportPromise = import ( '../next.cjs' )
2122
@@ -52,7 +53,7 @@ interface FutureContext extends Context {
5253
5354export default async ( request : Request , context : FutureContext ) => {
5455 const tracer = getTracer ( )
55-
56+ setWaitUntil ( context )
5657 if ( ! nextHandler ) {
5758 await tracer . withActiveSpan ( 'initialize next server' , async ( ) => {
5859 // set the server config
Original file line number Diff line number Diff line change 1+ /**
2+ * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/server/after/builtin-request-context.ts
3+ */
4+ const NEXT_REQUEST_CONTEXT_SYMBOL = Symbol . for ( '@next/request-context' )
5+
6+ export type NextJsRequestContext = {
7+ get ( ) : { waitUntil ?: ( promise : Promise < unknown > ) => void } | undefined
8+ }
9+
10+ type GlobalThisWithRequestContext = typeof globalThis & {
11+ [ NEXT_REQUEST_CONTEXT_SYMBOL ] ?: NextJsRequestContext
12+ }
13+
14+ /**
15+ * Registers a `waitUntil` to be used by Next.js for next/after
16+ */
17+
18+ export function setWaitUntil ( { waitUntil } : { waitUntil ?: ( promise : Promise < unknown > ) => void } ) {
19+ if ( ! waitUntil ) {
20+ return
21+ }
22+ // eslint-disable-next-line @typescript-eslint/no-extra-semi
23+ ; ( globalThis as GlobalThisWithRequestContext ) [ NEXT_REQUEST_CONTEXT_SYMBOL ] = {
24+ get ( ) {
25+ return { waitUntil }
26+ } ,
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments