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

Incorrect @import order in css bundle #16215

Closed
7 tasks done
edoardocavazza opened this issue Mar 20, 2024 · 3 comments · Fixed by #16304
Closed
7 tasks done

Incorrect @import order in css bundle #16215

edoardocavazza opened this issue Mar 20, 2024 · 3 comments · Fixed by #16304

Comments

@edoardocavazza
Copy link

Describe the bug

In CSS, if an entry is imported more than once, the last @import should win over the previous ones.
Instead, Vite generates the CSS bundle preserving just the first import.

For example:

@import './a.css';
@import './b.css';
@import './a.css';

should be equivalent to:

@import './b.css';
@import './a.css';

but Vite treats it like:

@import './a.css';
@import './b.css';

Reproduction

https://github.com/edoardocavazza/vite-css-bundle

Steps to reproduce

  • Run yarn install to dependencies.
  • Run yarn serve to start http-server
    • Navigate to http://127.0.0.1:8080
    • Note the red background (a.css wins over b.css that wins over the first a.css)
  • Run yarn dev to start vite

System Info

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 475.28 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
    pnpm: 8.6.3 - ~/Library/pnpm/pnpm
    bun: 1.0.30 - ~/.bun/bin/bun
  Browsers:
    Chrome: 122.0.6261.129
    Safari: 17.2.1
  npmPackages:
    vite: ^5.2.0 => 5.2.2

Used Package Manager

yarn

Logs

No response

Validations

@edoardocavazza
Copy link
Author

edoardocavazza commented Mar 20, 2024

Side note: using lightningcss as transformer it works as expected.

@sapphi-red
Copy link
Member

The inconsistency has been there for a long time and I guess we cannot change the behavior of postcss-import.
evanw/esbuild#465 (comment), postcss/postcss-import#462

@edoardocavazza
Copy link
Author

I understand the problem of introducing a fix that leads to a breaking change. On the other hand, it should be very clear in Vite's documentation that this issue exists and that the CSS output is potentially very different from that of other tools like esbuild and lightningcss.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants