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

Unstable @layer ordering #1112

Open
2 tasks done
Tenga opened this issue Jun 5, 2023 · 3 comments
Open
2 tasks done

Unstable @layer ordering #1112

Tenga opened this issue Jun 5, 2023 · 3 comments
Assignees
Labels
css Issue related to the core css package nextjs Issue related to NextJS

Comments

@Tenga
Copy link

Tenga commented Jun 5, 2023

Describe the bug

While attempting to use @layers with Vanilla Extract and [email protected] (pages dir), ordering of initial @layers seems to be unstable, defeating the purpose of the cascade layers.

The code in the minimal repro was my initial attempt to add 3 layers, and assign them to my reset, component framework, and a third layer (dummy in the repro, so I could observe what's happening) as it made sense to me.

I have followed this logic

  • Created layers.css.ts to define the layer ordering and exported them as suggested by the docs
  • Imported the reset layer to the reset.css.ts and added it to the reset styles
  • Imported the framework layer and added it to the styles for the framework components

While working under next dev, everything seemed fine, as there is a separate style tag containing the contents of layers.css.ts with proper ordering, and then separate style tags which contain contents of other css.ts files.

Running next build and next start, the layer order is broken, as the layers.css.ts and reset.css.ts seem to be combined in a single file resulting in the @layer reset being removed from the initial order. To me, it seems like it's being deduplicated in favor of the declaration in the reset.css.ts, resulting in out of order layers.

I've also tried and observed the following:

  • Importing layers.css.ts explicitly in _app.tsx before the reset.css.ts
    • No effect
  • Importing reset.css.ts in the page, instead of the _app.tsx.
    • Layers are "deduplicated" and ordered depending on the import order. Also unpractical.
  • Using layer instead of globalLayer
    • No effect
  • Created some dummy styles within layers.css.ts for each layer
    globalStyle("dummy", {
      "@layer": {
        [reset]: { left: 0 },
        [framework]: { left: 0 },
        [dummy]: { left: 0 },
      }
    });
    
    • Seems like a workaround as this preserves the layer order, even tho the the @layer <layer> declarations are "deduplicated"

Reproduction

https://github.com/Tenga/ve-layers-repro

System Info

System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 711.61 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
    npm: 9.5.0 - ~/.nvm/versions/node/v18.15.0/bin/npm
  Browsers:
    Chrome: 114.0.5735.90
    Firefox: 111.0.1
    Safari: 16.3
  npmPackages:
    @vanilla-extract/css: ^1.11.1 => 1.11.1
    @vanilla-extract/next-plugin: ^2.1.3 => 2.1.3

Used Package Manager

npm

Logs

No response

Validations

@mattcompiles mattcompiles added css Issue related to the core css package nextjs Issue related to NextJS and removed pending triage labels Jul 3, 2023
@askoufis
Copy link
Contributor

I wonder if this next issue is the cause vercel/next.js#16630

@6mint
Copy link

6mint commented Apr 16, 2024

Next 14.2 supposedly maintains css import order now.
You might want to check if the problem persists.

@askoufis
Copy link
Contributor

Next 14.2 supposedly maintains css import order now. You might want to check if the problem persists.

This doesn't seem fixed as of Next 14.2.2 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css Issue related to the core css package nextjs Issue related to NextJS
Projects
None yet
Development

No branches or pull requests

5 participants