Skip to content

Commit 30c0305

Browse files
authored
vite: Fix HMR invalidation (#1482)
1 parent 7b256d2 commit 30c0305

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

.changeset/twelve-pans-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/vite-plugin': patch
3+
---
4+
5+
Fixes a bug where Vanilla Extract files with extensions other than `css.ts` were not being invalidated during HMR

fixtures/features/src/html.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ export default `
1010
<div id="${testNodes.styleCompositionInSelector}" class="${styles.styleCompositionInSelector}">Style composition in selector</div>
1111
<div id="${testNodes.styleVariantsCompositionInSelector}" class="${styles.styleVariantsCompositionInSelector.variant}">Style variants composition in selector</div>
1212
`;
13+
14+
// @ts-expect-error Vite env not defined
15+
if (import.meta.hot) {
16+
// @ts-expect-error Vite env not defined
17+
import.meta.hot.accept();
18+
}

fixtures/features/src/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,3 @@ function render() {
55
}
66

77
render();
8-
9-
// Uncomment to enable HMR with Vite
10-
// if (import.meta.hot) {
11-
// import.meta.hot.accept('./features.css', () => {
12-
// render();
13-
// });
14-
// }

packages/vite-plugin/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export function vanillaExtractPlugin({
214214
// We have to invalidate the virtual module & deps, not the real one we just transformed
215215
// The deps have to be invalidated in case one of them changing was the trigger causing
216216
// the current transformation
217-
if (file.endsWith('.css.ts')) {
217+
if (cssFileFilter.test(file)) {
218218
invalidateModule(fileIdToVirtualId(file));
219219
}
220220
}

0 commit comments

Comments
 (0)