Skip to content

fix(dev): let a restarted fork reload changed .env values - #1592

Open
productdevbook wants to merge 1 commit into
nuxt:mainfrom
productdevbook:fix/dev-fork-dotenv
Open

productdevbook wants to merge 1 commit into
nuxt:mainfrom
productdevbook:fix/dev-fork-dotenv

Conversation

@productdevbook

Copy link
Copy Markdown
Member

Editing .env during nuxt dev prints .env changed. Restarting Nuxt in a new process..., but the new process keeps serving the old values.

Cause

ForkPool.createFork passes { ...process.env } to the fork. By then the parent's process.env already contains whatever the previous .env set.

setupDotenv in c12 only overwrites a variable when it is undefined or when c12 set it itself, and it tracks which ones it set in globalThis.__c12_dotenv_vars__. That record is per process, so inside the fork the stale values look like real shell variables. The fresh .env never wins: a changed value is ignored, and a removed one stays.

Fix

Before forking, drop the variables that c12 recorded as set by .env files in this process (withoutDotenvVars in dev/pool.ts). The fork then loads .env from scratch. Variables that came from the shell are not in that record, so they are passed through unchanged. If the record is missing (another c12), the env is passed as before.

Reproduction

The fixture's nuxt.config.ts has runtimeConfig: { public: { benchMarker: '' } }, and the dev server runs with CI=1:

echo NUXT_PUBLIC_BENCH_MARKER=before > .env
nuxt dev --port 33992 &
curl -s localhost:33992/ | grep -o 'public:{[^}]*}'   # public:{benchMarker:"before"}
echo NUXT_PUBLIC_BENCH_MARKER=after > .env           # ".env changed. Restarting Nuxt in a new process..."
curl -s localhost:33992/ | grep -o 'public:{[^}]*}'
after the 1st edit (after) after the 2nd edit (third)
main benchMarker:"before" ❌ —
this PR benchMarker:"after" ✅ benchMarker:"third" ✅

Checks

  • eslint and tsc --noEmit pass
  • vitest run packages/nuxt-cli/test/unit plus e2e dev-restart and dev: 134 files, 1881 tests passed

🤖 Generated with Claude Code

Editing `.env` restarts Nuxt in a new process, but the fork inherited the
parent's `process.env`, including the values the old `.env` had put
there. c12 only overwrites variables it set itself and keeps that record
per process, so in the fork the stale values looked like shell variables
and won: a changed value was never picked up, and a removed one stayed.

Drop the variables c12 set from `.env` before forking, so the fork reads
the files afresh. Variables from the shell are untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 946df2df-f607-4907-a628-402862da856f
📥 Commits

Reviewing files that changed from the base of the PR and between f140924 and d8ab4cf.

📒 Files selected for processing (1)
  • packages/nuxt-cli/src/dev/pool.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 3, 2026

Copy link
Copy Markdown
  • nuxt-cli-playground

    npm i https://pkg.pr.new/create-nuxt@1592
    
    npm i https://pkg.pr.new/nuxi@1592
    
    npm i https://pkg.pr.new/@nuxt/cli@1592
    

commit: d8ab4cf

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

CLI benchmark

@nuxt/cli v4.0.0-alpha.1 (baseline) vs v4.0.0-alpha.1 (this PR)

Metric baseline v4.0.0-alpha.1 head v4.0.0-alpha.1 Delta
nuxt --version wall time (median) 51 ms 52 ms +0.6%
nuxt --help wall time (median) 105 ms 103 ms -2.0%
nuxt dev --help wall time (median) 81 ms 81 ms +1.0%
nuxt --version modules loaded 35 35 0.0%
nuxt --version built-ins loaded 27 27 0.0%
nuxt --help modules loaded 134 134 0.0%
nuxt --help built-ins loaded 87 87 0.0%
nuxt dev --help modules loaded 63 63 0.0%
nuxt dev --help built-ins loaded 87 87 0.0%
Installed node_modules 2.43 MB 2.43 MB +0.0%
Published tarball (packed) 239.6 kB 239.8 kB +0.1%
Full report

@nuxt/cli v4.0.0-alpha.1 (baseline) vs v4.0.0-alpha.1 (head)

