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

Use CSS cascade layer (@layer) #140

Open
siriwatknp opened this issue Jun 13, 2024 · 1 comment
Open

Use CSS cascade layer (@layer) #140

siriwatknp opened this issue Jun 13, 2024 · 1 comment
Assignees
Labels
RFC Request For Comments

Comments

@siriwatknp
Copy link
Member

siriwatknp commented Jun 13, 2024

Why

To ensure that the styles are overrides in a correct order regardless of framework.

The issue I found is from Next.js v14 where the appearance of dev and production are not the same. The generated CSS are the same but the order are not:

dev: the CSS is bundled in one file _page.css which gives the expected result because the styles from sx prop comes later.
production: the CSS is split across files then Next.js specifies through <link rel="stylesheet">, somehow the link that contains sx overrides is placed before the components which gives the unexpected result like the image below (the header should not have background blue).

image

Solution

If styles are organized with CSS layer, the appearance will be the same for both dev and production regardless of how frameworks bundle the build.

Proposal

As a start, Pigment should have 2 layers when enabled: @layer base, overrides

  • base are default styles including CSS variables from the theme and component styles. This is for library author, e.g. Material UI to use.
  • overrides are styles from the consumer, any APIs that are used in the project including theme.components.

Search keywords:

@siriwatknp siriwatknp added the RFC Request For Comments label Jun 13, 2024
@siriwatknp
Copy link
Member Author

@brijeshb42 Do you think variants layer is needed?

@omerman omerman mentioned this issue Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

2 participants