Re: [csswg-drafts] [css-cascade-4] Revert at computed-value time (#4155)

I'll include my rant in this topic from the Blink I2S, for reference:

_(Excerpt begins)._

The biggest thing I don't like about this spec is that it's attempting to 'revert' at computed-value time, which I really think shouldn't be allowed. We risk running into a circularity at some point, since computing 'forced-color-adjust' requires cascading, yet its computed value affects how things cascade. (Yes, css-logical has a similar problem, which is not a convincing argument for making things worse). It's not a huge problem in practice, since the properties being reverted don't really affect other properties currently.

But imagine if forced colors mode wanted to do 'font-size:revert' (which doesn't make sense, but let's say that it did):

@property --x {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;

div {
  font-size: 20px;
  --x: 10em;
  forced-color-adjust: var(--x);

In order to know the computed value of 'forced-color-adjust' in this example, we must first compute '--x'. This contains 'em' units, which means the computed value of 'font-size' needs to be known. The computed value of 'font-size' is obviously '20px', which makes the computed value of '--x' 200px. When substituted into forced-color-adjust, we get forced-color-adjust:200px, which doesn't parse for that property, hence it becomes invalid at computed-value time, and is treated as unset (which becomes auto in this case).

Now the forced colors mode wants to revert font-size back to the UA-style (e.g. 16px), but the computed value of font-size has already been determined at 20px. Worse, its previously computed value had side effects: --x has a computed value of 200px, which would no longer be correct if font-size is reverted after its value is computed. Reverting font-size alone will not be enough to undo the "damage" done by the temporary and ultimately incorrect computed value of font-size. This is a bad situation.

To reiterate, the spec doesn't revert any properties that other properties depend on, so it doesn't exhibit this bad behavior currently. But it seems like it very easily could in the future, if we were to e.g. change how colors work. And in general I wanted to highlight why I think reverting at computed-value time isn't great.

_(Excerpt ends)._

GitHub Notification of comment by andruud
Please view or discuss this issue at using your GitHub account

Received on Thursday, 7 May 2020 19:14:48 UTC