Setting Value
Baseline ref:f140924fb88992febb831316ac01bce275609336 (v4.0.0-alpha.1)
Head local packages/nuxt-cli at dcaf00c (v4.0.0-alpha.1)
Node v24.21.0
OS Linux 6.17.0 (kernel 6.17.0-1022-azure)
CPU INTEL(R) XEON(R) PLATINUM 8573C x 4
Memory 15.6 GB
Load average at start 1.34, 0.37, 0.13
Run started 2026-10-03T17:10:45.375Z

Cold CLI startup

Median of 15 interleaved runs per command, one warmup discarded.

Command baseline v4.0.0-alpha.1 median head v4.0.0-alpha.1 median Delta baseline v4.0.0-alpha.1 min / p95 head v4.0.0-alpha.1 min / p95
nuxt --version 51 ms 52 ms +0.6% 48 ms / 55 ms 49 ms / 58 ms
nuxt --version (first output byte) 49 ms 49 ms +1.0% 46 ms / 52 ms 46 ms / 55 ms
nuxt --help 105 ms 103 ms -2.0% 101 ms / 108 ms 98 ms / 108 ms
nuxt --help (first output byte) 103 ms 100 ms -2.4% 99 ms / 105 ms 96 ms / 105 ms
nuxt dev --help 81 ms 81 ms +1.0% 78 ms / 82 ms 76 ms / 84 ms
nuxt dev --help (first output byte) 78 ms 78 ms +0.7% 75 ms / 80 ms 74 ms / 81 ms
nuxt &lt;unknown-command> (no-op) 110 ms 111 ms +0.4% 106 ms / 114 ms 105 ms / 115 ms
nuxt &lt;unknown-command> (no-op) (first output byte) 107 ms 107 ms +0.1% 103 ms / 111 ms 102 ms / 111 ms

Module load cost

Counted with a module.registerHooks load hook, compile cache disabled. Counts every JS module actually evaluated on that code path (native addons excluded). Built-ins loaded after bootstrap are counted separately, including the internal modules they load.

Command baseline v4.0.0-alpha.1 modules head v4.0.0-alpha.1 modules Delta baseline v4.0.0-alpha.1 source bytes head v4.0.0-alpha.1 source bytes Delta baseline v4.0.0-alpha.1 built-ins head v4.0.0-alpha.1 built-ins Delta
nuxt --version 35 35 0.0% 297.8 kB 297.8 kB 0.0% 27 27 0.0%
nuxt --help 134 134 0.0% 839.9 kB 840.4 kB +0.1% 87 87 0.0%
nuxt dev --help 63 63 0.0% 453.0 kB 453.4 kB +0.1% 87 87 0.0%

Install footprint and published tarball

Each version installed on its own into an empty project with nothing but @nuxt/cli as a dependency, so the tree is exactly the CLI and its transitive dependencies. npm cache is warm and the registry is only consulted for metadata, so install wall time is indicative, not a network benchmark.

Metric baseline v4.0.0-alpha.1 head v4.0.0-alpha.1 Delta
Direct dependencies of @nuxt/cli 23 23 0.0%
Packages in the installed tree (unique name@version) 39 39 0.0%
Unique package names 39 39 0.0%
Package directories on disk (cross-check) 32 32 0.0%
Installed node_modules on disk 2.43 MB 2.43 MB +0.0%
Installed files 434 434 0.0%
Install wall time (warm npm cache, median of 3) 1.03 s 1.03 s -0.5%
Published tarball (packed) 239.6 kB 239.8 kB +0.1%
Published tarball (unpacked) 775.2 kB 775.7 kB +0.1%
Files in tarball 99 99 0.0%

Interleaved runs on a shared runner: trust the deltas, not the absolute timings. The dev, restart and build suites run locally via pnpm bench:cli.

@codspeed

codspeed Bot commented Oct 3, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing productdevbook:fix/dev-fork-dotenv (d8ab4cf) with main (f140924)

Open in CodSpeed

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@f140924). Learn more about missing BASE report.

Files with missing lines Patch % Lines
packages/nuxt-cli/src/dev/pool.ts 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1592   +/-   ##
=======================================
  Coverage        ?   83.39%           
=======================================
  Files           ?      177           
  Lines           ?    11311           
  Branches        ?     3244           
=======================================
  Hits            ?     9433           
  Misses          ?     1582           
  Partials        ?      296           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants