Skip to content

Commit f96af09

Browse files
committed
initial implementation for creating cache entry blobs from prerendered content for APP_PAGE
1 parent 7ff2745 commit f96af09

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/build/content/prerendered.ts

+32-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import pLimit from 'p-limit'
1010
import { encodeBlobKey } from '../../shared/blobkey.js'
1111
import type {
1212
CachedFetchValue,
13+
NetlifyCachedAppPageValue,
1314
NetlifyCachedPageValue,
1415
NetlifyCachedRouteValue,
1516
NetlifyCacheHandlerValue,
@@ -46,31 +47,45 @@ const buildPagesCacheValue = async (path: string): Promise<NetlifyCachedPageValu
4647
kind: 'PAGE',
4748
html: await readFile(`${path}.html`, 'utf-8'),
4849
pageData: JSON.parse(await readFile(`${path}.json`, 'utf-8')),
49-
postponed: undefined,
5050
headers: undefined,
5151
status: undefined,
5252
})
5353

54-
const buildAppCacheValue = async (path: string): Promise<NetlifyCachedPageValue> => {
54+
const buildAppCacheValue = async (
55+
path: string,
56+
): Promise<NetlifyCachedAppPageValue | NetlifyCachedPageValue> => {
5557
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+
}
6882
}
6983

84+
// use new stuff
7085
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'),
7489
...meta,
7590
}
7691
}

0 commit comments

Comments
 (0)