File tree Expand file tree Collapse file tree 7 files changed +50
-12
lines changed
Expand file tree Collapse file tree 7 files changed +50
-12
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @opennextjs/aws " : minor
3+ ---
4+
5+ refactor: ` waitUntil ` passed around via ALS.
6+
7+ BREAKING CHANGE: ` waitUntil ` is passed around via ALS to fix #713 .
8+
9+ ` globalThis.openNextWaitUntil ` is no more available, you can access ` waitUntil `
10+ on the ALS context: ` globalThis.__openNextAls.getStore() `
11+
12+ The ` OpenNextHandler ` signature has changed: the second parameter was a ` StreamCreator ` .
13+ It was changed to be of type ` OpenNextHandlerOptions ` which has both a ` streamCreator ` key
14+ and a ` waitUntil ` key.
15+
16+ If you use a custom wrapper, you need to update the call to the handler as follow:
17+
18+ ``` ts
19+ // before
20+ globalThis .openNextWaitUntil = myWaitUntil ;
21+ handler (internalEvent , myStreamCreator );
22+
23+ // after
24+ handler (internalEvent , { streamCreator: myStreamCreator , waitUntil: myWaitUntil });
25+ ```
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import { resolveImageLoader } from "../core/resolve.js";
3131import { debug , error } from "./logger.js" ;
3232import { optimizeImage } from "./plugins/image-optimization/image-optimization.js" ;
3333import { setNodeEnv } from "./util.js" ;
34+ import type { OpenNextHandlerOptions } from "types/overrides.js" ;
3435
3536setNodeEnv ( ) ;
3637const nextDir = path . join ( __dirname , ".next" ) ;
@@ -59,7 +60,7 @@ export const handler = await createGenericHandler({
5960
6061export async function defaultHandler (
6162 event : InternalEvent ,
62- options ?: { streamCreator ?: StreamCreator ; waitUntil ?: WaitUntil } ,
63+ options ?: OpenNextHandlerOptions ,
6364) : Promise < InternalResult > {
6465 // Images are handled via header and query param information.
6566 debug ( "handler event" , event ) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import type {
22 InternalEvent ,
33 InternalResult ,
44 MiddlewareResult ,
5- WaitUntil ,
65} from "types/open-next" ;
76import { runWithOpenNextRequestContext } from "utils/promise" ;
87
@@ -19,13 +18,14 @@ import routingHandler, {
1918 INTERNAL_HEADER_INITIAL_PATH ,
2019 INTERNAL_HEADER_RESOLVED_ROUTES ,
2120} from "../core/routingHandler" ;
21+ import type { OpenNextHandlerOptions } from "types/overrides" ;
2222
2323globalThis . internalFetch = fetch ;
2424globalThis . __openNextAls = new AsyncLocalStorage ( ) ;
2525
2626const defaultHandler = async (
2727 internalEvent : InternalEvent ,
28- options ?: { waitUntil ?: WaitUntil } ,
28+ options ?: OpenNextHandlerOptions ,
2929) : Promise < InternalResult | MiddlewareResult > => {
3030 const originResolver = await resolveOriginResolver (
3131 globalThis . openNextConfig . middleware ?. originResolver ,
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import routingHandler, {
2222 MIDDLEWARE_HEADER_PREFIX_LEN ,
2323} from "./routingHandler" ;
2424import { requestHandler , setNextjsPrebundledReact } from "./util" ;
25+ import type { OpenNextHandlerOptions } from "types/overrides" ;
2526
2627// This is used to identify requests in the cache
2728globalThis . __openNextAls = new AsyncLocalStorage ( ) ;
@@ -30,10 +31,7 @@ patchAsyncStorage();
3031
3132export async function openNextHandler (
3233 internalEvent : InternalEvent ,
33- options ?: {
34- streamCreator ?: StreamCreator ;
35- waitUntil ?: WaitUntil ;
36- } ,
34+ options ?: OpenNextHandlerOptions
3735) : Promise < InternalResult > {
3836 const initialHeaders = internalEvent . headers ;
3937 // We run everything in the async local storage context so that it is available in the middleware as well as in NextServer
Original file line number Diff line number Diff line change 1- import type { InternalEvent , StreamCreator , WaitUntil } from "types/open-next" ;
2- import type { Wrapper , WrapperHandler } from "types/overrides" ;
1+ import type { InternalEvent } from "types/open-next" ;
2+ import type { OpenNextHandlerOptions , Wrapper , WrapperHandler } from "types/overrides" ;
33
44const dummyWrapper : WrapperHandler = async ( handler , converter ) => {
55 return async (
66 event : InternalEvent ,
7- options ?: { streamCreator ?: StreamCreator ; waitUntil ?: WaitUntil } ,
7+ options ?: OpenNextHandlerOptions ,
88 ) => {
99 return await handler ( event , options ) ;
1010 } ;
Original file line number Diff line number Diff line change @@ -123,12 +123,19 @@ export type Wrapper<
123123 edgeRuntime ?: boolean ;
124124} ;
125125
126+ export type OpenNextHandlerOptions = {
127+ // Create a `Writeable` for streaming responses.
128+ streamCreator ?: StreamCreator ;
129+ // Extends the liftetime of the runtime after the response is returned.
130+ waitUntil ?: WaitUntil ;
131+ } ;
132+
126133export type OpenNextHandler <
127134 E extends BaseEventOrResult = InternalEvent ,
128135 R extends BaseEventOrResult = InternalResult ,
129136> = (
130137 event : E ,
131- options ?: { streamCreator ?: StreamCreator ; waitUntil ?: WaitUntil } ,
138+ options ?: OpenNextHandlerOptions ,
132139) => Promise < R > ;
133140
134141export type Converter <
Original file line number Diff line number Diff line change @@ -102,11 +102,18 @@ function provideNextAfterProvider() {
102102 }
103103}
104104
105+ export type RunWithOpenNextContextOptions = {
106+ // Whether we are in ISR revalidation
107+ isISRRevalidation : boolean ;
108+ // Extends the liftetime of the runtime after the response is returned.
109+ waitUntil ?: WaitUntil ;
110+ } ;
111+
105112export function runWithOpenNextRequestContext < T > (
106113 {
107114 isISRRevalidation,
108115 waitUntil,
109- } : { isISRRevalidation : boolean ; waitUntil ?: WaitUntil } ,
116+ } : RunWithOpenNextContextOptions ,
110117 fn : ( ) => Promise < T > ,
111118) : Promise < T > {
112119 return globalThis . __openNextAls . run (
You can’t perform that action at this time.
0 commit comments