File tree 2 files changed +30
-1
lines changed
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'
16
16
17
17
import { createRequestContext , getLogger , getRequestContext } from './request-context.cjs'
18
18
import { getTracer } from './tracer.cjs'
19
+ import { setWaitUntil } from './wait-until.cjs'
19
20
20
21
const nextImportPromise = import ( '../next.cjs' )
21
22
@@ -52,7 +53,7 @@ interface FutureContext extends Context {
52
53
53
54
export default async ( request : Request , context : FutureContext ) => {
54
55
const tracer = getTracer ( )
55
-
56
+ setWaitUntil ( context )
56
57
if ( ! nextHandler ) {
57
58
await tracer . withActiveSpan ( 'initialize next server' , async ( ) => {
58
59
// 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