Skip to content

fix(vite): stop swallowing HMR updates for non-component resources#197

Merged
Brooooooklyn merged 5 commits intomainfrom
fix/vite-hmr-swallowed-updates
Mar 31, 2026
Merged

fix(vite): stop swallowing HMR updates for non-component resources#197
Brooooooklyn merged 5 commits intomainfrom
fix/vite-hmr-swallowed-updates

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Member

@Brooooooklyn Brooooooklyn commented Mar 30, 2026

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 handleHotUpdate from returning [] for every *.css/*.html change; it now swallows updates only when the changed file is a tracked component resource in resourceToComponent, letting global styles/templates flow through Vite so PostCSS/Tailwind can react.

During component transforms, the plugin now prunes stale resourceToComponent reverse mappings when a component’s templateUrl/styleUrls change 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.

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>
Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Brooooooklyn and others added 2 commits March 30, 2026 23:12
- 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>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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>
@Brooooooklyn Brooooooklyn merged commit f9c0863 into main Mar 31, 2026
9 checks passed
@Brooooooklyn Brooooooklyn deleted the fix/vite-hmr-swallowed-updates branch March 31, 2026 01:02
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.

Plugin swallows HMR updates that it doesn't handle

1 participant