-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
[Bug]: Empty blocks within @layer rule are not deleted and sometimes @layers blocks are not merged #1594
Comments
This happens because deleting an empty layer might change the layer priority (see closed issue #1544). To prevent keeping useless empty layers, cssnano should remember all the layer names it has seen before, but currently it does not do it. |
When why do you merge the styled into a single layer declaration? If you have to keep the layers, isn't better not to merge them? |
As far as I remember, the code that merges is the same for all at-rules, and predates even existence of |
Hello. Right now I realized, merging is also not working as good as it could if there's nesting of at-rules or styles. Here's a short example @layer layer {
@scope (.class1) {
.class1-child {
color: red;
}
}
@scope (.class2) {
.class2-child {
color: red;
}
}
}
@layer layer {
@scope (.class1) {
.class1-child {
font-size: 1px;
}
}
@scope (.class2) {
.class2-child {
font-size: 1px;
}
}
} Is compiled into @layer layer{@scope (.class1){.class1-child{color:red}}@scope (.class2){.class2-child{color:red}}}@layer layer{@scope (.class1){.class1-child{font-size:1px}}@scope (.class2){.class2-child{font-size:1px}}} While it could be 37% shorter @layer layer{@scope (.class1){.class1-child{color:red;font-size:1px}}@scope (.class2){.class2-child{color:red;font-size:1px}}}} Also, thank you for letting me know that not removing empty layers can change the layer priority. But if layers are configured properly, the change is not possible. Can you please add a configuration to the advanced preset, so a developers could decide whether they want to remove empty layers or not? |
Also, according to caniuse.com at-layer feature can be used by 94% of users worldwide. Can we now consider at-layer has already became more widespread? |
Hello, the changes that you suggest could certainly be made, if someone is willing to implement them. Right now I only focus on problems that cause invalid output |
Describe the bug
If my CSS code contains several instances of using
@layer
rule with the same layer name, after the minification CSS nano will keep each usage of it.This code
Is compiled into this (I added whitespaces)
Expected behaviour
The following
@layer components {}
blocks do not affect the styles, therefore they can be removedSteps to reproduce
The steps are described above
Version
6.1.2
Preset
default
Environment
Package details
Additional context
No response
The text was updated successfully, but these errors were encountered: