Skip to content

Commit

Permalink
prevent next.config defaults from being constantly assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Sep 1, 2023
1 parent 97e85bb commit ca33652
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/next/src/bin/next.ts
Expand Up @@ -135,15 +135,6 @@ async function main() {
)
const origEnv = Object.assign({}, process.env)

// TODO: set config to env variable to be re-used so we don't reload
// un-necessarily
const config = await loadConfig(
command === 'dev' ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
dir,
undefined,
undefined,
true
)
let dirsResult: ReturnType<typeof findPagesDir> | undefined = undefined

try {
Expand All @@ -156,6 +147,18 @@ async function main() {
process.env = origEnv
}

// TODO: set config to env variable to be re-used so we don't reload
// un-necessarily
const config = await loadConfig(
command === 'dev' ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
dir,
undefined,
undefined,
true
)

process.env.__NEXT_PRIVATE_CONFIG_INITIALIZED = '1'

if (dirsResult?.appDir) {
// we need to reset env if we are going to create
// the worker process with the esm loader so that the
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/server/config.ts
Expand Up @@ -186,6 +186,9 @@ function assignDefaults(

const result = { ...defaultConfig, ...config }

// avoid mutating config if it was already initialized
if (process.env.__NEXT_PRIVATE_CONFIG_INITIALIZED) return result

if (result.output === 'export') {
if (result.i18n) {
throw new Error(
Expand Down

0 comments on commit ca33652

Please sign in to comment.