Re: [csswg-drafts] [css-syntax][css-nesting] Design of `@nest` rule (#10234)

The *users* of tools that crawl/modify the CSSOM only matter for this proposal insofar as those tools expose the CSSOM to them (or this proposal makes those tools work better, thus improving the experience of their users). Do you have examples of that?

> I don’t see how this is different than defining what @nest {} does in the root scope. 

Sure, we have to define what `@nest` does in the global scope, in exactly the same way we defined what `&` matches in the global scope. (And it's currently defined to act exactly the same.) But these additional things are *more* corner cases to define. 

> Yes! Which again seems like a win and more broadly useful.

How is this a meaningful win over `x.insertRule("@nest { color: blue; }")`? I mean, it's very slightly shorter, sure. But does it matter otherwise? Is it worth the consistency loss of `insertRule()` no longer being restricted to taking rules?

> I’m not married to the details, but I was envisioning that these nodes would be merged automatically by the CSS OM, not during serialization. All the Web Platform’s OMs are full of these kinds of normalizations, so I don’t see what the problem is.

I don't think that's accurate to say. For example, in the following:

```html
<!DOCTYPE html>
<p>
<script>
var p = document.querySelector("p");
p.appendChild(new Text("foo"));
p.appendChild(new Text("bar"));
console.log(p.childNodes);
</script>
```

You'll get two Text nodes, despite that being essentially identical to just having a single Text node with "foobar". Having nodes magically merge underneath you as a side-effect of doing something unrelated (like removing a rule that previously happened to separate two of them) is the sort of thing that causes bugs in author code *very* easily, since objects disappear, indexes change, etc. in an unpredictable manner.

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


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

Received on Monday, 22 April 2024 21:49:54 UTC