@@ -37,7 +37,10 @@ import {
3737 getRuntimeStagePromise ,
3838} from '../app-render/work-unit-async-storage.external'
3939
40- import { makeHangingPromise } from '../dynamic-rendering-utils'
40+ import {
41+ makeDevtoolsIOAwarePromise ,
42+ makeHangingPromise ,
43+ } from '../dynamic-rendering-utils'
4144
4245import type { ClientReferenceManifestForRsc } from '../../build/webpack/plugins/flight-manifest-plugin'
4346
@@ -467,10 +470,20 @@ async function collectResult(
467470 // whether or not this cache should have its life & tags propagated when
468471 // we read the entry in the final prerender from the resume data cache.
469472
470- // TODO(restart-on-cache-miss): might need to do the same here?
471473 break
472474 }
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+
474487 case 'private-cache' :
475488 case 'cache' :
476489 case 'unstable-cache' :
@@ -986,14 +999,32 @@ export function cache(
986999 ? createHangingInputAbortSignal ( workUnitStore )
9871000 : undefined
9881001
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.
9911002 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+ }
9971028 }
9981029 }
9991030
@@ -1237,9 +1268,20 @@ export function cache(
12371268 }
12381269 break
12391270 }
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+ }
12401283 case 'prerender-ppr' :
12411284 case 'prerender-legacy' :
1242- case 'request' :
12431285 case 'cache' :
12441286 case 'private-cache' :
12451287 case 'unstable-cache' :
@@ -1423,10 +1465,21 @@ export function cache(
14231465 workStore . route ,
14241466 'dynamic "use cache"'
14251467 )
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+ }
14261480 case 'prerender-runtime' :
14271481 case 'prerender-ppr' :
14281482 case 'prerender-legacy' :
1429- case 'request' :
14301483 case 'cache' :
14311484 case 'private-cache' :
14321485 case 'unstable-cache' :
0 commit comments