Skip to content

Commit a8d4a32

Browse files
committed
fix: add back useHooks
1 parent f4e7509 commit a8d4a32

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

packages/runtime/src/helpers/functions.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { getResolverForPages, getResolverForSourceFiles } from '../templates/get
2828
import { ApiConfig, extractConfigFromFile, isEdgeConfig } from './analysis'
2929
import { getRequiredServerFiles } from './config'
3030
import { getDependenciesOfFile, getServerFile, getSourceFileForPage } from './files'
31-
import { writeFunctionConfiguration } from './functionsMetaData'
31+
import { writeFunctionConfiguration, nextVersionNum } from './functionsMetaData'
3232
import { pack } from './pack'
3333
import { ApiRouteType } from './types'
3434
import { getFunctionNameForPage } from './utils'
@@ -132,11 +132,13 @@ export const generateFunctions = async (
132132
}
133133

134134
const writeHandler = async (functionName: string, functionTitle: string, isODB: boolean) => {
135+
const useHooks = await nextVersionNum()
135136
const handlerSource = getHandler({
136137
isODB,
137138
publishDir,
138139
appDir: relative(functionDir, appDir),
139140
nextServerModuleRelativeLocation,
141+
useHooks,
140142
})
141143
await ensureDir(join(functionsDir, functionName))
142144

packages/runtime/src/templates/getHandler.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,20 @@ type MakeHandlerParams = {
4040
NextServer: NextServerType
4141
staticManifest: Array<[string, string]>
4242
mode: 'ssr' | 'odb'
43+
useHooks: boolean
4344
}
4445

4546
// We return a function and then call `toString()` on it to serialise it as the launcher function
4647
// 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) => {
4857
// Change working directory into the site root, unless using Nx, which moves the
4958
// dist directory and handles this itself
5059
const dir = path.resolve(__dirname, app)
@@ -62,14 +71,9 @@ const makeHandler = ({ conf, app, pageRoot, NextServer, staticManifest = [], mod
6271
// Next 13.4 conditionally uses different React versions and we need to make sure we use the same one
6372
// With the release of 13.5 experimental.appDir is no longer used.
6473
// 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)
7175
const NetlifyNextServer: NetlifyNextServerType = getNetlifyNextServer(NextServer)
72-
if (appDir) applyRequireHooks()
76+
if (appDir && useHooks) applyRequireHooks()
7377

7478
const ONE_YEAR_IN_SECONDS = 31536000
7579

@@ -214,6 +218,7 @@ export const getHandler = ({
214218
publishDir = '../../../.next',
215219
appDir = '../../..',
216220
nextServerModuleRelativeLocation,
221+
useHooks,
217222
}): string =>
218223
// 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)
219224
javascript/* javascript */ `
@@ -241,7 +246,7 @@ export const getHandler = ({
241246
const pageRoot = path.resolve(path.join(__dirname, "${publishDir}", "server"));
242247
exports.handler = ${
243248
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}});`
246251
}
247252
`

0 commit comments

Comments
 (0)