Skip to content

Commit b2db4e5

Browse files
committed
fix: fix memoization
1 parent 282dcf8 commit b2db4e5

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

helpers/getNextConfig.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
const { resolve } = require('path')
22

3-
let nextConfig
4-
53
// Load next.config.js
64
const getNextConfig = async function (failBuild = defaultFailBuild) {
5+
try {
6+
return await getNextConfigValue()
7+
} catch (error) {
8+
return failBuild('Error loading your next.config.js.', { error })
9+
}
10+
}
11+
12+
let nextConfigPromise
13+
14+
const getNextConfigValue = function () {
715
// Memoizes `nextConfig`
8-
if (nextConfig !== undefined) {
9-
return nextConfig
16+
if (nextConfigPromise !== undefined) {
17+
return nextConfigPromise
1018
}
1119

1220
// We cannot load `next` at the top-level because we validate whether the
1321
// site is using `next` inside `onPreBuild`.
1422
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
1523
const loadConfig = require('next/dist/next-server/server/config').default
1624

17-
try {
18-
nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, resolve('.'))
19-
} catch (error) {
20-
return failBuild('Error loading your next.config.js.', { error })
21-
}
22-
23-
return nextConfig
25+
nextConfigPromise = loadConfig(PHASE_PRODUCTION_BUILD, resolve('.'))
26+
return nextConfigPromise
2427
}
2528

2629
const defaultFailBuild = function (message, { error }) {

0 commit comments

Comments
 (0)