Closed gustmnds closed 3 months ago
Seeing the same issue when I created a similar setup in my theme styles for my Ladle stories
I've been looking into this, as someone completely new to this codebase, so take my findings with an enormous grain of salt.
Given the file structure that I'm working with in my project:
.ladle
theme
button.css.ts (imports from ../src
& exports static named object with properties that call style
)
index.ts (exports all styles from ./button.css.ts
and other siblings)
components.css.ts (imports from ./theme
)
components.tsx (imports from ./components.css.ts
& ../src
)
src
components (loads of components, styles, stories, etc)
_ styles (global styles, etc)
Problem space (as described above):
Editing .ladle/theme/button.css.ts
doesn't update styles
My findings (many things will be obvious for those who know more than me):
components.css.ts
serves as the main file entry point for components.tsx
style renderingcomponents.css.ts
are correctly associated as watch files https://github.com/vanilla-extract-css/vanilla-extract/blob/master/packages/integration/src/compiler.ts#L333button.css.ts
is saved, the compiler is told to process components.css.ts
https://github.com/vanilla-extract-css/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts#L209cssObjs
, cachedCss
& cachedClassRegistrations
, which a dep may have one or more of. In my case, button.css.ts
has all 3cssObjs
seeming to be a trigger for re-transformCss
-ing of the dep, this doesn't appear to be carrying through to the rendered component https://github.com/vanilla-extract-css/vanilla-extract/blob/master/packages/integration/src/compiler.ts#L350index.ts
is skipped and components.css.ts
imports button.css.ts
directly there is no change in behaviorcomponents.css.ts
seem to be as expected, showing all dep imports (index.ts
is excluded and all deps of index.ts
are present). All exports appear to be populated with expected values.I didn't end up finding the answer yet. I'll probably look into it further tomorrow
Possible solution (tested that it does allow styles to update, untested for possible undesirable side effects): https://github.com/vanilla-extract-css/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts#L217
// We have to invalidate the virtual module, not the real one we just transformed
// REPLACE:
// invalidateModule(fileIdToVirtualId(absoluteId));
// WITH:
Array.from(watchFiles).forEach((file) => {
if (file.endsWith('.css.ts')) {
invalidateModule(fileIdToVirtualId(file));
}
});
Describe the bug
In my project, I have two files:
theme.css.ts
(which uses createGlobalThemeContract and createGlobalTheme) andglobal.css.ts
(which uses globalStyles and importstheme.css.ts
). Theglobal.css.ts
file is imported in myapp.tsx
. When I make any changes inglobal.css.ts
, the changes are reflected in the front. However, if I change any value in createGlobalTheme intheme.css.ts
, the changes don't reflect in the front until I restart the app.Interestingly, if I import
theme.css.ts
directly inapp.tsx
, the changes are applied.So I think the problem is that the Vite plugin, for some reason, doesn't catch file changes if they are imported by other .css.ts files.
Reproduction
https://stackblitz.com/edit/vitejs-vite-bwy3de
System Info
Used Package Manager
yarn
Logs
Validations