@@ -15,6 +15,8 @@ import {
15
15
unlocalizeRoute ,
16
16
getMatchedRoute ,
17
17
} from './handlerUtils'
18
+ import { join } from 'path'
19
+ import { ExperimentalConfigWithLegacy } from '../helpers/utils'
18
20
19
21
interface NetlifyConfig {
20
22
revalidateToken ?: string
@@ -30,11 +32,16 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
30
32
return this . nextConfig . experimental ?. serverActions ? 'experimental' : 'next'
31
33
}
32
34
35
+ protected getManifest ( manifest : string ) {
36
+ // eslint-disable-next-line import/no-dynamic-require
37
+ return require ( join ( this . distDir , manifest ) )
38
+ }
39
+
33
40
public constructor ( options : Options , netlifyConfig : NetlifyConfig ) {
34
41
super ( options )
35
42
this . netlifyConfig = netlifyConfig
36
43
// 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' )
38
45
this . netlifyPrerenderManifest = {
39
46
...manifest ,
40
47
routes : { ...manifest . routes } ,
@@ -53,7 +60,8 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
53
60
const { url, headers } = req
54
61
55
62
// 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 )
57
65
58
66
// intercept on-demand revalidation requests and handle with the Netlify API
59
67
if ( headers [ 'x-prerender-revalidate' ] && this . netlifyConfig . revalidateToken ) {
@@ -83,12 +91,12 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
83
91
84
92
// doing what they do in https://github.com/vercel/vercel/blob/1663db7ca34d3dd99b57994f801fb30b72fbd2f3/packages/next/src/server-build.ts#L576-L580
85
93
private async netlifyPrebundleReact ( path : string , { basePath, trailingSlash } : NextConfig , parsedUrl ) {
86
- const routesManifest = this . getRoutesManifest ?.( )
94
+ const routesManifest = this . getRoutesManifest ?.( ) || this . getManifest ( 'routes-manifest.json' )
87
95
const appPathsRoutes = this . getAppPathRoutes ?.( )
88
96
const routes = routesManifest && [ ...routesManifest . staticRoutes , ...routesManifest . dynamicRoutes ]
89
97
const matchedRoute = await getMatchedRoute ( path , routes , parsedUrl , basePath , trailingSlash )
90
98
const isAppRoute = appPathsRoutes && matchedRoute ? appPathsRoutes [ matchedRoute . page ] : false
91
-
99
+
92
100
if ( isAppRoute ) {
93
101
// app routes should use prebundled React
94
102
// eslint-disable-next-line no-underscore-dangle
0 commit comments