Skip to content

Commit 765b856

Browse files
Fix changes to nested imports not updating styles during development (#1438)
Co-authored-by: Adam Skoufis <[email protected]> Co-authored-by: Adam Skoufis <[email protected]>
1 parent 85afd9e commit 765b856

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

.changeset/chilled-paws-shop.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 changes to `.css.ts` dependencies of top-level `.css.ts` files would not generate new CSS

packages/vite-plugin/src/index.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type {
55
ResolvedConfig,
66
ConfigEnv,
77
ViteDevServer,
8-
Rollup,
98
PluginOption,
9+
TransformResult,
1010
UserConfig,
1111
} from 'vite';
1212
import {
@@ -96,23 +96,6 @@ export function vanillaExtractPlugin({
9696
}
9797
}
9898

99-
function addWatchFiles(
100-
this: Rollup.PluginContext,
101-
fromId: string,
102-
files: Set<string>,
103-
) {
104-
// We don't need to watch files in build mode
105-
if (config.command === 'build' && !config.build.watch) {
106-
return;
107-
}
108-
109-
for (const file of files) {
110-
if (!file.includes('node_modules') && normalizePath(file) !== fromId) {
111-
this.addWatchFile(file);
112-
}
113-
}
114-
}
115-
11699
return {
117100
name: 'vanilla-extract',
118101
configureServer(_server) {
@@ -210,16 +193,33 @@ export function vanillaExtractPlugin({
210193
absoluteId,
211194
{ outputCss: true },
212195
);
213-
214-
addWatchFiles.call(this, absoluteId, watchFiles);
215-
216-
// We have to invalidate the virtual module, not the real one we just transformed
217-
invalidateModule(fileIdToVirtualId(absoluteId));
218-
219-
return {
196+
const result: TransformResult = {
220197
code: source,
221198
map: { mappings: '' },
222199
};
200+
201+
// We don't need to watch files in build mode
202+
if (config.command === 'build' && !config.build.watch) {
203+
return result;
204+
}
205+
206+
for (const file of watchFiles) {
207+
if (
208+
!file.includes('node_modules') &&
209+
normalizePath(file) !== absoluteId
210+
) {
211+
this.addWatchFile(file);
212+
}
213+
214+
// We have to invalidate the virtual module & deps, not the real one we just transformed
215+
// The deps have to be invalidated in case one of them changing was the trigger causing
216+
// the current transformation
217+
if (file.endsWith('.css.ts')) {
218+
invalidateModule(fileIdToVirtualId(file));
219+
}
220+
}
221+
222+
return result;
223223
}
224224
},
225225
resolveId(source) {

0 commit comments

Comments
 (0)