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

Optimizing properties of level 2 removes hsla values #1156

Closed
lex111 opened this issue Mar 2, 2021 · 9 comments · Fixed by davidrapson/davidrapson.co.uk#92
Closed

Optimizing properties of level 2 removes hsla values #1156

lex111 opened this issue Mar 2, 2021 · 9 comments · Fixed by davidrapson/davidrapson.co.uk#92
Labels

Comments

@lex111
Copy link

lex111 commented Mar 2, 2021

For some unknown reason, when using 2 level, color values specified in hsla format are removed.

Environment

  • clean-css version - npm ls clean-css: 5.1.0
  • node.js version - node -v: 12.13.0
  • operating system: Ubuntu 20.04

Configuration options

var CleanCSS = require('clean-css');
new CleanCSS({
  inline: false,
  level: {
    1: {
      all: false,
    },
    2: {
      all: true,
      restructureRules: true,
      removeUnusedAtRules: false,
    },
  },
})

Input CSS

.test {
  border: 1px solid hsla(0, 0%, 65.5%, 0.2);
}

Actual output CSS

.test {
  border: 1px solid;
}

Expected output CSS

.test {
  border: 1px solid hsla(0, 0%, 65.5%, 0.2);
}
@lex111
Copy link
Author

lex111 commented Mar 2, 2021

I also get the same result in the playground with 2 level rules completely disabled.

image

@lex111 lex111 changed the title Removing hsla values Optimizing properties of level 2 removes hsla values Mar 2, 2021
@lex111
Copy link
Author

lex111 commented Mar 2, 2021

So, after a little research, I figured out that this is due to the "optimizing properties", because if I specify the border property in the skipProperties field, the hsla value will not be removed (as it should).

image

@jakubpawlowicz could you please suggest what kind of optimization of properties are carried out, in addition to the existing rules? In my opinion, it is strange that as a result of this, valid values are completely removed.

@jakubpawlowicz
Copy link
Collaborator

Hey @lex111 - it looks like validator thinks it's an invalid CSS color value, but this is not true. Let me check why.

Since level 2 optimizations also check if certain values are valid CSS so in addition to those level 2 optimizations a certain property can be dropped if it's invalid. You are right, we should surface it somewhere. Maybe as warnings?

@lex111
Copy link
Author

lex111 commented Mar 3, 2021

@jakubpawlowicz that would be great, but why is the hsla value determined as invalid in this case, it is strange. Would it take a long time to fix this?

@jakubpawlowicz
Copy link
Collaborator

Let me take a look later today.

@jakubpawlowicz
Copy link
Collaborator

And btw sorry for this causing you trouble!

@jakubpawlowicz
Copy link
Collaborator

It's fixed in 5.1.1.

@lex111
Copy link
Author

lex111 commented Mar 3, 2021

@jakubpawlowicz wow how quickly, many thanks!

@jakubpawlowicz
Copy link
Collaborator

Cheers!

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