@@ -3256,49 +3256,6 @@ export default abstract class Server<
32563256
32573257 const { value : cachedData } = cacheEntry
32583258
3259- if (
3260- typeof segmentPrefetchHeader === 'string' &&
3261- cachedData ?. kind === CachedRouteKind . APP_PAGE &&
3262- cachedData . segmentData
3263- ) {
3264- // This is a prefetch request issued by the client Segment Cache. These
3265- // should never reach the application layer (lambda). We should either
3266- // respond from the cache (HIT) or respond with 204 No Content (MISS).
3267-
3268- // Set a header to indicate that PPR is enabled for this route. This
3269- // lets the client distinguish between a regular cache miss and a cache
3270- // miss due to PPR being disabled. In other contexts this header is used
3271- // to indicate that the response contains dynamic data, but here we're
3272- // only using it to indicate that the feature is enabled — the segment
3273- // response itself contains whether the data is dynamic.
3274- res . setHeader ( NEXT_DID_POSTPONE_HEADER , '2' )
3275-
3276- const matchedSegment = cachedData . segmentData . get ( segmentPrefetchHeader )
3277- if ( matchedSegment !== undefined ) {
3278- // Cache hit
3279- return {
3280- type : 'rsc' ,
3281- body : RenderResult . fromStatic ( matchedSegment ) ,
3282- // TODO: Eventually this should use cache control of the individual
3283- // segment, not the whole page.
3284- cacheControl : cacheEntry . cacheControl ,
3285- }
3286- }
3287-
3288- // Cache miss. Either a cache entry for this route has not been generated
3289- // (which technically should not be possible when PPR is enabled, because
3290- // at a minimum there should always be a fallback entry) or there's no
3291- // match for the requested segment. Respond with a 204 No Content. We
3292- // don't bother to respond with 404, because these requests are only
3293- // issued as part of a prefetch.
3294- res . statusCode = 204
3295- return {
3296- type : 'rsc' ,
3297- body : RenderResult . fromStatic ( '' ) ,
3298- cacheControl : cacheEntry ?. cacheControl ,
3299- }
3300- }
3301-
33023259 // If the cache value is an image, we should error early.
33033260 if ( cachedData ?. kind === CachedRouteKind . IMAGE ) {
33043261 throw new InvariantError ( 'SSG should not return an image cache value' )
@@ -3379,6 +3336,56 @@ export default abstract class Server<
33793336
33803337 cacheEntry . cacheControl = cacheControl
33813338
3339+ if (
3340+ typeof segmentPrefetchHeader === 'string' &&
3341+ cachedData ?. kind === CachedRouteKind . APP_PAGE &&
3342+ cachedData . segmentData
3343+ ) {
3344+ // This is a prefetch request issued by the client Segment Cache. These
3345+ // should never reach the application layer (lambda). We should either
3346+ // respond from the cache (HIT) or respond with 204 No Content (MISS).
3347+
3348+ // Set a header to indicate that PPR is enabled for this route. This
3349+ // lets the client distinguish between a regular cache miss and a cache
3350+ // miss due to PPR being disabled. In other contexts this header is used
3351+ // to indicate that the response contains dynamic data, but here we're
3352+ // only using it to indicate that the feature is enabled — the segment
3353+ // response itself contains whether the data is dynamic.
3354+ res . setHeader ( NEXT_DID_POSTPONE_HEADER , '2' )
3355+
3356+ // Add the cache tags header to the response if it exists and we're in
3357+ // minimal mode while rendering a static page.
3358+ const tags = cachedData . headers ?. [ NEXT_CACHE_TAGS_HEADER ]
3359+ if ( this . minimalMode && isSSG && tags && typeof tags === 'string' ) {
3360+ res . setHeader ( NEXT_CACHE_TAGS_HEADER , tags )
3361+ }
3362+
3363+ const matchedSegment = cachedData . segmentData . get ( segmentPrefetchHeader )
3364+ if ( matchedSegment !== undefined ) {
3365+ // Cache hit
3366+ return {
3367+ type : 'rsc' ,
3368+ body : RenderResult . fromStatic ( matchedSegment ) ,
3369+ // TODO: Eventually this should use cache control of the individual
3370+ // segment, not the whole page.
3371+ cacheControl : cacheEntry . cacheControl ,
3372+ }
3373+ }
3374+
3375+ // Cache miss. Either a cache entry for this route has not been generated
3376+ // (which technically should not be possible when PPR is enabled, because
3377+ // at a minimum there should always be a fallback entry) or there's no
3378+ // match for the requested segment. Respond with a 204 No Content. We
3379+ // don't bother to respond with 404, because these requests are only
3380+ // issued as part of a prefetch.
3381+ res . statusCode = 204
3382+ return {
3383+ type : 'rsc' ,
3384+ body : RenderResult . fromStatic ( '' ) ,
3385+ cacheControl : cacheEntry ?. cacheControl ,
3386+ }
3387+ }
3388+
33823389 // If there's a callback for `onCacheEntry`, call it with the cache entry
33833390 // and the revalidate options.
33843391 const onCacheEntry = getRequestMeta ( req , 'onCacheEntry' )
@@ -3520,15 +3527,11 @@ export default abstract class Server<
35203527 }
35213528 }
35223529
3523- if (
3524- this . minimalMode &&
3525- isSSG &&
3526- cachedData . headers ?. [ NEXT_CACHE_TAGS_HEADER ]
3527- ) {
3528- res . setHeader (
3529- NEXT_CACHE_TAGS_HEADER ,
3530- cachedData . headers [ NEXT_CACHE_TAGS_HEADER ] as string
3531- )
3530+ // Add the cache tags header to the response if it exists and we're in
3531+ // minimal mode while rendering a static page.
3532+ const tags = cachedData . headers ?. [ NEXT_CACHE_TAGS_HEADER ]
3533+ if ( this . minimalMode && isSSG && tags && typeof tags === 'string' ) {
3534+ res . setHeader ( NEXT_CACHE_TAGS_HEADER , tags )
35323535 }
35333536
35343537 // If the request is a data request, then we shouldn't set the status code
0 commit comments