@@ -40,11 +40,20 @@ type MakeHandlerParams = {
40
40
NextServer : NextServerType
41
41
staticManifest : Array < [ string , string ] >
42
42
mode : 'ssr' | 'odb'
43
+ useHooks : boolean
43
44
}
44
45
45
46
// We return a function and then call `toString()` on it to serialise it as the launcher function
46
47
// eslint-disable-next-line max-lines-per-function
47
- const makeHandler = ( { conf, app, pageRoot, NextServer, staticManifest = [ ] , mode = 'ssr' } : MakeHandlerParams ) => {
48
+ const makeHandler = ( {
49
+ conf,
50
+ app,
51
+ pageRoot,
52
+ NextServer,
53
+ staticManifest = [ ] ,
54
+ mode = 'ssr' ,
55
+ useHooks,
56
+ } : MakeHandlerParams ) => {
48
57
// Change working directory into the site root, unless using Nx, which moves the
49
58
// dist directory and handles this itself
50
59
const dir = path . resolve ( __dirname , app )
@@ -62,14 +71,9 @@ const makeHandler = ({ conf, app, pageRoot, NextServer, staticManifest = [], mod
62
71
// Next 13.4 conditionally uses different React versions and we need to make sure we use the same one
63
72
// With the release of 13.5 experimental.appDir is no longer used.
64
73
// we will need to check if appDir is set and Next version before running requireHooks
65
- // const runRequireHooks = async (hook) =>
66
- // await nextVersionNum()
67
- // .then((version) => (appDir && version ? hook : null))
68
- // .catch(() => ({}))
69
-
70
- if ( appDir ) overrideRequireHooks ( conf . experimental )
74
+ if ( appDir && useHooks ) overrideRequireHooks ( conf . experimental )
71
75
const NetlifyNextServer : NetlifyNextServerType = getNetlifyNextServer ( NextServer )
72
- if ( appDir ) applyRequireHooks ( )
76
+ if ( appDir && useHooks ) applyRequireHooks ( )
73
77
74
78
const ONE_YEAR_IN_SECONDS = 31536000
75
79
@@ -214,6 +218,7 @@ export const getHandler = ({
214
218
publishDir = '../../../.next' ,
215
219
appDir = '../../..' ,
216
220
nextServerModuleRelativeLocation,
221
+ useHooks,
217
222
} ) : string =>
218
223
// 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)
219
224
javascript /* javascript */ `
@@ -241,7 +246,7 @@ export const getHandler = ({
241
246
const pageRoot = path . resolve ( path . join ( __dirname , "${ publishDir } " , "server" ) ) ;
242
247
exports . handler = ${
243
248
isODB
244
- ? `builder((${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, mode: 'odb'}));`
245
- : `(${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, mode: 'ssr'});`
249
+ ? `builder((${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, mode: 'odb', useHooks: ${ useHooks } }));`
250
+ : `(${ makeHandler . toString ( ) } )({ conf: config, app: "${ appDir } ", pageRoot, NextServer, staticManifest, mode: 'ssr', useHooks: ${ useHooks } });`
246
251
}
247
252
`
0 commit comments