@@ -4,6 +4,7 @@ import type { Bridge as NodeBridge } from '@vercel/node-bridge/bridge'
4
4
import { outdent as javascript } from 'outdent'
5
5
6
6
import type { NextConfig } from '../helpers/config'
7
+ import { ExperimentalConfigWithLegacy } from '../helpers/utils'
7
8
8
9
import type { NextServerType } from './handlerUtils'
9
10
import type { NetlifyNextServerType } from './server'
@@ -37,6 +38,7 @@ type MakeHandlerParams = {
37
38
staticManifest : Array < [ string , string ] >
38
39
blobsManifest : Set < string >
39
40
mode : 'ssr' | 'odb'
41
+ useHooks : boolean
40
42
}
41
43
42
44
// We return a function and then call `toString()` on it to serialise it as the launcher function
@@ -49,6 +51,7 @@ const makeHandler = ({
49
51
staticManifest = [ ] ,
50
52
blobsManifest = new Set ( ) ,
51
53
mode = 'ssr' ,
54
+ useHooks,
52
55
} : MakeHandlerParams ) => {
53
56
// Change working directory into the site root, unless using Nx, which moves the
54
57
// dist directory and handles this itself
@@ -63,10 +66,13 @@ const makeHandler = ({
63
66
require . resolve ( './pages.js' )
64
67
} catch { }
65
68
69
+ const { appDir } : ExperimentalConfigWithLegacy = conf . experimental
66
70
// Next 13.4 conditionally uses different React versions and we need to make sure we use the same one
67
- overrideRequireHooks ( conf )
71
+ // With the release of 13.5 experimental.appDir is no longer used.
72
+ // we will need to check if appDir is set and Next version before running requireHooks
73
+ if ( appDir && useHooks ) overrideRequireHooks ( conf . experimental )
68
74
const NetlifyNextServer : NetlifyNextServerType = getNetlifyNextServer ( NextServer )
69
- applyRequireHooks ( )
75
+ if ( appDir && useHooks ) applyRequireHooks ( )
70
76
71
77
const ONE_YEAR_IN_SECONDS = 31536000
72
78
@@ -224,6 +230,7 @@ export const getHandler = ({
224
230
publishDir = '../../../.next' ,
225
231
appDir = '../../..' ,
226
232
nextServerModuleRelativeLocation,
233
+ useHooks,
227
234
} ) : string =>
228
235
// This is a string, but if you have the right editor plugin it should format as js (e.g. bierner.comment-tagged-templates in VS Code)
229
236
javascript /* javascript */ `
@@ -239,7 +246,7 @@ export const getHandler = ({
239
246
const { setBlobInit } = require ( './blobStorage' )
240
247
// We copy the file here rather than requiring from the node module
241
248
const { Bridge } = require ( "./bridge" ) ;
242
- const { augmentFsModule, getMaxAge, getMultiValueHeaders, getPrefetchResponse, normalizePath } = require ( './handlerUtils' )
249
+ const { augmentFsModule, getMaxAge, getMultiValueHeaders, getPrefetchResponse, normalizePath, nextVersionNum } = require ( './handlerUtils' )
243
250
const { overrideRequireHooks, applyRequireHooks } = require ( "./requireHooks" )
244
251
const { getNetlifyNextServer } = require ( "./server" )
245
252
const NextServer = require ( ${ JSON . stringify ( nextServerModuleRelativeLocation ) } ) . default
@@ -257,7 +264,7 @@ export const getHandler = ({
257
264
const pageRoot = path . resolve ( path . join ( __dirname , "${ publishDir } " , "server" ) ) ;
258
265
exports . handler = ${
259
266
isODB
260
- ? `builder((${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, blobsManifest, mode: 'odb' }));`
261
- : `(${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, blobsManifest, mode: 'ssr' });`
267
+ ? `builder((${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, blobsManifest, mode: 'odb', useHooks: ${ useHooks } }));`
268
+ : `(${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, blobsManifest, mode: 'ssr', useHooks: ${ useHooks } });`
262
269
}
263
270
`
0 commit comments