Skip to content

Commit

Permalink
ensure config is only loaded once
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Sep 1, 2023
1 parent 97e85bb commit ddb7cfd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 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,16 @@ async function main() {
process.env = origEnv
}

const config = await loadConfig(
command === 'dev' ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
dir,
undefined,
undefined,
true
)

process.env.__NEXT_EXISTING_CONFIG = JSON.stringify(config)

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
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/server-ipc/index.ts
Expand Up @@ -109,7 +109,7 @@ export const createWorker = async (
.replace(/--max-old-space-size=[\d]{1,}/, '')
.trim(),
__NEXT_PRIVATE_RENDER_WORKER: type,
__NEXT_PRIVATE_RENDER_WORKER_CONFIG: JSON.stringify(nextConfig),
__NEXT_EXISTING_CONFIG: JSON.stringify(nextConfig),
__NEXT_PRIVATE_ROUTER_IPC_PORT: ipcPort + '',
__NEXT_PRIVATE_ROUTER_IPC_KEY: ipcValidationKey,
__NEXT_PRIVATE_STANDALONE_CONFIG:
Expand Down

0 comments on commit ddb7cfd

Please sign in to comment.