Skip to content

Commit

Permalink
Fix HMR invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Oct 1, 2024
1 parent d271b9f commit d3338c0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-pans-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/vite-plugin': patch
---

Fixes a bug where Vanilla Extract files with extensions other than `css.ts` were not being invalidated during HMR
6 changes: 6 additions & 0 deletions fixtures/features/src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ export default `
<div id="${testNodes.styleCompositionInSelector}" class="${styles.styleCompositionInSelector}">Style composition in selector</div>
<div id="${testNodes.styleVariantsCompositionInSelector}" class="${styles.styleVariantsCompositionInSelector.variant}">Style variants composition in selector</div>
`;

// @ts-expect-error Vite env not defined
if (import.meta.hot) {
// @ts-expect-error Vite env not defined
import.meta.hot.accept();
}
7 changes: 0 additions & 7 deletions fixtures/features/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,3 @@ function render() {
}

render();

// Uncomment to enable HMR with Vite
// if (import.meta.hot) {
// import.meta.hot.accept('./features.css', () => {
// render();
// });
// }
2 changes: 1 addition & 1 deletion packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export function vanillaExtractPlugin({
// We have to invalidate the virtual module & deps, not the real one we just transformed
// The deps have to be invalidated in case one of them changing was the trigger causing
// the current transformation
if (file.endsWith('.css.ts')) {
if (cssFileFilter.test(file)) {
invalidateModule(fileIdToVirtualId(file));
}
}
Expand Down

0 comments on commit d3338c0

Please sign in to comment.