Re: [csswg-drafts] [css-values] Short-circuit if() evaluation (#11500)

> review is appreciated

Generally looks great. However:

> This should address Emilio's concerns about the dependency graph being ill-defined if if() can short-circuit. It's now strictly defined, algorithmically, how and when dependencies are invoked and checked.

I think that's indeed the case if we capture one additional thing: cycles that can happen via the `style()` test. Example:

```css
--foo: if(style(--foo: 10px): green)
```

`--foo` is in a cycle here, because the act of comparing `10px` against the computed value of `--foo` requires resolving the `if()`. For cycle detection purposes, we can simply think of `style()` as an equality check, and the left hand side being replaced with a `var()`:

```css
--foo: if(eq(var(--foo), 10px): green)
```

So we need to expand the [Evaluate](https://drafts.csswg.org/css-values-5/#replace-an-if-function:~:text=be%20condition.-,Evaluate,-condition.%20If%20the) step of "replace an if() function" a little bit, probably.

>  I'll apply the same changes to var() and custom functions

Beware the following pitfalls re. substitutions contexts:

- A function named `--f()` can appear multiple times on the call stack, but refer to _different functions_ due to ShadowDOM. It is therefore not enough to capture the function name as a string in the substitution context: we also need to capture the tree scope.
- A local variable (or "custom property", in the new model) named `--x` can appear multiple times on the substitution stack, but refer to _different local variables_ due to dynamic scoping. Therefore the substitution function needs to capture the custom property name, _and_ the specific custom function (not its name) that it belongs to.

-- 
GitHub Notification of comment by andruud
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11500#issuecomment-2754141206 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 26 March 2025 11:52:31 UTC