Skip to content

fix(watch): warn when the project root matches a default ignore glob - #23529

Closed
nikolas-sapa wants to merge 1 commit into
vitejs:mainfrom
nikolas-sapa:fix/23523-warn-root-under-ignored-glob
Closed

nikolas-sapa wants to merge 1 commit into
vitejs:mainfrom
nikolas-sapa:fix/23523-warn-root-under-ignored-glob

Conversation

@nikolas-sapa

Copy link
Copy Markdown

Fixes #23523.

Problem

resolveChokidarOptions prepends hardcoded default ignore globs — **/.git/**, **/node_modules/**, **/test-results/** (Playwright) — ahead of every user entry. Those globs are meant for tooling output inside a project, but they are anchored with **/, so they also match when the project root itself lives under an ancestor path segment of that name.

When that happens (e.g. a harness stages project copies inside a gitignored test-results/ directory — exactly what the glob exists to ignore), chokidar watches zero project directories: file edits fire no events, the module graph never invalidates, HMR never emits, and a full reload keeps serving pre-edit modules. There is no error surface — the failure looks like a downstream caching bug. And because anymatch ignores a path when any pattern matches, no server.watch.ignored entry can re-include the files.

The issue reporter confirmed watcher.getWatched() returns 0 directories over such a root, and that moving the project one directory up makes the watcher see everything again.

Change

Warn when the resolved project root matches one of the hardcoded default ignore globs, so a dead watcher is diagnosable instead of silent:

(!) The project root /home/user/test-results/my-project matches the default watch
    ignore pattern **/test-results/**.
    The dev server watcher will observe no files, so HMR will not work. Move the
    project out of that path.

Only the built-in defaults are checked — a user's own server.watch.ignored matching the root is their explicit choice, not a surprise, so it does not warn (there's a test for that). This is the lower-risk half of the reporter's suggestion (b); making the defaults removable (a) would be a larger API change and can be a follow-up.

Tests

Three cases in watcher.spec.ts: warns for a root under test-results/, does not warn for a normal root, and does not warn when only a user-supplied ignore matches the root. Reverting the source change turns the first test red while the two negative tests stay green. Full watcher.spec.ts passes (including the existing real-server watch tests).

resolveChokidarOptions prepends hardcoded default ignore globs
(**/.git/**, **/node_modules/**, **/test-results/**) ahead of every
user entry. When the project root itself lives under an ancestor path
segment matching one of these (e.g. staged under a test-results/
directory), chokidar watches zero project directories: no HMR, no module
invalidation, no error surface — the failure looks like a downstream
caching bug and is very hard to diagnose. anymatch's ANY-match semantics
mean no user server.watch.ignored entry can re-include the files either.

Warn when the root matches one of the default globs so the dead watcher
is diagnosable. Only the hardcoded defaults are checked — a user's own
ignore matching the root is their choice, not a surprise.

Fixes vitejs#23523
@github-actions github-actions Bot added the bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR label Sep 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically flagged as likely to be created by a bot, LLM, or agent, and will be automatically closed. These contributions harm the maintenance of the project. Please read our AI policy for more information.

If you believe this is a mistake, please reply to this comment and we will review it.

@github-actions github-actions Bot closed this Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR

Projects

None yet

1 participant