@@ -21,7 +21,7 @@ interface CachedRedirectValue {
21
21
}
22
22
23
23
interface CachedRouteValue {
24
- kind : "ROUTE" ;
24
+ kind : "ROUTE" | "APP_ROUTE" ;
25
25
// this needs to be a RenderResult so since renderResponse
26
26
// expects that type instead of a string
27
27
body : Buffer ;
@@ -39,7 +39,7 @@ interface CachedImageValue {
39
39
}
40
40
41
41
interface IncrementalCachedPageValue {
42
- kind : "PAGE" ;
42
+ kind : "PAGE" | "PAGES" ;
43
43
// this needs to be a string since the cache expects to store
44
44
// the string value
45
45
html : string ;
@@ -48,9 +48,21 @@ interface IncrementalCachedPageValue {
48
48
headers ?: Record < string , undefined | string > ;
49
49
}
50
50
51
+ interface IncrementalCachedAppPageValue {
52
+ kind : "APP_PAGE" ;
53
+ // this needs to be a string since the cache expects to store
54
+ // the string value
55
+ html : string ;
56
+ rscData : Buffer ;
57
+ headers ?: Record < string , undefined | string | string [ ] > ;
58
+ postponed ?: string ;
59
+ status ?: number ;
60
+ }
61
+
51
62
type IncrementalCacheValue =
52
63
| CachedRedirectValue
53
64
| IncrementalCachedPageValue
65
+ | IncrementalCachedAppPageValue
54
66
| CachedImageValue
55
67
| CachedFetchValue
56
68
| CachedRouteValue ;
@@ -94,6 +106,7 @@ declare global {
94
106
var disableDynamoDBCache : boolean ;
95
107
var disableIncrementalCache : boolean ;
96
108
var lastModified : Record < string , number > ;
109
+ var isNextAfter15 : boolean ;
97
110
}
98
111
// We need to use globalThis client here as this class can be defined at load time in next 12 but client is not available at load time
99
112
export default class S3Cache {
@@ -203,7 +216,7 @@ export default class S3Cache {
203
216
return {
204
217
lastModified : _lastModified ,
205
218
value : {
206
- kind : "ROUTE" ,
219
+ kind : globalThis . isNextAfter15 ? "APP_ROUTE" : "ROUTE" ,
207
220
body : Buffer . from (
208
221
cacheData . body ?? Buffer . alloc ( 0 ) ,
209
222
isBinaryContentType ( String ( meta ?. headers ?. [ "content-type" ] ) )
@@ -215,10 +228,22 @@ export default class S3Cache {
215
228
} ,
216
229
} as CacheHandlerValue ;
217
230
} else if ( cacheData ?. type === "page" || cacheData ?. type === "app" ) {
231
+ if ( globalThis . isNextAfter15 && cacheData ?. type === "app" ) {
232
+ return {
233
+ lastModified : _lastModified ,
234
+ value : {
235
+ kind : "APP_PAGE" ,
236
+ html : cacheData . html ,
237
+ rscData : Buffer . from ( cacheData . rsc ) ,
238
+ status : meta ?. status ,
239
+ headers : meta ?. headers ,
240
+ } ,
241
+ } as CacheHandlerValue ;
242
+ }
218
243
return {
219
244
lastModified : _lastModified ,
220
245
value : {
221
- kind : "PAGE" ,
246
+ kind : globalThis . isNextAfter15 ? "PAGES" : "PAGE" ,
222
247
html : cacheData . html ,
223
248
pageData :
224
249
cacheData . type === "page" ? cacheData . json : cacheData . rsc ,
@@ -259,7 +284,7 @@ export default class S3Cache {
259
284
. getStore ( )
260
285
?. pendingPromiseRunner . withResolvers < void > ( ) ;
261
286
try {
262
- if ( data ?. kind === "ROUTE" ) {
287
+ if ( data ?. kind === "ROUTE" || data ?. kind === "APP_ROUTE" ) {
263
288
const { body, status, headers } = data ;
264
289
await globalThis . incrementalCache . set (
265
290
key ,
@@ -277,8 +302,8 @@ export default class S3Cache {
277
302
} ,
278
303
false ,
279
304
) ;
280
- } else if ( data ?. kind === "PAGE" ) {
281
- const { html, pageData } = data ;
305
+ } else if ( data ?. kind === "PAGE" || data ?. kind === "PAGES" ) {
306
+ const { html, pageData, status , headers } = data ;
282
307
const isAppPath = typeof pageData === "string" ;
283
308
if ( isAppPath ) {
284
309
await globalThis . incrementalCache . set (
@@ -287,6 +312,10 @@ export default class S3Cache {
287
312
type : "app" ,
288
313
html,
289
314
rsc : pageData ,
315
+ meta : {
316
+ status,
317
+ headers,
318
+ } ,
290
319
} ,
291
320
false ,
292
321
) ;
@@ -301,6 +330,21 @@ export default class S3Cache {
301
330
false ,
302
331
) ;
303
332
}
333
+ } else if ( data ?. kind === "APP_PAGE" ) {
334
+ const { html, rscData, headers, status } = data ;
335
+ await globalThis . incrementalCache . set (
336
+ key ,
337
+ {
338
+ type : "app" ,
339
+ html,
340
+ rsc : rscData . toString ( "utf8" ) ,
341
+ meta : {
342
+ status,
343
+ headers,
344
+ } ,
345
+ } ,
346
+ false ,
347
+ ) ;
304
348
} else if ( data ?. kind === "FETCH" ) {
305
349
await globalThis . incrementalCache . set < true > ( key , data , true ) ;
306
350
} else if ( data ?. kind === "REDIRECT" ) {
0 commit comments