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

Disable colormin feature from cssnano #53393

Open
wants to merge 4 commits into
base: canary
Choose a base branch
from

Conversation

RobinMalfait
Copy link

cssnano by default tries to convert rgb colors to an hsla color when the hsla color is shorter for minification purposes.

The issue with this is that the colors aren't the same and we are losing data when converting to hsla.

Input:

html {
  background-color: rgb(143 101 98 / 43%);
}

Output:

html {
  background-color: hsla(4, 19%, 47%, .43);
}

(I pretty printed it to make the diff a bit nicer).

If we would convert this hsla color back to rgb syntax, then it results in:

html {
  background-color: rgb(143 100 97 / 43%);
}

Comparing the original value with the last value, then you can see the difference:

  html {
-   background-color: rgb(143 101 98 / 43%);
+   background-color: rgb(143 100 97 / 43%);
  /*                            ^  ^        */
  }

To solve this issue, we can just disable the colormin minification of cssnano entirely.

cssnano by default tries to convert `rgb` colors to an `hsla` color when
the `hsla` color is shorter for minification purposes.

The issue with this is that the colors aren't the same and we are losing
data when converting to `hsla`.

Input:
```css
html {
  background-color: rgb(143 101 98 / 43%);
}
```

Output:
```css
html {
  background-color: hsla(4, 19%, 47%, .43);
}
```
(I pretty printed it to make the diff a bit nicer).

If we would convert this `hsla` color back to `rgb` syntax, then it
results in:
```css
html {
  background-color: rgb(143 100 97 / 43%);
}
```

Comparing the original value with the last value, then you can see the
difference:
```diff
  html {
-   background-color: rgb(143 101 98 / 43%);
+   background-color: rgb(143 100 97 / 43%);
  /*                            ^  ^        */
  }
```

To solve this issue, we can just disable the `colormin` minification of
`cssnano` entirely.
Took example code from another existing test: `test/e2e/app-dir/app-css/index.test.css`
@adamwathan
Copy link
Contributor

I've opened an issue on cssnano as well in case they'd like to make some changes around this upstream, but since they are looking for new maintainers on that package it might be something anyone can easily prioritize right now and might not happen very quickly:

cssnano/cssnano#1515

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

Successfully merging this pull request may close these issues.

3 participants