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] : CSSNano has problems with postcss-nested #1004
Comments
Hi, thank you for the detailed reproduction! I have managed to reproduce the bug and I also believe it is fixed in the cssnano 5.0.0 release candidate. Could you tell me if the release candidate fixes the issue on your end too?
|
Hey, great to hear it. I tested it, and it seems to work. thx :) |
Unfortunately, I have a more detailed example: #app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
transform: scale(0.5);
transition: all 400ms ease-in;
p {
margin-top: 60px;
width: 100%;
height: 50px;
display: block;
background-color: yellow;
border: 1px solid black;
&.t {
color: green;
}
}
}
div {
margin-top: 60px;
} and the output ignores the Output: #app {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
font-family: Avenir, Helvetica, Arial, sans-serif;
text-align: center;
transform: scale(0.5);
transition: all 0.4s ease-in;
}
#app,
#app p {
margin-top: 60px;
}
#app p {
background-color: #ff0;
border: 1px solid #000;
display: block;
height: 50px;
width: 100%;
}
div {
margin-top: 60px;
} |
Interesting. My intuition would be that |
Yeah I thought also. I thought I need to change the order, when the stuff should run, but this is not needed as you said? |
hey, is there anything todo where I can help here? |
I don't think there is anything to do except diving inside the |
Hey @ludofischer thx for the info. That's is all what I wanted to know. Thx :) |
If I have time, I can also have a look into it. Maybe adding console.logs into it to see what comes first :D |
Didn't check the new version yet, will check this first and will let you know :) |
It would be wonderful if you could help improve the situation, a few people already tried but so far I have not heard back from any of them ;-). Last time I checked there are similar issues open in other minifiers too. Merging rules and declarations often yields small size improvements, so it is often handier to disable the optimization completely. For example esbuild managed to become a fairly competitive CSS minifier in a short time, part of the secret is that esbuild just does not attempt merging rules (last time I have checked). |
Atm I have some other projects todo, that's why I can live with the result for now. I also checked the newest versions and unfortunaltey, same problem. Will check what I can and will let you know when I have time. Maybe we should switch to discussions. Otherwise we can stay here :) |
An alternative to cssnano is csso. So I tried this code which is the end result of cssnano: #app {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
font-family: Avenir, Helvetica, Arial, sans-serif;
text-align: center;
transform: scale(0.5);
transition: all 0.4s ease-in;
}
#app,
#app p {
margin-top: 60px;
}
#app p {
background-color: #ff0;
border: 1px solid #000;
display: block;
height: 50px;
width: 100%;
}
#app p.t {
color: green;
}
div {
margin-top: 60px;
} and the output of csso (http://css.github.io/csso/csso.html -beautified) is: #app {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
font-family: Avenir,Helvetica,Arial,sans-serif;
text-align: center;
transform: scale(.5);
transition: all .4s ease-in
}
#app,#app p,div {
margin-top: 60px
}
#app p {
background-color: #ff0;
border: 1px solid #000;
display: block;
height: 50px;
width: 100%
}
#app p.t {
color: green
} as you can see, this is my expected output. When I Take the input code and try it on the cssnano playground, output will be the same as the input. So maybe a look into csso could be good? |
This is again caused by the decision in postcss-merge-rules to only merge adjacent rules to avoid cascade problems. I think it does not cause incorrect output, just a missing optimization. |
I understand the thing. I mean this is why I created this ticket. At the end maybe this is a missing feature so removing the bug is fine for me. I just tested csso and it handles it correct. So I thought it was a bug at first time and I expect cssnano to optimice this too. |
Describe the bug
I think it is a bug but at the end I can understand, that this is a missing feature maybe.
I have a piece of code, in which I have two properties with the same value
margin-top: 60px
in a p and in an id selector. CSSNano can handle this and put this together to #app,p{margin-top: 60px}. It will remove the separated p and the property inside of the #app selector and merge them together.When I use the plugin postcss-nested and I put the div within the #app selector, cssnano will not remove the duplicated value.
It will just put the p on the same level, which is correct
#app p{margin-top:60px}
but it will leave the margin-top also inside of the app. For me, I expect to have this#app,#app p{margin-top:60px}
. Everything what I described, you can find here: https://github.com/Chris2011/cssnano-postcss-nested-problemTo Reproduce
Steps to reproduce the behavior:
yarn
yarn build
#app{margin-top:60px}#app p{margin-top:60px}
Expected behavior
Result should be:
#app,#app p{margin-top:60px}
Desktop (please complete the following information):
npx envinfo && npm ls cssnano
The text was updated successfully, but these errors were encountered: