Repository navigation
Stop the frontend watch from rebuilding in a loop - #4407
Conversation
Tailwind's content globs match the built `_static/*.js` files, and the Tailwind Vite plugin watches every file it scans. Each watch build wrote `_static`, which started the next build, so `./dev.sh isolated-watch` never settled. The watcher now ignores `_static` and `node_modules`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| // Only set under --watch: any non-null value turns a plain `vite build` into a watcher. | ||
| watch: process.argv.includes('--watch') | ||
| ? { exclude: ['**/_static/**', '**/node_modules/**'] } |
There was a problem hiding this comment.
Severity: P3 (Low)
Add automated regression coverage for the build/watch lifecycle. This fix has no accompanying test that verifies a normal build exits, watch mode settles after writing _static, and a source edit triggers another build. Those are the behaviors this change must preserve, and without coverage the rebuild loop or a hanging frontend build can return unnoticed.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
There was a problem hiding this comment.
Added vite.config.test.ts in c90ecf1. It covers both regressions at the config level: a one-shot vite build keeps build.watch unset (otherwise the MSBuild step hangs), and --watch excludes _static/** (otherwise every build triggers the next). I checked that it fails when watch is forced on. A real vite build --watch lifecycle test, which edits a file and counts rebuilds, would need several seconds of real Vite and Tailwind builds and would be flaky, so I left it out of the Jest suite.
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4407/ |
A one-shot `vite build` must exit, or the MSBuild frontend step hangs. Under `--watch`, the watcher must ignore `_static`, or each build triggers the next one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
./dev.sh isolated-watchanddocs-builder serveno longer rebuild the frontend endlessly. The Vite watcher now ignores its own_staticoutput, so it builds once and then waits for real source changes.Affects: Site UI, Isolated builds
Prompt summary: The move from Parcel to Vite in #4383 broke
./dev.sh isolated-watch. The goal is to make the isolated watch flow usable again.Why
tailwind.config.jsscans./**/*.{js,…}, and that glob also matches the built_static/*.jsfiles. The Tailwind Vite plugin watches every file it scans. Undervite build --watch, each build writes to_static, and those writes start the next build. The serve process runsnpm run watch, so the frontend never settles.What
Watch mode ignores build output
Vite's watcher excludes
_static/**andnode_modules/**. Writes to the build output no longer trigger a rebuild, and edits underAssets/still do.One-shot builds stay one-shot
Vite treats any non-null
build.watchas a request to watch. The config sets the exclusion only when Vite runs with--watch. Without that guard, thenpm run buildstep in MSBuild never exits and the .NET build hangs.A test guards both modes
vite.config.test.tsloads the config with and without--watch. It fails if a one-shot build turns into a watcher, or if watch mode stops ignoring_static.Verify
Editing a file under
src/Elastic.Documentation.Site/Assets/should trigger exactly one more build.🤖 Generated with Claude Code