@@ -183,37 +183,54 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
183183
184184 private async injectEntryToPrerenderManifest (
185185 key : string ,
186- revalidate : NetlifyCachedPageValue [ 'revalidate' ] ,
186+ { revalidate, cacheControl } : Pick < NetlifyCachedPageValue , 'revalidate' | 'cacheControl' > ,
187187 ) {
188- if ( this . options . serverDistDir && ( typeof revalidate === 'number' || revalidate === false ) ) {
188+ if (
189+ this . options . serverDistDir &&
190+ ( typeof revalidate === 'number' ||
191+ revalidate === false ||
192+ typeof cacheControl !== 'undefined' )
193+ ) {
189194 try {
190195 const { loadManifest } = await import ( 'next/dist/server/load-manifest.js' )
191196 const prerenderManifest = loadManifest (
192197 join ( this . options . serverDistDir , '..' , 'prerender-manifest.json' ) ,
193198 ) as PrerenderManifest
194199
195- try {
196- const { normalizePagePath } = await import (
197- 'next/dist/shared/lib/page-path/normalize-page-path.js'
198- )
199-
200- prerenderManifest . routes [ key ] = {
201- experimentalPPR : undefined ,
202- dataRoute : posixJoin ( '/_next/data' , `${ normalizePagePath ( key ) } .json` ) ,
203- srcRoute : null , // FIXME: provide actual source route, however, when dynamically appending it doesn't really matter
204- initialRevalidateSeconds : revalidate ,
205- // Pages routes do not have a prefetch data route.
206- prefetchDataRoute : undefined ,
200+ if ( typeof revalidate === 'number' || revalidate === false ) {
201+ try {
202+ const { normalizePagePath } = await import (
203+ 'next/dist/shared/lib/page-path/normalize-page-path.js'
204+ )
205+
206+ prerenderManifest . routes [ key ] = {
207+ experimentalPPR : undefined ,
208+ dataRoute : posixJoin ( '/_next/data' , `${ normalizePagePath ( key ) } .json` ) ,
209+ srcRoute : null , // FIXME: provide actual source route, however, when dynamically appending it doesn't really matter
210+ initialRevalidateSeconds : revalidate ,
211+ // Pages routes do not have a prefetch data route.
212+ prefetchDataRoute : undefined ,
213+ }
214+ } catch {
215+ // depending on Next.js version - prerender manifest might not be mutable
216+ // https://github.com/vercel/next.js/pull/64313
217+ // if it's not mutable we will try to use SharedRevalidateTimings ( https://github.com/vercel/next.js/pull/64370) instead
218+ const { SharedRevalidateTimings } = await import (
219+ 'next/dist/server/lib/incremental-cache/shared-revalidate-timings.js'
220+ )
221+ const sharedRevalidateTimings = new SharedRevalidateTimings ( prerenderManifest )
222+ sharedRevalidateTimings . set ( key , revalidate )
207223 }
208- } catch {
209- // depending on Next.js version - prerender manifest might not be mutable
210- // https://github.com/vercel/next.js/pull/64313
211- // if it's not mutable we will try to use SharedRevalidateTimings ( https://github.com/vercel/next.js/pull/64370) instead
212- const { SharedRevalidateTimings } = await import (
213- 'next/dist/server/lib/incremental-cache/shared-revalidate-timings.js'
224+ } else if ( typeof cacheControl !== undefined ) {
225+ // instead of `revalidate` property, we might get `cacheControls` ( https://github.com/vercel/next.js/pull/76207 )
226+ // then we need to keep track of revalidate values via SharedCacheControls
227+ const { SharedCacheControls } = await import (
228+ // @ts -expect-error supporting multiple next version, this module is not resolvable with currently used dev dependency
229+ // eslint-disable-next-line import/no-unresolved, n/no-missing-import
230+ 'next/dist/server/lib/incremental-cache/shared-cache-controls.js'
214231 )
215- const sharedRevalidateTimings = new SharedRevalidateTimings ( prerenderManifest )
216- sharedRevalidateTimings . set ( key , revalidate )
232+ const sharedCacheControls = new SharedCacheControls ( prerenderManifest )
233+ sharedCacheControls . set ( key , cacheControl )
217234 }
218235 } catch { }
219236 }
@@ -315,7 +332,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
315332
316333 span . addEvent ( blob . value ?. kind , { lastModified : blob . lastModified , revalidate, ttl } )
317334
318- await this . injectEntryToPrerenderManifest ( key , revalidate )
335+ await this . injectEntryToPrerenderManifest ( key , blob . value )
319336
320337 return {
321338 lastModified : blob . lastModified ,
@@ -327,7 +344,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
327344
328345 span . addEvent ( blob . value ?. kind , { lastModified : blob . lastModified , revalidate, ttl } )
329346
330- await this . injectEntryToPrerenderManifest ( key , revalidate )
347+ await this . injectEntryToPrerenderManifest ( key , blob . value )
331348
332349 return {
333350 lastModified : blob . lastModified ,
@@ -356,6 +373,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
356373 return {
357374 ...data ,
358375 revalidate : context . revalidate ,
376+ cacheControl : context . cacheControl ,
359377 body : data . body . toString ( 'base64' ) ,
360378 }
361379 }
@@ -364,13 +382,15 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
364382 return {
365383 ...data ,
366384 revalidate : context . revalidate ,
385+ cacheControl : context . cacheControl ,
367386 }
368387 }
369388
370389 if ( data ?. kind === 'APP_PAGE' ) {
371390 return {
372391 ...data ,
373392 revalidate : context . revalidate ,
393+ cacheControl : context . cacheControl ,
374394 rscData : data . rscData ?. toString ( 'base64' ) ,
375395 }
376396 }
0 commit comments