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

[Feature]: Better support for CSS layers #1318

Open
meesvandongen opened this issue Aug 10, 2024 · 2 comments
Open

[Feature]: Better support for CSS layers #1318

meesvandongen opened this issue Aug 10, 2024 · 2 comments

Comments

@meesvandongen
Copy link

meesvandongen commented Aug 10, 2024

What problem does this feature solve?

When using libraries that use @layer within rspress, the "unlayered" preflight / css reset will have higher priority than any styled declared using the @layer directive. As a result, the highest priority CSS rules may not be the desired rules.

Next to this, the control over the order of css file content in the resulting css bundle file is limited, complicating @layer usage. Considering the user has a library with multiple @layers, the order would need to be defined by the user before any rules are attached to such a layer. (Otherwise the order may be wrong).

/** At the top of the bundled file */
@layer rp-preflight, user-library1, user-library2;

/** later... */

@layer user-library1 {
  /** attach some css rule */
}

I experienced this last problem when I used the bundleless output of modern.js module, since CSS Modules are not bundled in this mode. The individual files inside node_modules will import the CSS files that have been built. In Rspress, all those files will be bundled into 1 css file. The order of the imports (which is related to the order of the bundle) is harder to control in this case.

What does the proposed API look like?

For the first point, something like this in base.css could help:

@import url(./preflight.css) layer(rp-preflight);

For the second point; the code could be altered such that the globalStyles is always the first file.

@meesvandongen
Copy link
Author

As a workaround I can use

head: ["<style>@layer rp-preflight, user-library1, user-library2;</style>"],

But this works only during build (is that intended?).

@chenjiahan
Copy link
Member

chenjiahan commented Aug 11, 2024

This may be related to: web-infra-dev/rspack#7452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants