Skip to content

fix(dev): stop the dist watcher once .nuxt/dist is removed - #1729

Closed
mikeporterdev wants to merge 1 commit into
nuxt:mainfrom
mikeporterdev:fix/dist-watcher-storm
Closed

mikeporterdev wants to merge 1 commit into
nuxt:mainfrom
mikeporterdev:fix/dist-watcher-storm

Conversation

@mikeporterdev

Copy link
Copy Markdown

Problem

On Windows, once .nuxt/dist is deleted under a running nuxt dev, the dev server never restarts and its memory grows until it OOMs.

fs.watch on a directory that has been removed keeps firing rename events, about 90k per second on Windows / Node 22 in a standalone repro, and it doesn't stop. Every event passes the existsSync(distDir) guard and calls scheduleReload, which resets the 25ms debounce. The timer never fires, so the reload never happens. Each call also leaves a pending promise in the debounce's resolve list, and those pile up.

Measured on a real app: heap after GC grew ~2MB/s (1.0GB → 2.1GB in 9 minutes) with no restart. The CPU profile was dominated by this handler.

The usual trigger is nuxt prepare run beside a running dev server (e.g. in a pre-commit typecheck). 4.x already skips the clearBuildDir in that case. Anything else that deletes the build dir (rm -rf .nuxt, git clean, other tooling) still causes the storm.

Fix

Close the dist watcher on the first event after the directory is gone. One event is enough to schedule the reload, and #load creates a new watcher for the new instance.

Verified by patching the equivalent code into 3.31.2: five delete-and-restart cycles each restarted normally. Without the patch, the second cycle hung and leaked as above. I haven't added a test, because reproducing the storm needs a Windows fs.watch. Happy to add one if you have a preferred way to simulate it.

@agentscanapp

agentscanapp Bot commented Dec 4, 2026

Copy link
Copy Markdown

Insufficient data

Looks like you're new to GitHub - we're delighted you'd like to contribute! 💚

We welcome the thoughtful use of AI tools when contributing, but ask all contributors to follow two core principles:

  1. Never let an LLM speak for you - all comments, issues, and PR descriptions should be written in your own words, reflecting your own understanding.
  2. Never let an LLM think for you - only submit contributions you fully understand and can explain.

View full analysis →

This is an automated analysis by AgentScan

@pkg-pr-new

pkg-pr-new Bot commented Dec 4, 2026

Copy link
Copy Markdown
  • nuxt-cli-playground

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

commit: 5730e24

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

CLI benchmark

@nuxt/cli v4.1.1 (baseline) vs v4.1.1 (this PR)

Metric baseline v4.1.1 head v4.1.1 Delta
nuxt --version wall time (median) 64 ms 65 ms +1.6%
nuxt --help wall time (median) 132 ms 130 ms -1.5%
nuxt dev --help wall time (median) 101 ms 101 ms -0.1%
nuxt --version modules loaded 35 35 0.0%
nuxt --version built-ins loaded 29 29 0.0%
nuxt --help modules loaded 138 138 0.0%
nuxt --help built-ins loaded 93 93 0.0%
nuxt dev --help modules loaded 68 68 0.0%
nuxt dev --help built-ins loaded 90 90 0.0%
Installed node_modules 2.67 MB 2.68 MB +0.0%
Published tarball (packed) 265.3 kB 265.3 kB +0.0%
Full report

@nuxt/cli v4.1.1 (baseline) vs v4.1.1 (head)

Setting Value
Baseline ref:e48e326790618cf268763bc037e1674a958f867a (v4.1.1)
Head local packages/nuxt-cli at a7a097b (v4.1.1)
Node v24.23.0
OS Linux 7.0.0 (kernel 7.0.0-1020-azure)
CPU INTEL(R) XEON(R) PLATINUM 8573C x 4
Memory 15.6 GB
Load average at start 0.81, 0.33, 0.16
Run started 2026-12-04T10:00:01.244Z

Cold CLI startup

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

Command baseline v4.1.1 median head v4.1.1 median Delta baseline v4.1.1 min / p95 head v4.1.1 min / p95
nuxt --version 64 ms 65 ms +1.6% 61 ms / 67 ms 61 ms / 68 ms
nuxt --version (first output byte) 60 ms 61 ms +1.6% 58 ms / 63 ms 58 ms / 64 ms
nuxt --help 132 ms 130 ms -1.5% 129 ms / 135 ms 126 ms / 135 ms
nuxt --help (first output byte) 127 ms 125 ms -1.1% 125 ms / 130 ms 122 ms / 131 ms
nuxt dev --help 101 ms 101 ms -0.1% 96 ms / 103 ms 98 ms / 106 ms
nuxt dev --help (first output byte) 96 ms 97 ms +0.0% 92 ms / 99 ms 94 ms / 102 ms
nuxt <unknown-command> (no-op) 140 ms 141 ms +0.2% 135 ms / 145 ms 136 ms / 144 ms
nuxt <unknown-command> (no-op) (first output byte) 136 ms 136 ms +0.3% 130 ms / 139 ms 131 ms / 139 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.1.1 modules head v4.1.1 modules Delta baseline v4.1.1 source bytes head v4.1.1 source bytes Delta baseline v4.1.1 built-ins head v4.1.1 built-ins Delta
nuxt --version 35 35 0.0% 312.4 kB 312.4 kB 0.0% 29 29 0.0%
nuxt --help 138 138 0.0% 904.3 kB 904.3 kB 0.0% 93 93 0.0%
nuxt dev --help 68 68 0.0% 478.9 kB 478.9 kB 0.0% 90 90 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.1.1 head v4.1.1 Delta
Direct dependencies of @nuxt/cli 23 23 0.0%
Packages in the installed tree (unique name@version) 38 38 0.0%
Unique package names 38 38 0.0%
Package directories on disk (cross-check) 32 32 0.0%
Installed node_modules on disk 2.67 MB 2.68 MB +0.0%
Installed files 448 448 0.0%
Install wall time (warm npm cache, median of 3) 1.34 s 1.33 s -0.7%
Published tarball (packed) 265.3 kB 265.3 kB +0.0%
Published tarball (unpacked) 858.5 kB 858.6 kB +0.0%
Files in tarball 108 108 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 Dec 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 2 untouched benchmarks


Comparing mikeporterdev:fix/dist-watcher-storm (5730e24) with main (e48e326)

Open in CodSpeed

@codecov-commenter

codecov-commenter commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
packages/nuxt-cli/src/dev/utils.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1729   +/-   ##
=======================================
  Coverage        ?   85.54%           
=======================================
  Files           ?      191           
  Lines           ?    14153           
  Branches        ?     4812           
=======================================
  Hits            ?    12107           
  Misses          ?     1767           
  Partials        ?      279           

☔ 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.

@mikeporterdev

Copy link
Copy Markdown
Author

Sorry, this PR was opened by mistake by an overeager Claude agent that was meant to be debugging a local performance problem in my own project. Closing it. Apologies for the noise.

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