question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS variables containing only whitespace are incorrectly removed

See original GitHub issue

Environment

Just testing at https://clean-css.github.io/

Input CSS

.inset {
  --inset: inset;
}

.outset {
  --inset: ;
}

.shadow {
  box-shadow: var(--inset) 0 2px 2px #0004;
}

Actual output CSS

.inset{--inset:inset}.shadow{box-shadow:var(--inset) 0 2px 2px #0004}

Expected output CSS

.inset{--inset:inset}.outset{--inset: ;}.shadow{box-shadow:var(--inset) 0 2px 2px #0004}

Explanation

Whitespace is a valid value for a CSS variable, like this:

--my-var: ;

This is semantically not the same as:

--my-var:;

From CSS Custom Properties for Cascading Variables Module Level 1:

Note: While <declaration-value> must represent at least one token, that one token may be whitespace. This implies that --foo: ; is valid, and the corresponding var(–foo) call would have a single space as its substitution value, but --foo:; is invalid.

Because of this issue, clean-css currently cannot be used with Tailwind CSS, as we rely on this feature a lot to support class composition in the framework.

Thanks for your awesome work on this lib ❤️

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jakubpawlowiczcommented, Aug 30, 2021

Thanks @adamwathan for more details on this.

@SuyashJoshi179 go ahead with fixing it, that’s much appreciated!

I think you need to fix the tokenizer first as it doesn’t understand that spaces can be significant. Then level 1 optimizations default to whitespace removal for variables, but in this case it should skip if variable’s value is just whitespace.

Hth, let us know if you need anything else.

0reactions
adamwathancommented, Aug 30, 2021

Hey @SuyashJoshi179! Semicolon is not required you’re correct, here’s a demo:

https://jsfiddle.net/cgys45af/

To test this issue in general, change line 5 to remove the whitespace, then notice that the demo breaks 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

white-space - CSS: Cascading Style Sheets - MDN Web Docs
The white-space CSS property sets how white space inside an element is handled.
Read more >
White space around css3 scale
How can I remove the withe space around the div while scaled ? I can use js if needed ! EDIT: Here is...
Read more >
CSS Custom Properties for Cascading Variables Module ...
If a declaration, once all var() functions are substituted in, contains only a CSS-wide keyword (and possibly whitespace), its value is ...
Read more >
Fighting the Space Between Inline Block Elements
Remove the spaces · Negative margin · Skip the closing tag · Set the font size to zero · Just float them instead...
Read more >
[OutSystems UI Web Style Guide Preview] Remove hard- ...
... Remove hard-coded values of css variables from colors, typography, spaces, ... as it is based on theme, but ALL IT'D harded-code values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found