@@ -37,7 +37,10 @@ import {
37
37
getRuntimeStagePromise ,
38
38
} from '../app-render/work-unit-async-storage.external'
39
39
40
- import { makeHangingPromise } from '../dynamic-rendering-utils'
40
+ import {
41
+ makeDevtoolsIOAwarePromise ,
42
+ makeHangingPromise ,
43
+ } from '../dynamic-rendering-utils'
41
44
42
45
import type { ClientReferenceManifestForRsc } from '../../build/webpack/plugins/flight-manifest-plugin'
43
46
@@ -467,10 +470,20 @@ async function collectResult(
467
470
// whether or not this cache should have its life & tags propagated when
468
471
// we read the entry in the final prerender from the resume data cache.
469
472
470
- // TODO(restart-on-cache-miss): might need to do the same here?
471
473
break
472
474
}
473
- case 'request' :
475
+ case 'request' : {
476
+ if (
477
+ process . env . NODE_ENV === 'development' &&
478
+ outerWorkUnitStore . cacheSignal
479
+ ) {
480
+ // If we're filling caches for a dev request, apply the same logic as prerenders do above,
481
+ // and don't propagate cache life/tags yet.
482
+ break
483
+ }
484
+ // fallthrough
485
+ }
486
+
474
487
case 'private-cache' :
475
488
case 'cache' :
476
489
case 'unstable-cache' :
@@ -986,14 +999,32 @@ export function cache(
986
999
? createHangingInputAbortSignal ( workUnitStore )
987
1000
: undefined
988
1001
989
- // In a runtime prerender, we have to make sure that APIs that would hang during a static prerender
990
- // are resolved with a delay, in the runtime stage. Private caches are one of these.
991
1002
if ( cacheContext . kind === 'private' ) {
992
- const runtimeStagePromise = getRuntimeStagePromise (
993
- cacheContext . outerWorkUnitStore
994
- )
995
- if ( runtimeStagePromise ) {
996
- await runtimeStagePromise
1003
+ const { outerWorkUnitStore } = cacheContext
1004
+ switch ( outerWorkUnitStore . type ) {
1005
+ case 'prerender-runtime' : {
1006
+ // In a runtime prerender, we have to make sure that APIs that would hang during a static prerender
1007
+ // are resolved with a delay, in the runtime stage. Private caches are one of these.
1008
+ if ( outerWorkUnitStore . runtimeStagePromise ) {
1009
+ await outerWorkUnitStore . runtimeStagePromise
1010
+ }
1011
+ break
1012
+ }
1013
+ case 'request' : {
1014
+ if ( process . env . NODE_ENV === 'development' ) {
1015
+ // Similar to runtime prerenders, private caches should not resolve in the static stage
1016
+ // of a dev request, so we delay them.
1017
+ // When we implement the 3-task render, this will change to match the codepath above.
1018
+ // (to resolve them in the runtime stage, and not later)
1019
+ await makeDevtoolsIOAwarePromise ( undefined )
1020
+ }
1021
+ break
1022
+ }
1023
+ case 'private-cache' :
1024
+ break
1025
+ default : {
1026
+ outerWorkUnitStore satisfies never
1027
+ }
997
1028
}
998
1029
}
999
1030
@@ -1237,9 +1268,20 @@ export function cache(
1237
1268
}
1238
1269
break
1239
1270
}
1271
+ case 'request' : {
1272
+ if ( process . env . NODE_ENV === 'development' ) {
1273
+ // We delay the cache here so that it doesn't resolve in the static task --
1274
+ // in a regular static prerender, it'd be a hanging promise, and we need to reflect that,
1275
+ // so it has to resolve later.
1276
+ // TODO(restart-on-cache-miss): Optimize this to avoid unnecessary restarts.
1277
+ // We don't end the cache read here, so this will always appear as a cache miss in the static stage,
1278
+ // and thus will cause a restart even if all caches are filled.
1279
+ await makeDevtoolsIOAwarePromise ( undefined )
1280
+ }
1281
+ break
1282
+ }
1240
1283
case 'prerender-ppr' :
1241
1284
case 'prerender-legacy' :
1242
- case 'request' :
1243
1285
case 'cache' :
1244
1286
case 'private-cache' :
1245
1287
case 'unstable-cache' :
@@ -1423,10 +1465,21 @@ export function cache(
1423
1465
workStore . route ,
1424
1466
'dynamic "use cache"'
1425
1467
)
1468
+ case 'request' : {
1469
+ if ( process . env . NODE_ENV === 'development' ) {
1470
+ // We delay the cache here so that it doesn't resolve in the static task --
1471
+ // in a regular static prerender, it'd be a hanging promise, and we need to reflect that,
1472
+ // so it has to resolve later.
1473
+ // TODO(restart-on-cache-miss): Optimize this to avoid unnecessary restarts.
1474
+ // We don't end the cache read here, so this will always appear as a cache miss in the static stage,
1475
+ // and thus will cause a restart even if all caches are filled.
1476
+ await makeDevtoolsIOAwarePromise ( undefined )
1477
+ }
1478
+ break
1479
+ }
1426
1480
case 'prerender-runtime' :
1427
1481
case 'prerender-ppr' :
1428
1482
case 'prerender-legacy' :
1429
- case 'request' :
1430
1483
case 'cache' :
1431
1484
case 'private-cache' :
1432
1485
case 'unstable-cache' :
0 commit comments