Skip to content

Stop the frontend watch from rebuilding in a loop - #4407

Merged
akira28 merged 2 commits into
mainfrom
feature/fix-isolated-watch
Oct 13, 2026
Merged

akira28 merged 2 commits into
mainfrom
feature/fix-isolated-watch

Conversation

@akira28

@akira28 akira28 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

./dev.sh isolated-watch and docs-builder serve no longer rebuild the frontend endlessly. The Vite watcher now ignores its own _static output, 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.js scans ./**/*.{js,…}, and that glob also matches the built _static/*.js files. The Tailwind Vite plugin watches every file it scans. Under vite build --watch, each build writes to _static, and those writes start the next build. The serve process runs npm run watch, so the frontend never settles.

What

Watch mode ignores build output

Vite's watcher excludes _static/** and node_modules/**. Writes to the build output no longer trigger a rebuild, and edits under Assets/ still do.

One-shot builds stay one-shot

Vite treats any non-null build.watch as a request to watch. The config sets the exclusion only when Vite runs with --watch. Without that guard, the npm run build step in MSBuild never exits and the .NET build hangs.

A test guards both modes

vite.config.test.ts loads 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

cd src/Elastic.Documentation.Site && npx jest vite.config.test.ts

./dev.sh isolated-stop && ./dev.sh isolated-watch
# expect a single "[npm run watch]: build started" line, then the site on http://localhost:3000

Editing a file under src/Elastic.Documentation.Site/Assets/ should trigger exactly one more build.

🤖 Generated with Claude Code

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>
@akira28
akira28 requested a review from a team as a code owner October 12, 2026 13:59
@akira28 akira28 added the bug label Oct 12, 2026
@akira28
akira28 requested a review from reakaleek October 12, 2026 13:59
Comment on lines +35 to +37
// 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/**'] }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown
Contributor

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>
@akira28
akira28 enabled auto-merge (squash) October 13, 2026 06:05
@akira28
akira28 disabled auto-merge October 13, 2026 06:13
@akira28
akira28 merged commit 6a6c0c0 into main Oct 13, 2026
32 checks passed
@akira28
akira28 deleted the feature/fix-isolated-watch branch October 13, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants