fix(vtz): invalidate dependents' cache when a file fails to compile [#2766]#2940
Merged
Merged
Conversation
…2766] The dev-server file-watcher loop `continue`d inside the compile-error branch, bypassing `process_file_change`. If a user introduced a syntax error in `utils.ts`, transitive dependents kept their stale compiled-cache entries — so even after the error was fixed, dependents could still serve stale code until individually re-touched. Same shape as #2764 (delete events), different trigger. The compile-error branch now falls through to `process_file_change` so the changed file and its transitive dependents are invalidated. The module-graph update is still skipped on error (don't commit edges scanned from broken source); last-successful edges persist until the next successful compile, which can only cause over-invalidation (safe). Also suppress the HMR broadcast while `compile_result.errors` is non-empty: the overlay is the user-visible state, and firing Update/FullReload on every broken keystroke would make the client re-fetch a module that will error out, or (for entry-file edits) reload the page mid-error and lose in-memory state. The cache is invalidated above; the next successful compile drives the refetch. As part of the fix, the per-change handler body was moved out of the file-watcher closure in `server::http` into `server::file_change_handler::handle_file_change` so it's reachable from tests without spinning up `start_server_with_lifecycle`. Closes #2766. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The dev-server file-watcher loop
continued inside the compile-error branch, bypassingprocess_file_change. If a user introduced a syntax error inutils.ts, transitive dependents kept their stale compiled-cache entries — so even after the error was fixed, dependents could still serve stale compiled code until individually re-touched. Same shape as #2764 (delete events), different trigger.process_file_changeso the changed file and its transitive dependents are invalidated.compile_result.errorsis non-empty: the overlay is the user-visible state, and firingUpdate/FullReloadon every broken keystroke would make the client re-fetch a broken module, or (for entry-file edits) reload mid-error and lose in-memory state. The next successful compile drives the refetch.server::http's file-watcher closure into a newserver::file_change_handler::handle_file_changeso it's reachable from tests without spinning upstart_server_with_lifecycle.Public API Changes
None.
@vertz/runtimeis documented as internal; the newly-exposedpub fn handle_file_changeis used by the in-tree regression test only and is not surfaced anywhere a user would reach.Test Plan
cargo test --allgreen (incl. new regression test that modelspage → app → helloand verifies all three cache entries are invalidated whenhello.tsxis modified with a syntax error)return;is re-introduced in the compile-error branchcargo clippy --all-targets --release -- -D warningsclean (pre-push hook)cargo fmt --all -- --checkcleanReview
Ran one adversarial review; all three should-fix findings (HMR broadcast on compile error, stale graph-edge comment, single-level dependent test coverage) and the brittle broken-source string nit were addressed. Review notes and resolution:
reviews/fix-2766/phase-01-hmr-compile-error.md(not committed to main).Closes #2766.
🤖 Generated with Claude Code