Skip to content

fix: ensure vite build watch mode works - #16632

Draft
teemingc wants to merge 2 commits into
version-3from
fix-vite-build-watch
Draft

fix: ensure vite build watch mode works#16632
teemingc wants to merge 2 commits into
version-3from
fix-vite-build-watch

Conversation

@teemingc

@teemingc teemingc commented Aug 3, 2026

Copy link
Copy Markdown
Member

fixes #16624

Two changes were required:

  • we need to correctly handle the result of builder.build which can return a watcher instead of the build chunks. Added a normaliser to handle that. Unfortunately, the bundle has to be taken from the generateBundle hook.
  • ignore generated files during a build when the watch mode is enabled. Copied the config from the dev server watch config option

Questions:

  • this remains unfixed in v2. Do we need to fix it there too?
  • no test added because it seems more trouble than it's worth. That said, it did regress. I think we can add a test where we monitor the logs of the ongoing build --watch process and end it if the assertions pass? with a timeout so it doesn't go on indefinitely?

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 3, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 849b73d:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/849b73d34eb9cb2fa0e154230be03e606b9ea6f8

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16632

@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 849b73d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot

Copy link
Copy Markdown

@teemingc teemingc added the vite label Aug 3, 2026
@teemingc teemingc changed the title fix: ignore generated files during vite build --watch fix: ensure vite build watch mode works Aug 3, 2026
@teemingc
teemingc force-pushed the fix-vite-build-watch branch from 49a9699 to 96fe7e0 Compare August 3, 2026 18:55
@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

What if the replacement happened in generateBundle instead, mutating chunk.code before write? That would make rebuilds correct by construction and remove normalise_build entirely. As it stands the chunk threading also still crashes; the second argument is evaluated before the watcher's first build, so it's permanently undefined (repro'd with the pkg build from 49a9699 on vite 8.0.12 and 8.2.0, same "chunks is not iterable" as #16624; the ERROR path has the same issue).

@teemingc
teemingc marked this pull request as draft August 3, 2026 19:14
@teemingc
teemingc force-pushed the fix-vite-build-watch branch from e99e640 to 849b73d Compare August 3, 2026 19:21
@teemingc

teemingc commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

The real issue is that all our logic in the buildApp hook doesn't re-run when watch mode is enabled 🤦🏼 going to enquire about this in the Vite discord before continuing

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.

vite build --watch regression

2 participants