@@ -183,37 +183,54 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
183
183
184
184
private async injectEntryToPrerenderManifest (
185
185
key : string ,
186
- revalidate : NetlifyCachedPageValue [ 'revalidate' ] ,
186
+ { revalidate, cacheControl } : Pick < NetlifyCachedPageValue , 'revalidate' | 'cacheControl' > ,
187
187
) {
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
+ ) {
189
194
try {
190
195
const { loadManifest } = await import ( 'next/dist/server/load-manifest.js' )
191
196
const prerenderManifest = loadManifest (
192
197
join ( this . options . serverDistDir , '..' , 'prerender-manifest.json' ) ,
193
198
) as PrerenderManifest
194
199
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 )
207
223
}
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'
214
231
)
215
- const sharedRevalidateTimings = new SharedRevalidateTimings ( prerenderManifest )
216
- sharedRevalidateTimings . set ( key , revalidate )
232
+ const sharedCacheControls = new SharedCacheControls ( prerenderManifest )
233
+ sharedCacheControls . set ( key , cacheControl )
217
234
}
218
235
} catch { }
219
236
}
@@ -315,7 +332,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
315
332
316
333
span . addEvent ( blob . value ?. kind , { lastModified : blob . lastModified , revalidate, ttl } )
317
334
318
- await this . injectEntryToPrerenderManifest ( key , revalidate )
335
+ await this . injectEntryToPrerenderManifest ( key , blob . value )
319
336
320
337
return {
321
338
lastModified : blob . lastModified ,
@@ -327,7 +344,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
327
344
328
345
span . addEvent ( blob . value ?. kind , { lastModified : blob . lastModified , revalidate, ttl } )
329
346
330
- await this . injectEntryToPrerenderManifest ( key , revalidate )
347
+ await this . injectEntryToPrerenderManifest ( key , blob . value )
331
348
332
349
return {
333
350
lastModified : blob . lastModified ,
@@ -356,6 +373,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
356
373
return {
357
374
...data ,
358
375
revalidate : context . revalidate ,
376
+ cacheControl : context . cacheControl ,
359
377
body : data . body . toString ( 'base64' ) ,
360
378
}
361
379
}
@@ -364,13 +382,15 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions {
364
382
return {
365
383
...data ,
366
384
revalidate : context . revalidate ,
385
+ cacheControl : context . cacheControl ,
367
386
}
368
387
}
369
388
370
389
if ( data ?. kind === 'APP_PAGE' ) {
371
390
return {
372
391
...data ,
373
392
revalidate : context . revalidate ,
393
+ cacheControl : context . cacheControl ,
374
394
rscData : data . rscData ?. toString ( 'base64' ) ,
375
395
}
376
396
}
0 commit comments