Skip to content

Commit 0a3353b

Browse files
authored
[fix] do not collapse whitespace-only css vars (#7303)
Fixes #7152, see also #7288 --foo:; used to be an invalid CSS custom property value, while -foo: ; was valid. By collapsing the whitespace in these declaration values, we were breaking scenarios where an empty custom property was desired. The spec was updated to trim whitespace and treat these values identically, but Chromium browsers still treat --foo; as invalid. This was recently fixed and will be released in Chrome 99, but this would still be a good fix to maintain backwards compatibility.
1 parent 2c629bc commit 0a3353b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/compiler/compile/css/Stylesheet.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class Declaration {
145145
? this.node.value.children[0]
146146
: this.node.value;
147147

148+
// Don't minify whitespace in custom properties, since some browsers (Chromium < 99)
149+
// treat --foo: ; and --foo:; differently
150+
if (first.type === 'Raw' && /^\s+$/.test(first.value)) return;
151+
148152
let start = first.start;
149153
while (/\s/.test(code.original[start])) start += 1;
150154

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
:root{--root-test:20}div.svelte-xyz{--test:10}
1+
:root{--root-test:20}div.svelte-xyz{--test:10}div.svelte-xyz{--foo: ;--bar: !important}

test/css/samples/css-vars/input.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
div {
88
--test: 10;
99
}
10+
11+
div {
12+
--foo: ;
13+
--bar: !important;
14+
}
1015
</style>

0 commit comments

Comments
 (0)