Skip to content

Vite moves @import at the top leading to an erroneous layers order #18384

Description

@ellhn

Describe the bug

I am applying the following css:

@layer reset, bootstrap;
@import url('https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.css') layer(bootstrap);

@layer reset {
  h1 {
    margin-top: 100px;
  }
}

to <h1>Text</h1>

I am expecting:
bootstrap layer to take precedence over reset layer and h1 to have a top margin of 0px.

What is actually happening:
reset layer takes precedence over bootstrap layer and h1 has a top margin of 100px.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ucaxjr?file=main.js,style.css&terminal=dev

Steps to reproduce

No response

System Info

Chrome and Firefox

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamBug in a dependency of Vitefeat: cssp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions