fix(vite): stop swallowing HMR updates for non-component resources#197
fix(vite): stop swallowing HMR updates for non-component resources#197Brooooooklyn merged 5 commits intomainfrom
Conversation
The plugin's handleHotUpdate was returning [] for all CSS/HTML files, preventing Vite from processing global stylesheets and notifying PostCSS/Tailwind of content changes. Now only component resource files (tracked in resourceToComponent) are swallowed; non-component files flow through Vite's normal HMR. Also emits a synthetic watcher event when component templates change so Tailwind can rescan for new classes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b07c3b340
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
- Remove server.watcher.emit('change', file) for component resources:
Vite treats HTML changes with no module graph entries as full reloads,
which would regress template HMR behavior.
- Fix test to call config() with command='serve' so watchMode=true and
resourceToComponent is actually populated during transform. Tests now
use real temp files and assert exact return values.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use .call() with plugin context for handleHotUpdate to satisfy TS2684, and remove invalid 'type' property from mock ModuleNode to fix TS2345. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7e277bbf0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Prune old resource→component mappings before re-registering during transform, so renamed/removed templateUrl/styleUrls no longer cause handleHotUpdate to swallow updates for files that are no longer component resources. - Replace real fs.watch with no-op in tests to avoid EPERM errors on Windows when temp files are cleaned up. resourceToComponent is populated before watchFn runs, so test coverage is preserved. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3a9004408
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
When a component drops a resource from templateUrl/styleUrls, the file was already unwatched from Vite's chokidar watcher by the custom fs.watch setup. Pruning the resourceToComponent entry made the file invisible to both systems. Now re-add pruned files to Vite's watcher so they can flow through normal HMR if used elsewhere (e.g., as a global stylesheet). Also skip pruning resources that are still in the new dependency set. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>


The plugin's handleHotUpdate was returning [] for all CSS/HTML files,
preventing Vite from processing global stylesheets and notifying
PostCSS/Tailwind of content changes. Now only component resource files
(tracked in resourceToComponent) are swallowed; non-component files
flow through Vite's normal HMR. Also emits a synthetic watcher event
when component templates change so Tailwind can rescan for new classes.
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
Note
Medium Risk
Touches Vite dev-server HMR and file-watching behavior; regressions could break live reload or asset processing, but changes are scoped and covered by new tests.
Overview
Stops
handleHotUpdatefrom returning[]for every*.css/*.htmlchange; it now swallows updates only when the changed file is a tracked component resource inresourceToComponent, letting global styles/templates flow through Vite so PostCSS/Tailwind can react.During component transforms, the plugin now prunes stale
resourceToComponentreverse mappings when a component’stemplateUrl/styleUrlschange and re-adds removed resources back to Vite’s watcher. Adds a Vitest suite (hmr-hot-update.test.ts) that exercises both pass-through vs swallow behavior for component vs non-component files.Written by Cursor Bugbot for commit d3c7bde. This will update automatically on new commits. Configure here.