Re: [csswg-drafts] [cssom][css-nesting] Error behavior for insertRule with declaration blocks. (#10520)

The CSS Working Group just discussed `[cssom][css-nesting] Error behavior for insertRule with declaration blocks.`, and agreed to the following:

* `RESOLUTION: throw on insertRule only when there are no valid declarations. Do not throw otherwise`
* `RESOLVED: throw on insertRule only when there are no valid declarations. Do not throw otherwise`

<details><summary>The full IRC log of that discussion</summary>
&lt;noamr> emilio: we resolved to be able to call insertRule for various declarations, but we didn't resolve on error handling<br>
&lt;noamr> emilio: 2 options: (1) do nothing, effectively making this API not throw at all, right now we throw. (2) throw, but only when we get empty declaration blocks<br>
&lt;noamr> emilio: 2 is a bit weird if you only specify invalid declarations, but would be consistent with how it's parsing. Seems like there's a variety of opinions on the thread or other options<br>
&lt;noamr> astearns: other people who have commented<br>
&lt;noamr> Mattieud: we thought that maybe we'd add another function, insertDeclaration, to avoid this issue.<br>
&lt;emilio> q+<br>
&lt;noamr> MattieuD: This was one of the options we resolved on last time, still option for the discussion.<br>
&lt;astearns> ack emilio<br>
&lt;noamr> emilio: I thought we wanted insertRule work and would do the right thing<br>
&lt;noamr> TabAtkins: the resolution was to prefer insertRule, but fall back if necessary due to web compat<br>
&lt;noamr> emilio: were you against throwing on declaration blocks?<br>
&lt;noamr> TabAtkins: I want to be consistent. Need to look at existing implementation. If we throw now we should keep throwing<br>
&lt;noamr> emilio: insertRule current throws<br>
&lt;noamr> TabAtkins: then insertRule should throw if the declaration is consisting only of invalid rules<br>
&lt;noamr> emilio: that's the current spec<br>
&lt;noamr> matthieud: The spec says to throw syntax errors in multiple places<br>
&lt;noamr> astearns: matthieud are you ok with matching the throwing behavior here, or prefer a separate method?<br>
&lt;noamr> matthieud: current is OK, it's a bit weird and surprising when mixing valid/invalid declarations, but that's fine<br>
&lt;astearns> ack fantasai<br>
&lt;noamr> fantasai: throwing on "only invalid rules" vs throwing on "mixed" is weird and inconsistent. we should throw on "some invalid stuff"<br>
&lt;emilio> q+<br>
&lt;astearns> ack emilio<br>
&lt;noamr> TabAtkins: we can't throw on "some invalid" because of forward compatibility, as people won't be able to use it for multiple browsers in the future as it would always throw<br>
&lt;noamr> fantasai: it would be weird if something was throwing for not having any valid rules and then suddenly not throw when one valid rule added<br>
&lt;TabAtkins> we currently throw on "one invalid at-rule", I'm not sure that throwing on "one invalid decl" is inconsistent<br>
&lt;noamr> emilio: that's exactly the CSS parser behavior<br>
&lt;florian> q+<br>
&lt;matthieud> matthieud: the CSS parser and the CSSOM have different behavior "on purpose" : the CSS parser happily skip invalid rules/at-rules/declarations - but the CSSOM throws on invalid rule<br>
&lt;noamr> emilio: It's not that bad, because that's how the CSS parser behavior works<br>
&lt;noamr> emilio: I don't recall the behavior when there are multiple rules<br>
&lt;fantasai> s/any valid rules/any valid declarations/<br>
&lt;fantasai> s/one valid rule/one valid declaration/<br>
&lt;noamr> Matthieud: you can't insert multiple rules with insertRule<br>
&lt;astearns> ack florian<br>
&lt;noamr> florian: from my POV if we throw on everything that's invalid or empty and don't throw on mix valid/invalid, than that's consistent<br>
&lt;noamr> florian: you need at least 1 valid declaration to be valid<br>
&lt;emilio> q+<br>
&lt;noamr> fantasai: if we care about the idea of forward compat, if we use 3 new syntax and one old syntax, and then you remove the old one it starts throwing, it doesn't make sense<br>
&lt;noamr> fantasai: if we want to throw invalid declarations we should always do that<br>
&lt;noamr> florian: it works the same as with inserting an empty string<br>
&lt;astearns> ack emilio<br>
&lt;noamr> emilio: I don't disagree with fantasai but I don't think it's possible because it would make the API never throw with any input<br>
&lt;TabAtkins> `insertRule("@invalid {...}")` throws - this is perhaps a bad idea for forwards compat *as well*, but it's the current long-standing behavior<br>
&lt;noamr> emilio: that's a pretty significant breaking change<br>
&lt;noamr> emilio: the current spec is perhaps the most sensible solution<br>
&lt;astearns> ack fantasai<br>
&lt;noamr> florian: I argue that it makes conceptual sense, not necessarily that it's convenient for devs<br>
&lt;noamr> fantasai: I agree we shouldn't change the behavior for @ rules, that's fine since it's one rule at a time<br>
&lt;noamr> fantasai: I'm arguing that for invalid declarations only, or a mix of valid and invalid declarations<br>
&lt;emilio> q+<br>
&lt;matthieud> q+<br>
&lt;noamr> fantasai: as a consequence we need to decide whether we throw on all-invalid and empty string<br>
&lt;astearns> ack emilio<br>
&lt;fantasai> s/that for/for consistency on/<br>
&lt;noamr> fantasai: we need to either throw or not throw on all-invalid/non-invalid/empty-string<br>
&lt;noamr> fantasai: the 3 of them should behave in the same way<br>
&lt;fantasai> s/non-invalid/some-invalid/<br>
&lt;noamr> emilio: not-throwing on all invalid is not feasible, because you don't know if you were given invalid declarations or an invalid at rule. it gets weird<br>
&lt;florian> q+<br>
&lt;noamr> florian: right, it means changing the existing situation where we throw on invalid rule<br>
&lt;noamr> s<br>
&lt;noamr> s/florian/Matthieud<br>
&lt;fantasai> s/as a consequence we need to decide/and I think we should be consistent about/<br>
&lt;noamr> emilio: then we should other do what's on the spec, or throw on some invalid, but it's a bit odd how the rest of CSS works<br>
&lt;astearns> ack matthieud<br>
&lt;TabAtkins> At the moment there's no way, given the parsing algos, to tell the difference between "empty string" and "all invalid decls"; invalid decls are dropped during parsing.<br>
&lt;noamr> MatthieuD: this would be a breaking API change<br>
&lt;astearns> ack florian<br>
&lt;TabAtkins> If we try to just split on "empty string" vs "not empty", then a string containing just an invalid rule will pass (whereas currently it throws).<br>
&lt;noamr> florian: maybe I'm failing to understand something, but the way I see it, you want to throw as a reaction to anything invalid being passed, while I think we should throw on the absence of something valid<br>
&lt;TabAtkins> We'd had to instead do some heuristic on the stuff in the string to see if it *might* look like there's a decl in there.<br>
&lt;noamr> florian: throwing is not a signal of "something was wrong" but rather "there was not a single thing that was right"<br>
&lt;fantasai> Could check for initial "@" for "invalid at-rule". Probably that's what most people would rely on.<br>
&lt;noamr> florian: at least it's useful in some cases where you insert some valid rules and some invalid<br>
&lt;TabAtkins> Can't look for just an @; style rules are allowed too<br>
&lt;noamr> fantasai: it's ok conceptually, do we want to be resilient on wrong declarations, if we don't throw on most implementations and silently handle invalid declarations, and then some implementation arbitrarily succeeds<br>
&lt;fantasai> TabAtkins, ahh right<br>
&lt;noamr> florian: isn't that useful, when you want to get told when "one thing works" vs "nothing works"<br>
&lt;TabAtkins> Grammar is hard (this is why I wanted insertDeclarations(), fwiw)<br>
&lt;matthieud> I don't think trying to find an heuristic like looking for an @ is a good idea (and it already doesnt work for nested style rule)<br>
&lt;emilio> q+<br>
&lt;noamr> fantasai: why do I care if I dropped 2/3 vs 3/3?<br>
&lt;noamr> florian: it depends why you inserted more than one<br>
&lt;noamr> florian: maybe you added a prefixed and a non-prefixed, it depends on why you use the API<br>
&lt;noamr> florian: this works for fallback properties, where you want "at least one of these to work"<br>
&lt;noamr> florian: you called insertRule, if it succeeded you probably meant it because you have enough fallbacks, but if nothing goes through something went wrong<br>
&lt;noamr> fantasai: this might not be more or less wrong<br>
&lt;astearns> ack emilio<br>
&lt;noamr> emilio: it consistent with how the API behaves right now. If the rule list grows by 1 it doesn't throw, otherwise it throws<br>
&lt;noamr> emilio: it's weird because it's inserting something that's not a rule into a rule list<br>
&lt;noamr> astearns: a lot of comments on IRC, not entirely sure we're ready for a resolution. take back to the issue?<br>
&lt;noamr> fantasai: I'm not going to object, people will be confused, but I don't know if there is a better option<br>
&lt;noamr> fantasai: given the restrictions, I don't see a better solution<br>
&lt;noamr> astearns: concerns about "only throwing when there is nothing valid?"<br>
&lt;noamr> proposed resolution: throw for insertRule if there are no valid declarations, not throw otherwise<br>
&lt;noamr> RESOLUTION: throw on insertRule only when there are no valid declarations. Do not throw otherwise<br>
&lt;noamr> RESOLVED: throw on insertRule only when there are no valid declarations. Do not throw otherwise<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10520#issuecomment-2260929551 using your GitHub account


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

Received on Wednesday, 31 July 2024 16:37:26 UTC