Skip to content

Commit 4aca054

Browse files
committed
fix: include .html files for ODB functions
1 parent 4770dfe commit 4aca054

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

demos/default/netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build]
2-
command = "next build"
2+
command = "# next build"
33
publish = ".next"
44
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
55

packages/runtime/src/helpers/functions.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { basename, extname } from 'path'
2+
13
import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
24
import bridgeFile from '@vercel/node-bridge'
35
import chalk from 'chalk'
46
import destr from 'destr'
57
import { copyFile, ensureDir, existsSync, readJSON, writeFile, writeJSON, stat } from 'fs-extra'
8+
import type { PrerenderManifest } from 'next/dist/build'
69
import type { ImageConfigComplete, RemotePattern } from 'next/dist/shared/lib/image-config'
710
import { outdent } from 'outdent'
811
import { join, relative, resolve, dirname } from 'pathe'
@@ -300,6 +303,34 @@ const getBundleWeight = async (patterns: string[]) => {
300303
return sum(sizes.flat(1))
301304
}
302305

306+
const changeExtension = (file: string, extension: string) => {
307+
const base = basename(file, extname(file))
308+
return join(dirname(file), base + extension)
309+
}
310+
311+
const getSSRDependencies = async (publish: string): Promise<string[]> => {
312+
const prerenderManifest: PrerenderManifest = await readJSON(join(publish, 'prerender-manifest.json'))
313+
314+
return Object.entries(prerenderManifest.routes).flatMap(([route, ssgRoute]) => {
315+
if (ssgRoute.initialRevalidateSeconds === false) {
316+
return []
317+
}
318+
319+
if (ssgRoute.dataRoute.endsWith('.rsc')) {
320+
return [
321+
join(publish, 'server', 'app', ssgRoute.dataRoute),
322+
join(publish, 'server', 'app', changeExtension(ssgRoute.dataRoute, '.html')),
323+
]
324+
}
325+
326+
const trimmedPath = route === '/' ? 'index' : route.slice(1)
327+
return [
328+
join(publish, 'server', 'pages', `${trimmedPath}.html`),
329+
join(publish, 'server', 'pages', `${trimmedPath}.json`),
330+
]
331+
})
332+
}
333+
303334
export const getSSRLambdas = async (publish: string, baseDir: string): Promise<SSRLambda[]> => {
304335
const commonDependencies = await getCommonDependencies(publish, baseDir)
305336
const ssrRoutes = await getSSRRoutes(publish)
@@ -308,6 +339,8 @@ export const getSSRLambdas = async (publish: string, baseDir: string): Promise<S
308339
const nonOdbRoutes = ssrRoutes
309340
const odbRoutes = ssrRoutes
310341

342+
const ssrDependencies = await getSSRDependencies(publish)
343+
311344
return [
312345
{
313346
functionName: HANDLER_FUNCTION_NAME,
@@ -316,14 +349,14 @@ export const getSSRLambdas = async (publish: string, baseDir: string): Promise<S
316349
},
317350
{
318351
functionName: ODB_FUNCTION_NAME,
319-
includedFiles: [...commonDependencies, ...odbRoutes.flatMap((route) => route.includedFiles)],
352+
includedFiles: [...commonDependencies, ...odbRoutes.flatMap((route) => route.includedFiles), ...ssrDependencies],
320353
routes: odbRoutes,
321354
},
322355
]
323356
}
324357

325358
// TODO: check if there's any other glob specialties missing
326-
const escapeGlob = (path: string) => path.replace(/\[/g, '*').replace(/\]/g, '*')
359+
const escapeGlob = (path: string) => path.replace(/\[/g, '*').replace(/]/g, '*')
327360

328361
const getSSRRoutes = async (publish: string): Promise<RouteConfig[]> => {
329362
const pages = (await readJSON(join(publish, 'server', 'pages-manifest.json'))) as Record<string, string>

0 commit comments

Comments
 (0)