Skip to content

Commit eb887c0

Browse files
committed
fix: run prebundledReact if appDir exists in conf
1 parent 276f327 commit eb887c0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/runtime/src/templates/server.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
unlocalizeRoute,
1616
getMatchedRoute,
1717
} from './handlerUtils'
18+
import { join } from 'path'
19+
import { ExperimentalConfigWithLegacy } from '../helpers/utils'
1820

1921
interface NetlifyConfig {
2022
revalidateToken?: string
@@ -30,11 +32,16 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
3032
return this.nextConfig.experimental?.serverActions ? 'experimental' : 'next'
3133
}
3234

35+
protected getManifest(manifest: string) {
36+
// eslint-disable-next-line import/no-dynamic-require
37+
return require(join(this.distDir, manifest))
38+
}
39+
3340
public constructor(options: Options, netlifyConfig: NetlifyConfig) {
3441
super(options)
3542
this.netlifyConfig = netlifyConfig
3643
// copy the prerender manifest so it doesn't get mutated by Next.js
37-
const manifest = this.getPrerenderManifest()
44+
const manifest = this.getPrerenderManifest() || this.getManifest('prerender-manifest.json')
3845
this.netlifyPrerenderManifest = {
3946
...manifest,
4047
routes: { ...manifest.routes },
@@ -53,7 +60,8 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
5360
const { url, headers } = req
5461

5562
// conditionally use the prebundled React module
56-
this.netlifyPrebundleReact(url, this.nextConfig, parsedUrl)
63+
const { appDir }: ExperimentalConfigWithLegacy = this.nextConfig.experimental
64+
if (appDir) this.netlifyPrebundleReact(url, this.nextConfig, parsedUrl)
5765

5866
// intercept on-demand revalidation requests and handle with the Netlify API
5967
if (headers['x-prerender-revalidate'] && this.netlifyConfig.revalidateToken) {
@@ -83,12 +91,12 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
8391

8492
// doing what they do in https://github.com/vercel/vercel/blob/1663db7ca34d3dd99b57994f801fb30b72fbd2f3/packages/next/src/server-build.ts#L576-L580
8593
private async netlifyPrebundleReact(path: string, { basePath, trailingSlash }: NextConfig, parsedUrl) {
86-
const routesManifest = this.getRoutesManifest?.()
94+
const routesManifest = this.getRoutesManifest?.() || this.getManifest('routes-manifest.json')
8795
const appPathsRoutes = this.getAppPathRoutes?.()
8896
const routes = routesManifest && [...routesManifest.staticRoutes, ...routesManifest.dynamicRoutes]
8997
const matchedRoute = await getMatchedRoute(path, routes, parsedUrl, basePath, trailingSlash)
9098
const isAppRoute = appPathsRoutes && matchedRoute ? appPathsRoutes[matchedRoute.page] : false
91-
99+
92100
if (isAppRoute) {
93101
// app routes should use prebundled React
94102
// eslint-disable-next-line no-underscore-dangle

0 commit comments

Comments
 (0)