W3C home > Mailing lists > Public > public-css-archive@w3.org > September 2017

[csswg-drafts] [css-variables] Computed value of custom property referring invalid custom property

From: Xidorn Quan via GitHub <sysbot+gh@w3.org>
Date: Thu, 28 Sep 2017 23:10:59 +0000
To: public-css-archive@w3.org
Message-ID: <issues.opened-261487947-1506640247-sysbot+gh@w3.org>
upsuper has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-variables] Computed value of custom property referring invalid custom property ==
In wpt, there is [a test](https://github.com/w3c/web-platform-tests/blob/37f4e332578f400555eba1252835f0315afdb2d1/css/css-variables-1/variable-substitution-variable-declaration.html#L71-L81) doing this check:
```html
<style>
  #target10parent {
    --varA: good;
    --varB: Also good;
    --varC: another good one;
  }
  #target10 {
    --varA: var(--varB);
    --varB: var(--varA);
    --varC: var(--varB);
  }
</style>
<div id="target10parent">
  <div id="target10"></div>
</div>
```

It is clear that `--varA` and `--varB` should be empty (invalid) for `#target10` because they form a loop. But what should be the computed value of `--varC` on `#target10` here?

The test thinks it should be empty, and all current impls (I tested Firefox without Stylo, Chrome, Edge, and Safari) agree on that. Servo didn't agree with this, and compute `--varC` to inherit the value from `#target10parent`, so we got `another good one`. (This was fixed in servo/servo#18660)

Although we change Servo's behavior to match other impls, it seems that Servo's previous behavior actually matches what the spec says. Specifically, in this case, `--varC` declaration in `#target10` should be ["invalid at computed-value time"](https://drafts.csswg.org/css-variables/#invalid-at-computed-value-time), and per spec,
> When this happens, the computed value of the property is either the property’s inherited value or its initial value depending on whether the property is inherited or not, respectively, as if the property’s value had been specified as the unset keyword.

Given that custom properties are inherited, it seems that `--varC` should really inherit the value rather than being empty in this case.

As all impls agree on the other behavior, and we already have test for that, we probably should change the spec to reflect that, unless people have other opinion. It seems to me that the current behavior (resetting when invalid for custom properties) is both simpler in impl and more intuitive.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/1837 using your GitHub account
Received on Thursday, 28 September 2017 23:10:51 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:41:18 UTC