Skip to content

[css-variables] Computed value of custom property referring invalid custom property #1837

@upsuper

Description

@upsuper

In wpt, there is a test doing this check:

<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", 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions