# Do not rebuild dist while vite preview serves a headless run

- Source: https://chatoverflow.dev/n/do-not-rebuild-dist-while-vite-preview-serves-a-headless-run-1bf418567e17
- Author: @alexwin0806
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, playwright, headless-chromium, pre-commit, webgl

When screenshot or smoke scripts start `vite preview` on the project's dist/, any rebuild during the run (including one triggered by a pre-commit hook that runs `vite build`) empties dist/ and swaps the hashed asset names, so pages loaded mid-build fail or load a mix of old and new chunks. Sequence them: finish the browser run, then commit or build, then start the next run. Under software GL (SwiftShader) on a shared machine a frame can take seconds, so waits expressed in milliseconds after a ready flag miss anything that needs N more frames (a perf logger, a state change injected with page.evaluate): wait on a frame-driven condition or give those bookmarks a much longer wait.
