@@ -10,6 +10,7 @@ import pLimit from 'p-limit'
10
10
import { encodeBlobKey } from '../../shared/blobkey.js'
11
11
import type {
12
12
CachedFetchValue ,
13
+ NetlifyCachedAppPageValue ,
13
14
NetlifyCachedPageValue ,
14
15
NetlifyCachedRouteValue ,
15
16
NetlifyCacheHandlerValue ,
@@ -46,31 +47,45 @@ const buildPagesCacheValue = async (path: string): Promise<NetlifyCachedPageValu
46
47
kind : 'PAGE' ,
47
48
html : await readFile ( `${ path } .html` , 'utf-8' ) ,
48
49
pageData : JSON . parse ( await readFile ( `${ path } .json` , 'utf-8' ) ) ,
49
- postponed : undefined ,
50
50
headers : undefined ,
51
51
status : undefined ,
52
52
} )
53
53
54
- const buildAppCacheValue = async ( path : string ) : Promise < NetlifyCachedPageValue > => {
54
+ const buildAppCacheValue = async (
55
+ path : string ,
56
+ ) : Promise < NetlifyCachedAppPageValue | NetlifyCachedPageValue > => {
55
57
const meta = JSON . parse ( await readFile ( `${ path } .meta` , 'utf-8' ) )
56
- const rsc = await readFile ( `${ path } .rsc` , 'utf-8' ) . catch ( ( ) =>
57
- readFile ( `${ path } .prefetch.rsc` , 'utf-8' ) ,
58
- )
59
-
60
- // Next < v14.2.0 does not set meta.status when notFound() is called directly on a page
61
- // Exclude Parallel routes, they are 404s when visited directly
62
- if (
63
- ! meta . status &&
64
- rsc . includes ( 'NEXT_NOT_FOUND' ) &&
65
- ! meta . headers [ 'x-next-cache-tags' ] . includes ( '/@' )
66
- ) {
67
- meta . status = 404
58
+ const html = await readFile ( `${ path } .html` , 'utf-8' )
59
+
60
+ // TODO: check actual next version and not rely on env var set by tests
61
+ const useOldStuff = process . env . NEXT_VERSION !== 'canary'
62
+ if ( useOldStuff ) {
63
+ const rsc = await readFile ( `${ path } .rsc` , 'utf-8' ) . catch ( ( ) =>
64
+ readFile ( `${ path } .prefetch.rsc` , 'utf-8' ) ,
65
+ )
66
+
67
+ // Next < v14.2.0 does not set meta.status when notFound() is called directly on a page
68
+ // Exclude Parallel routes, they are 404s when visited directly
69
+ if (
70
+ ! meta . status &&
71
+ rsc . includes ( 'NEXT_NOT_FOUND' ) &&
72
+ ! meta . headers [ 'x-next-cache-tags' ] . includes ( '/@' )
73
+ ) {
74
+ meta . status = 404
75
+ }
76
+ return {
77
+ kind : 'PAGE' ,
78
+ html,
79
+ pageData : rsc ,
80
+ ...meta ,
81
+ }
68
82
}
69
83
84
+ // use new stuff
70
85
return {
71
- kind : 'PAGE ' ,
72
- html : await readFile ( ` ${ path } .html` , 'utf-8' ) ,
73
- pageData : rsc ,
86
+ kind : 'APP_PAGE ' ,
87
+ html,
88
+ rscData : await readFile ( ` ${ path } . rsc` , 'base64' ) ,
74
89
...meta ,
75
90
}
76
91
}
0 commit comments