@@ -148,6 +148,7 @@ export type AppRenderContext = AppRenderBaseContext & {
148
148
serverComponentsErrorHandler : ErrorHandler
149
149
isNotFoundPath : boolean
150
150
res : ServerResponse
151
+ builtInWaitUntil : RenderOpts [ 'builtInWaitUntil' ]
151
152
}
152
153
153
154
function createNotFoundLoaderTree ( loaderTree : LoaderTree ) : LoaderTree {
@@ -387,12 +388,23 @@ async function generateFlight(
387
388
ctx . staticGenerationStore . pendingRevalidates ||
388
389
ctx . staticGenerationStore . revalidatedTags
389
390
) {
390
- resultOptions . waitUntil = Promise . all ( [
391
+ const pendingPromise = Promise . all ( [
391
392
ctx . staticGenerationStore . incrementalCache ?. revalidateTag (
392
393
ctx . staticGenerationStore . revalidatedTags || [ ]
393
394
) ,
394
395
...Object . values ( ctx . staticGenerationStore . pendingRevalidates || { } ) ,
395
- ] )
396
+ ] ) . finally ( ( ) => {
397
+ if ( process . env . NEXT_PRIVATE_DEBUG_CACHE ) {
398
+ console . log ( 'pending revalidates promise finished for:' , urlPathname )
399
+ }
400
+ } )
401
+
402
+ // use built-in waitUntil if available
403
+ if ( ctx . builtInWaitUntil ) {
404
+ ctx . builtInWaitUntil ( pendingPromise )
405
+ } else {
406
+ resultOptions . waitUntil = pendingPromise
407
+ }
396
408
}
397
409
398
410
return new FlightRenderResult ( flightReadableStream , resultOptions )
@@ -848,6 +860,7 @@ async function renderToHTMLOrFlightImpl(
848
860
849
861
const ctx : AppRenderContext = {
850
862
...baseCtx ,
863
+ builtInWaitUntil : renderOpts . builtInWaitUntil ,
851
864
getDynamicParamFromSegment,
852
865
query,
853
866
isPrefetch : isPrefetchRSCRequest ,
@@ -1401,12 +1414,23 @@ async function renderToHTMLOrFlightImpl(
1401
1414
staticGenerationStore . pendingRevalidates ||
1402
1415
staticGenerationStore . revalidatedTags
1403
1416
) {
1404
- options . waitUntil = Promise . all ( [
1417
+ const pendingPromise = Promise . all ( [
1405
1418
staticGenerationStore . incrementalCache ?. revalidateTag (
1406
1419
staticGenerationStore . revalidatedTags || [ ]
1407
1420
) ,
1408
1421
...Object . values ( staticGenerationStore . pendingRevalidates || { } ) ,
1409
- ] )
1422
+ ] ) . finally ( ( ) => {
1423
+ if ( process . env . NEXT_PRIVATE_DEBUG_CACHE ) {
1424
+ console . log ( 'pending revalidates promise finished for:' , req . url )
1425
+ }
1426
+ } )
1427
+
1428
+ // use built-in waitUntil if available
1429
+ if ( renderOpts . builtInWaitUntil ) {
1430
+ renderOpts . builtInWaitUntil ( pendingPromise )
1431
+ } else {
1432
+ options . waitUntil = pendingPromise
1433
+ }
1410
1434
}
1411
1435
1412
1436
addImplicitTags ( staticGenerationStore )
0 commit comments