Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@vanilla-extract/vite-plugin loads css files multiple times in Storybook when using theme #1488

Open
2 tasks done
SamBernaerdtOntoforce opened this issue Oct 10, 2024 · 1 comment
Labels
vite Issue related to vite

Comments

@SamBernaerdtOntoforce
Copy link

Describe the bug

Minimal Problem:
When using themes, vite loads a new (filename).css.ts.vanilla.css?t=1728553686586 file for every other file that uses itin the development build of storybook.

image

Expected:
Each .css.ts file should only be loaded once (until it changes and causes a hot reload)

Problem:
This might not be an issue on the small reproducible project, but on a larger project, where multiple theme files are composited, each of the theme files is loaded for each component using a theme value. This causes so many file loads that it freezes storybook.

image

Reproduction

https://github.com/SamBernaerdtOntoforce/vanilla-extract-theme-and-storybook

System Info

System:
    OS: macOS 14.7
    CPU: (12) arm64 Apple M2 Pro
    Memory: 279.81 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.3 - ~/.nvm/versions/node/v21.7.3/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v21.7.3/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v21.7.3/bin/npm
    pnpm: 8.8.0 - ~/.nvm/versions/node/v21.7.3/bin/pnpm
  Browsers:
    Chrome: 129.0.6668.100
    Edge: 129.0.2792.79
    Safari: 18.0
  npmPackages:
    @vanilla-extract/css: ^1.16.0 => 1.16.0
    @vanilla-extract/vite-plugin: ^4.0.16 => 4.0.16
    vite: ^5.4.8 => 5.4.8

Used Package Manager

yarn

Logs

No response

Validations

@askoufis askoufis added vite Issue related to vite and removed pending triage labels Dec 11, 2024
@askoufis
Copy link
Contributor

Thanks for the reproduction! It definitely looks like there could be an optimization here. This doesn't seem related specifically to Storybook as I can reproduce the issue using just a vite dev server.

It seems that the issue starts once HMR has kicked in at least once. Different files that share the same dependency (e.g. shared.css.ts) end up with different timestamped imports of that file, causing both of them to be loaded, even though only 1 is necessary.

I'm also seeing some inconsistency in how many .vanilla.css files are loaded. Occasionally each file is loaded only once:
image

However most of the time the same file is loaded a few times (but with different timestamps):
image

This could be a result of how vite loads modules during development, and maybe there's nothing we can do to change it. I'll need to dig into it some more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vite Issue related to vite
Projects
None yet
Development

No branches or pull requests

2 participants