Skip to content

Commit 8c2c040

Browse files
committed
use correct cache kind for initial cache seeding depending on next version
1 parent 7b91eb9 commit 8c2c040

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/build/content/prerendered.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ const writeCacheEntry = async (
4545
*/
4646
const routeToFilePath = (path: string) => (path === '/' ? '/index' : path)
4747

48-
const buildPagesCacheValue = async (path: string): Promise<NetlifyCachedPageValue> => ({
49-
kind: 'PAGES',
48+
const buildPagesCacheValue = async (
49+
path: string,
50+
shouldUseEnumKind: boolean,
51+
): Promise<NetlifyCachedPageValue> => ({
52+
kind: shouldUseEnumKind ? 'PAGES' : 'PAGE',
5053
html: await readFile(`${path}.html`, 'utf-8'),
5154
pageData: JSON.parse(await readFile(`${path}.json`, 'utf-8')),
5255
headers: undefined,
@@ -96,8 +99,9 @@ const buildAppCacheValue = async (
9699
const buildRouteCacheValue = async (
97100
path: string,
98101
initialRevalidateSeconds: number | false,
102+
shouldUseEnumKind: boolean,
99103
): Promise<NetlifyCachedRouteValue> => ({
100-
kind: 'APP_ROUTE',
104+
kind: shouldUseEnumKind ? 'APP_ROUTE' : 'ROUTE',
101105
body: await readFile(`${path}.body`, 'base64'),
102106
...JSON.parse(await readFile(`${path}.meta`, 'utf-8')),
103107
revalidate: initialRevalidateSeconds,
@@ -133,6 +137,12 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
133137
})
134138
: false
135139

140+
const shouldUseEnumKind = ctx.nextVersion
141+
? satisfies(ctx.nextVersion, '>=15.0.0-canary.114 <15.0.0-d || >15.0.0-rc.0', {
142+
includePrerelease: true,
143+
})
144+
: false
145+
136146
await Promise.all(
137147
Object.entries(manifest.routes).map(
138148
([route, meta]): Promise<void> =>
@@ -152,7 +162,10 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
152162
// if pages router returns 'notFound: true', build won't produce html and json files
153163
return
154164
}
155-
value = await buildPagesCacheValue(join(ctx.publishDir, 'server/pages', key))
165+
value = await buildPagesCacheValue(
166+
join(ctx.publishDir, 'server/pages', key),
167+
shouldUseEnumKind,
168+
)
156169
break
157170
case meta.dataRoute?.endsWith('.rsc'):
158171
value = await buildAppCacheValue(
@@ -164,6 +177,7 @@ export const copyPrerenderedContent = async (ctx: PluginContext): Promise<void>
164177
value = await buildRouteCacheValue(
165178
join(ctx.publishDir, 'server/app', key),
166179
meta.initialRevalidateSeconds,
180+
shouldUseEnumKind,
167181
)
168182
break
169183
default:

0 commit comments

Comments
 (0)