Skip to content

fix(vite): a template edited while its component fails to compile is not served stale - #616

Open
Rush wants to merge 1 commit into
voidzero-dev:mainfrom
encharm:fix/vite-stale-template-cache
Open

Rush wants to merge 1 commit into
voidzero-dev:mainfrom
encharm:fix/vite-stale-template-cache

Conversation

@Rush

@Rush Rush commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

When a component's .ts fails to compile, its transform finds no templateUrl, and the transform's pruning drops the component's claim on its template. An edit to that template is then not recognised as a component resource in handleHotUpdate, so resourceCache keeps the old contents. Once the component compiles again, it is compiled with the old template until the dev server restarts:

  1. break a component's class (a syntax error);
  2. edit its template;
  3. fix the class: the page shows the old template, also after a reload.

handleHotUpdate now drops a changed file's cache entry first, whatever its role, and also with liveReload: false. A path's cached contents are stale once the file changed, whoever owns it.

The new test in test/hmr-hot-update.test.ts runs that sequence and fails without the change. All 377 plugin tests pass. We found it with a browser test of a real app.

…not served stale

A transform that fails before finding the component's templateUrl prunes the component's claim on its template, so
handleHotUpdate then treats an edit to that template as a stranger's and leaves its old contents in resourceCache;
once the component compiles again, it is compiled with the old template, until the dev server restarts.
handleHotUpdate now drops a changed file's cache entry whatever its role (also with liveReload off).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant