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 bde9e09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions packages/next/src/bin/next.ts
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ export default async function loadConfig(
// have Webpack plugins added.
// Because of this change, unserializable fields like `.webpack` won't be
// existing here but the render worker shouldn't use these as well.
if (process.env.__NEXT_PRIVATE_RENDER_WORKER_CONFIG) {
return JSON.parse(process.env.__NEXT_PRIVATE_RENDER_WORKER_CONFIG)
if (process.env.__NEXT_EXISTING_CONFIG) {
return JSON.parse(process.env.__NEXT_EXISTING_CONFIG)
}

const curLog = silent
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/server-ipc/index.ts
Original file line number Diff line number Diff line change
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 bde9e09

Please sign in to comment.