vanilla-extract-css / vanilla-extract

Zero-runtime Stylesheets-in-TypeScript
https://vanilla-extract.style
MIT License
9.5k stars 286 forks source link

[VITE] Libraries shipping vanilla extract css loaded out of order when using vite #1376

Open otaviosoares opened 5 months ago

otaviosoares commented 5 months ago

Describe the bug

It happens when using vite and importing VE css from a library. The css is loaded in a non deterministic way, causing reset css to have a higher priority.

I created a small example using braid-design-system. Apparently, vite's dependency optimizer is bundling the styles in the wrong order, but I'm not sure.

Screenshot 2024-04-05 at 10 59 25 AM

Screenshot 2024-04-05 at 10 59 37 AM

DISCLAIMER: This only happens in dev mode. During build the css file that is extract has the correct order.

WORKAROUND I'm using css layers to avoid this issue but I'm intrigued and would love to know what's causing this behaviour. Any help is appreciated.

Reproduction

https://stackblitz.com/edit/vitejs-vite-qfbgzz

System Info

System:
    OS: macOS 14.2.1
    CPU: (16) arm64 Apple M3 Max
    Memory: 3.28 GB / 128.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 4.0.2 - ~/.yarn/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Chrome: 123.0.6312.107
    Edge: 123.0.2420.81
    Safari: 17.2.1
  npmPackages:
    vite: ^5.1.4 => 5.1.4

Used Package Manager

yarn

Logs

No response

Validations

rururux commented 4 months ago

maybe a duplicate of #725