Skip to content

[css-cascade] [css-nesting] Figure out whether we're fine with "shifting up" bare declarations after rules #8738

Closed

Description

@emilio

If you do:

div {
  color: green;
  @media (width > 0) {
    color: red;
    background: red;
  }
  background: green;
}

My understanding is that per spec the div color and background would be red.

That seems rather confusing. There are various alternatives here:

  • We're ok with this.
  • We forbid declarations after nested rules.
  • We deal with bare declarations by somehow sorting them together, so that would be effectively something like:
div {
  color: green;
  @media (width > 0) {
    color: red;
    background: red;
  }
  & {
    background: green
  }
}

Maybe something else?

cc @fantasai

Activity

  1. Loirooriol commented on Apr 19, 2023

    @Loirooriol
    Contributor

    We forbid declarations after nested rules

    Seems potentially problematic that some people may have some garbage followed by lots of declarations, then at some point we add some feature that parses the garbage as a nested rule, and then all the declarations stop applying. Spooky action at distance.

    One of the main characteristics of option 3 (later modified with lookahead) is that it allows freely mixing declarations and nested rules. So at this point I don't think it makes sense to restrict that. The proper way to have such restriction would have been choosing option 4 or similar (which BTW seemed better to me).

  2. tabatkins commented on Apr 19, 2023

    @tabatkins
    Member

    Right, I argued in previous discussions that forbidding decls after rules is fundamentally problematic. The basic question is "when has a rule occurred?", and this needs to not be dependent on whether a rule is valid or not, as that would mean different browser levels would interpret following properties differently.

    So you need to define some notion of when we've found a rule, that allows for invalid rules, and do so in a way that doesn't unduly restrict our future syntax options.

    For example, if we ever allow {} in a property, and you write it invalidly so it triggers rule parsing, would that kick the "now there's a rule" switch? Does that mean we actually have to forbid ever using {} in properties?


    On the other hand, sticking with the current design that just allows them, and relying on people to not write unreadable stylesheets, suffers from none of these issues.

  3. emilio commented on Apr 21, 2023

    @emilio
    CollaboratorAuthor

    Not saying it's necessarily a good idea, but playing devil's advocate a bit, we already have that kind of concept for e.g. @import / @namespace / etc, don't we?

    Imagine someone wrote this ten years ago:

    :has(body) {}
    
    @import "something.css";

    (Or something along those lines)

    Their @import would stop working on browsers that support :has(), yet that hasn't been ever a concern (and I don't think it should be).

    The switch for that is "A valid rule has been parsed", and I think we could do the same, so that random garbage doesn't cause that action at a distance.

  4. tabatkins commented on Apr 27, 2023

    @tabatkins
    Member

    I think these are pretty different situations in practice, tho. We add to the set of "things that can go before @import" super rarely -- in fact, we've only done it once, with @layer.

    On the other hand, we add new things that would qualify for nesting fairly regularly - we recently added @scope, and just resolved to add @initial-name-tbd. So the set of things that may or may not trigger "no more properties from here on" is regularly changed, presenting new hazards.

    Ultimately, the question is still - what are we trying to protect authors from? This sort of interleaving has been allowed in Sass and related tools for many years, with the exact same "pretend all the properties are together at the top" behavior, and never caused notable issues.

  5. SebastianZ commented on Apr 27, 2023

    @SebastianZ
    Contributor

    For example, if we ever allow {} in a property, and you write it invalidly so it triggers rule parsing, would that kick the "now there's a rule" switch? Does that mean we actually have to forbid ever using {} in properties?

    If you mean the property value and I interpret the algorithm correctly, then {} is already allowed by consuming a component value in step 5 of consuming a declaration. And it can't trigger rule parsing because the consumed component value is appended to the declaration's value.

    Sebastian

  6. tabatkins commented on Apr 27, 2023

    @tabatkins
    Member

    This is in reference to the resolved-on new parsing algo that tries to parse as a decl, then falls back to parsing as a rule if the result wasn't valid. That algo isn't in the Syntax spec quite yet.

  7. cdoublev commented on May 11, 2023

    @cdoublev
    Collaborator

    That algo isn't in the Syntax spec quite yet.

    Should we expect more changes to come (in CSS Syntax 3, at least) after this commit?

    color: red; @media { foo: bar } color: green does not seem to parse as I would expect against <declaration-list>, probably because there is no ; after foo: bar. I think } should be provided as a stop token to consume a declaration.

  8. tabatkins commented on May 11, 2023

    @tabatkins
    Member

    Thanks for spotting that! I hadn't gotten around to updating my own parser to the new text to test it, so I missed that I was mishandling nested constructs.

    I believe it's all good now; the three construct consumption algorithms (at-rule, qualified rule, declaration) now all take a "nested" bool, which triggers them to stop early when encountering a top-level unmatched }. This is passed by "parse a block's contents" (which is renamed from "parse a declaration list" since it definitely returns more than just declarations).

  9. cdoublev commented on May 12, 2023

    @cdoublev
    Collaborator

    <declaration-list> is defined with consume a list of declarations and the procedure to parse the input of CSSStyleDeclaration.cssText is defined with parse a list of declarations. Both procedures are removed.

    I do not mind waiting for an update to your parser to validate your updates. This would prevent me from polluting this issue with implementation details.

    That said, <declaration-list> could be renamed to <statement-list> and could be parsed with consume a list of statements.

    This would allow using <declaration-list> for when a list of declarations (strict) is required (eg. keyframe rule, @font, etc). But I do not know if it would be backward compatible to apply it to existing rules, and your intent may even be to preserve this flexibility to accept declarations/rules within any rule, for future extensibility.

  10. tabatkins commented on May 12, 2023

    @tabatkins
    Member

    I've done the parser update, but had to stop at end of day before I could get my testing framework updated to the new data structures. Later today I'll have it working. ^_^

    But I do not know if it would be backward compatible to apply it to existing rules, and your intent may even be to preserve this flexibility to accept declarations/rules within any rule, for future extensibility.

    Yes, all rules already handled at-rules in their blocks even if they only accepted declarations validly, so that's staying, and at that point there's not really any reason to continue having a parsing split. All blocks are parsed the exact same way now in Syntax, accepting all three kinds of constructs (at rules, qualified rules, declarations).

    My plan on reshuffling the productions is just to define one generic production, and then probably some sub-productions that automatically imply certain restrictions on what's valid so you don't have to say it in prose. But they won't change the parsing behavior.

  11. LeaVerou commented on Jun 15, 2023

    @LeaVerou
    Member

    Unfortunately, it appears that Chrome shipped before we could decide on this, and now authors are already blogging about the "gotcha".

    Hopefully it's not too late to change this.
    I think we should really try to avoid any rewriting that changes order of declarations.

    Since we’re already resolved that nested MQs will wrap their contents with an implicit & {}, perhaps we can do the same thing with any declarations after the first nested rule, as @emilio proposes in the OP?

  12. tabatkins commented on Jun 15, 2023

    @tabatkins
    Member

    I still feel very strongly that we should not change this, and the current behavior is the best. Again, this is the exact behavior that Sass (and I suspect other preprocessors) have had for a decade+ already, and it has not been a problem there. (Largely because people just don't write that code - they put their declarations first, then their nested rules.) I don't think we should try to add more behavior for something that has proven itself to not be a problem in practice.

    MQs wrap all naked properties in an & {}; style rules obviously cannot do this, so the behavior would be inconsistent either way. As the spec is currently written, style rules and MQs are each internally consistent with a single behavior for all naked properties. I think it would be a (probably minor) bad thing for style rules to have two behaviors, depending on relative ordering of rules and declarations.

  13. kizu commented on Jun 16, 2023

    @kizu
    Member

    While I would like to see a world where the order would stay as written, I think I agree with Tab on that this is the behavior that was implemented in all preprocessors: less, sass and stylus, at least some CSS-in-JS solutions (tested in styled-components, couldn't find a good playground to share), and nested PostCSS plugin (can be tested here), lightningCSS (but it polyfills the current spec).

    Given this was done literally everywhere, I'd say it is not worth it to change this.

  14. 92 remaining items

  15. astearns commented on Apr 16, 2024

    @astearns
    Member

    In the interests of resolving this 90-comment issue, would it be OK to open a new issue on the details of @nest, or do we need to figure it all out to make any progress?

  16. LeaVerou commented on Apr 17, 2024

    @LeaVerou
    Member

    In the interests of resolving this 90-comment issue, would it be OK to open a new issue on the details of @nest, or do we need to figure it all out to make any progress?

    I think we can probably resolve on the general proposal, then discuss serialization in a separate issue.

  17. mdubet commented on Apr 17, 2024

    @mdubet

    Same point, really - is it worth doing anything more complicated than just "here's a new type of at-rule, it acts like you'd expect"?

    More complicated for browser engine indeed, but less complicated for CSS users (no need to learn about a @nest rule which will maybe create some confusion with the nesting selector & ..etc)

  18. emilio commented on Apr 17, 2024

    @emilio
    CollaboratorAuthor

    More complicated for browser engine indeed, but less complicated for CSS users

    Not sure I agree. This requires to expand the API surface of CSSOM quite a bit, or changing APIs in ways that are confusing / inconsistent (like not returning rules from .cssRules), or unclear...

    If you're not inspecting stylesheets via script, it doesn't matter either way. If you do, then IMO the @nest rule is easier to deal with than something new / more complicated. It just works like a style rule.

    Given that, and that this is somewhat of a time bomb which we probably want to fix sooner rather than later, I tend to think that the simplest / less magical solution is best.

    • It's implementable in a very straight-forward / performant way in all engines.
    • It raises less open / follow-up questions.
    • It's (IMO) not worse for authors than the current state of things or alternatives.

    @tabatkins regarding the proposal, I'm assuming:

    • @nest doesn't need to be a grouping rule (though I guess it doesn't matter much either way).
    • With "style rules" in your proposal you mean style declarations, presumably, right?
  19. andruud commented on Apr 17, 2024

    @andruud
    Member

    Fully agree with @emilio.

    I initially thought that we should serialize back to bare declarations for outer cssText since it's shorter, nicer, and basically "why not". But the round-trip issues and other edge cases convinced me the other way.

    @LeaVerou You said that we should consider another name for @nest, would that mitigate the situation? If the name better explains what it does/is, maybe its presence will feel less offensive? @this? @self? @wart?

    changing APIs in ways that are confusing / inconsistent (like not returning rules from .cssRules)

    Yes, let's avoid this, please. Getting creative about the OM structure is even more intrusive than getting creative about its serialization.

  20. css-meeting-bot commented on Apr 17, 2024

    @css-meeting-bot
    Member

    The CSS Working Group just discussed [css-cascade] [css-nesting] Figure out whether we're fine with "shifting up" bare declarations after rules, and agreed to the following:

    • RESOLVED: Tab specs this by representing @nestin the CSSOM, with an inline issue about@nest as a syntactic construct that authors could write being something we might want to get rid of
    The full IRC log of that discussion <emilio> TabAtkins: So, background... current spec for nesting allows you to interleave declarations with rules
    <emilio> ... the way it's handled in the syntax spec is that all the declarations get collected together
    <emilio> ... losing the order information relative to the rules
    <emilio> ... this appears to cause author confusion
    <emilio> ... particularly if you repeat the same declaration a few times between things
    <emilio> ... it also means that whenever we introduce mixins, the ability to make it work with nesting doesn't work well
    <emilio> ... so thought was, can we instead interpret declarations in between rules as if they were wrapped in another rule
    <emilio> ... it interacts nicely with cssRules etc
    <emilio> ... andruud added use counters and it seems it can probably be made
    <lea> q?
    <lea> q+
    <emilio> ... I proposed the change in the comment from the agenda
    <kbabbitt> q+
    <lea> q-
    <lea> q+
    <emilio> ... basically collect declarations into a new type of atrule (tentative name `@nest`)
    <emilio> ... `@nest` doesn't do anything other than grouping the declarations
    <emilio> ... This is slightly different to wrapping the parent selector
    <emilio> ... So it improves our behavior when nesting declarations inside media queries
    <emilio> q+
    <emilio> ... everyone seemed happy with it, only q was about serialization which we'd move to a different issue
    <emilio> ... authors can write it but it's not particularly useful for them to do so
    <emilio> astearns: before going to the queue, wanna say that we only need to resolve on the approach
    <astearns> ack kbabbitt
    <emilio> kbabbitt: a little uncertain about how this interact with the OM
    <kbabbitt> .rule1 { font-family: serif; color: blue; }
    <emilio> ... was playing with an example
    <kbabbitt> .rule2 { font-family: serif; @media (...) { ... } color: blue; }
    <emilio> ... if I do setProperty("color", "red")
    <emilio> ... does it know how to dig inside @nest?
    <emilio> ... or ends up not having an effect
    <emilio> TabAtkins: the later
    <emilio> kbabbitt: that's a bit concerning
    <emilio> ... in this world setProperty I added an @media and suddenly that doesn't work anymore
    <emilio> TabAtkins: I agree you can run into potentially confusing situations with this
    <emilio> ... but it's not incompatible with current usage
    <matthieud> q+
    <astearns> ack lea
    <TabAtkins> scribe+ TabAtkins
    <TabAtkins> emilio: It is unfortunate that that woudl stop working, but it's also a tradeoff that seems hard to avoid
    <TabAtkins> emilio: In the ame example, if you set color in both locations, and you wanted to *keep* both color declarations (which is what needs to happen here), it becomes..
    <TabAtkins> emilio: Like, maybe you can discard the previous somehow. But if you want to keep the altter decl you need a place to store it.
    <TabAtkins> emilio: So it seems hard to avoid unless we do even more invasive changes to the OM, like letting you represent both declarations and rules directly
    <TabAtkins> emilio: Not convinced that's worth it
    <TabAtkins> emilio: I also think we generally discourage mutations in CSSOM when they affect stylesheets.
    <TabAtkins> emilio: Doing so has pretty bad perf implications, it dedups shared/cached stylesheets.
    <TabAtkins> emilio: So not sure it's worth rejiggering to "fix" this case
    <TabAtkins> emilio: If you wrapped the decl in a *different* rule, it would also not be changed by setProperty()
    <TabAtkins> kevin: to be clear, in my example the decl isn't in the @media
    <TabAtkins> emilio: Right, just saying that it's in an @nest, and if it were any other rule it woudlnt' be surprising
    <TabAtkins> kevin: just concerned that adding an @media in the middle of a rule causes the beahvior to change
    <TabAtkins> matthieud: In the issue we discussed using cssstyledeclaration, and that woudl avoid the issue
    <TabAtkins> emilio: That wouldn't fix this, you'd need the exact same logic to find the "correct" cssstyledeclaration to mutate
    <TabAtkins> lea: what if we have the proeprty there but it's not enumerable
    <TabAtkins> lea: Like a property that gives you all the decls, and a non-enumerable getter that gives you non-interleaved properties
    <TabAtkins> lea: So normally you'd get the first set, but if you want to read a specific proeprty you'd just all of them from @nests
    <TabAtkins> emilio: What if you have multiple?
    <TabAtkins> emilio: I agree that this setProperty() breakage is somewhat surprising/unfortunate. I don't see a great way of avoiding it.
    <TabAtkins> lea: I think we could design it to minimize the surprise
    <TabAtkins> q+
    <TabAtkins> lea: but we can't do this during the call
    <dbaron> Is the behavior either with or without this change bad enough that CSS style guides will generally say not to use the interleaving feature (i.e., say to put all the declarations first)?
    <TabAtkins> lea: reading properties should work, and there's an unambiguous value for each property, reading them shoudl give you correct
    <TabAtkins> That's gonna be what I'm gonna say when I get to my q entry
    <TabAtkins> emilio: I don't think it's worth complicating the OM substantially. The implicit rule is already magic, I don't want more.
    <TabAtkins> emilio: This is pretty fundamental to what we're dsicussing. If we want the latter rules to act liek rules...
    <lea> +1 for the proposed solution in general. Even though I do feel pretty strongly about the serialization issue, I think it's far better than the current situation _regardless_ of how serialization ends up working, so I think we should try to implement it asap before the current behavior starts being depended on. Far easier to change the serialization than how interleaved rules and declarations behave.
    <dbaron> s/+1 for/lea: +1 for/
    <lea> To summarize the serialization issue, these rules are added magically to author code, so I think when serialized they should also be removed magically, so that author code can roundtrip better. This would mean somewhat surprising behavior in the extremely rare cases where authors actually wrote an @nest rule, but far less surprising in the huge majority of cases where authors did not actually write it.
    <lea> But perhaps more fundamental to the design of this feature, if authors have no reason to write it, should they even be able to? If not, that entirely solves the serialization issue, since we never need to handle it and it becomes a CSS OM detail rather than an actual CSS syntax feature.
    <lea> We may also want to consider adding a new CSS OM property to get *all* declarations, including the interleaved ones.
    <emilio> s/But/lea: But
    <emilio> q+
    <lea> dbaron: I don't think so, especially if we design the CSS OM so that it works in the largest possible set of cases
    <dbaron> s/dbaron:/dbaron,/
    <emilio> emilio: You'd still need to come up with something to return from CSSNestRule.cssText or what not
    <astearns> ack emilio
    <emilio> ... I think I'd rather avoid trying to hide the fact that we implicitly add this rule
    <emilio> ... otherwise this kind of complexity proliferates and causes tons of edge cases everywhere that are bad for both authors end browser developers
    <astearns> ack matthieud
    <emilio> matthieud: In general I don't think we need @nest
    <emilio> ... because we don't want authors to actually use it
    <emilio> ... it's just an implementation detail
    <emilio> ... all these serialization questions would go away if we didn't put it on the spec
    <emilio> ... one solution would be to be able to use multiple CSSStyleDeclarations
    <emilio> ... I think modifying CSSOM is a better solution
    <emilio> q+
    <lea> q+
    <emilio> ... adding a new at-rule that we don't want authors to be using is a good solution
    <emilio> ... I think it's pretty fundamental to this approach
    <emilio> ... I think the question is do we add a new atrule or not
    <emilio> ... the setProperty issue is less of an issue
    <dholbert> emilio: [missed scribing]
    <dholbert> scribe+ dholbert
    <dholbert> emilio: I think the at-rule is the most obvious path forward to fix this
    <dholbert> ... I think it's weird but it's the most obvious weirdness that we don't have to propagate to everywhere else
    <dholbert> ... I don't see how a different approach fixes the annoyances it'd introduce, without massive redesign work
    <lea> emilio you said an @rule can be implemented quickly. Would a CSS OM rule type that doesn't correspond to an actual syntactic rule take longer to implement?
    <emilio> s/[missed scribing]/Multiple CSSStyleDeclarations don't fix any of the weirdness that @nest introduces
    <lea> q?
    <emilio> ack emilio
    <astearns> ack TabAtkins
    <emilio> lea: somewhat? I don't think we have a precedent for anything like that
    <emilio> TabAtkins: what's being brought up is about what's more convenient or predictable when reading and modifying the OM
    <emilio> ... when is that done, compared to writing CSS
    <emilio> ... tool writers do
    <lea> qq+ to reply to Tab
    <emilio> ... but for anything that's not doing that specific thing, the most I've seen anybody do is copying stylesheets around
    <matthieud> q+
    <emilio> ... so actually modifying the OM is really rare
    <emilio> ... so any complexity we introduce there needs to be weighted against the relatively small audience
    <emilio> ... also, when I do this kind of thing I value more consistency / predictability
    <dbaron> (does writing of polyfills tend to touch the OM, or just reparse everything from scratch?)
    <emilio> ... vs. convenient APIs
    <lea> dbaron, depends on the polyfill and how closely it tries to follow the actual syntax
    <emilio> ... I think the @nest proposal keeps consistency for CSSOM
    <emilio> ... anyways, let's resolve on keeping styles where they are
    <emilio> ... I need to write _something_
    <emilio> ... can't go "do this in an unspecified way"
    <emilio> ... unless anybody has a strong objection right now my plan is to put the proposal on the spec, open to change
    <emilio> ack lea
    <Zakim> lea, you wanted to react to TabAtkins to reply to Tab
    <astearns> ack lea
    <lea> Lea: Tab, it's true that tool writers are a tiny minority of authors, but breaking tools has huge impact on authors, since a lot more authors _use_ tools than _write_ tools.
    <lea> Lea: To reply to Emilio’s earlier point, I think there is an underlying design principles issue. I don't think avoiding magic at all costs should be a goal; the right magic can make a huge usability difference, at the cost of implementation complexity. Magic becomes a problem when it's unpredictable for users, and/or when users cannot opt-out of it. Neither seems to be the case here (at least if we design this right).
    <lea> Lea: There one thing that is crucial to understand, emilio you said an @rule can be implemented quickly. Would a CSS OM rule type that doesn't correspond to an actual syntactic rule take longer to implement? Cause I agree we should contain the weirdness, not making this part of CSS syntax is a way to do that. Cause if authors _can_ write it, they will.
    <dholbert> emilio: replying directly to that... then, you need to figure out all the APIs that are on CSSRule that... people expect to be able to call Stylesheet.insertRule, rule.cssText
    <dholbert> emilio: if that rule can't be written by authors, what does that do?
    <dholbert> lea: what is the reason to do insertRule in that case?
    <dholbert> emilio: if you're writing a tool that wants to move rules around. that's the consistency argument that TabAtkins was talking about
    <TabAtkins> Yup, having *one* object that acts differently from everything else inside of .cssRules is generally bad (and needs a fairly significatn justification to break)
    <dholbert> emilio: if I want to filter the set of rules on a stylesheet and put them on another stylesheet, it seems reasonable that you'd be able to call insertRule with the cssText of every stylesheet you care about, but that doesn't work
    <dholbert> lea: why does that need @nest { ...declarations...}?
    <dholbert> emilio: that's not a rule
    <dholbert> TabAtkins: that today would fail to parse. Would be a potential compat impact if we were to make that suddenly valid
    <dholbert> matthieud: why would we use insertRule to insert declarations anyway?
    <dholbert> emilio: you'd use it to insert a nested rule
    <astearns> ack matthieud
    <dholbert> lea: we do want to be able to use CSSOM to insert interleaved rules, so that does seem like a problem
    <emilio> matthieud: I agree CSSOM is a very small audience
    <emilio> ... we should not introduce new complexity in the CSS spec
    <emilio> ... for that
    <emilio> ... only modifying CSSOM is less invasive
    <astearns> ack fantasai
    <emilio> ... if you create new @-rules, then we need to explain it to all authors
    <emilio> fantasai: wondering if it'd make sense to use the nesting at-rule concept in CSSOM but only in the OM, and stripping it out for serialization, and also have the first rule be represented in the same manner?
    <lea> To summarize my position: 1. Ideally, @nest should only exist in the CSS OM, and insertRule() should accept raw decls 2. If that's not possible, then serialization should strip @nest 3. But even if @nest has to be serialized, that's still better than hoisting.
    <emilio> ... so it'd be in .style and .cssRules[0].style
    <emilio> TabAtkins: duplicating them would be inconsistent
    <emilio> TabAtkins: @page does have declarations and rules
    <emilio> matthieud: font-feature-values could take various at-rules and then a nested declaration
    <emilio> q+
    <astearns> ack emilio
    <dholbert> emilio: the other option, a bit less weird perhaps, is:
    <dholbert> emilio: so right now, we're using this trick of a style rule with the & selector
    <dholbert> emilio: the idea behind @nest or whatever the name ends up being, would effectively be wrapping it in a style rule with a magic selector that represents the parent
    <lea> q+
    <dholbert> emilio: @nest is conceptually a style rule with a magic selector that doesn't get wrapped
    <dholbert> emilio: we could define such magic selector somehow
    <dholbert> emilio: would that make people less worried about the OM shenanigans?
    <dholbert> TabAtkins: that wouldn't fix the problems that were brought up
    <kbabbitt> q=
    <kbabbitt> q+
    <dholbert> emilio: it would behave like @nest, and like bare declarations in @media. So less breaking change than what we've been discussing
    <dholbert> TabAtkins: every issue discussed has been from being in a rule of *any* kind
    <dholbert> emilio: it doesn't happen if it's a style rule... I guess we need to explain the new selector
    <dholbert> TabAtkins: that sounds even more magical
    <dholbert> emilio: just wondering if it would be more amenable. But I think @nest is the best solution, given the constraints. Just curious if people would prefer putting the magic in the selector list rather than the at-rule. But I don't mind either way
    <astearns> ack lea
    <lea> Lea: Do note that this does not need to be set in stone, we can implement it as a hidden CSS OM rule type to minimize API surface and fix the immediate problem, and figure out how things like insertRule() would work later — and if we can't, we just promote it to a regular rule. But it's much harder to go the other way
    <astearns> +1 to start with the least user-facing change
    <emilio> kbabbitt: I do agree that we need some kind of a solution, and I think @nest is better than the status quo
    <emilio> kbabbitt: IIUC what emilio was proposing was making @nest explicitly with some sort of selector, it feels less magical
    <emilio> ... it doesn't solve the setProperty issue but it makes it so that if you have to confront that it becomes obvious
    <fantasai> +1 to lea
    <lea> +1 to astearns
    <ydaniv> +1 to both
    <emilio> astearns: does it sound reasonable to make @nest {} as a magic thing that authors can't write?
    <emilio> lea: wasn't it what matthieud proposed?
    <emilio> matthieud: I was proposing using CSSStyleDeclaration
    <lea> s/astearns: does it sound reasonable to make @nest {} as a magic thing that authors can't write?/astearns: does it sound reasonable to make @nest {} as a magic thing that authors can't write for now?/
    <emilio> ... but this sounds a bit in the middle
    <emilio> TabAtkins: if we make @nest parse invalid we can't round-trip
    <emilio> ... anything we do here has significant complexity that makes corners of stuff behave weirdly
    <emilio> astearns: your point was that this wasn't affecting authors much
    <lea> Yes, the idea was there would be no @nest in serialization for now
    <emilio> TabAtkins: it does because we need to define @nest to not serialize
    <emilio> lea: the idea is to make @nest not serialize
    <dholbert> emilio: I agree with TabAtkins for what it's worth
    <emilio> ... if we settle on @nest then we switch to serialize it
    <lea> straw poll?
    <oriol> +1 to Tab and emilio
    <dholbert> emilio: doing this in two steps that can break code seems unnecessary
    <emilio> TabAtkins: really strongly against extra magic other than in parsing
    <emilio> ... unless there's a great argument for that, but I haven't heard one
    <emilio> ... the more changes we make here the more potential there is for compat risk
    <kbabbitt> ack kbabbitt
    <emilio> TabAtkins: I'm close to objecting to things that put lots of magic in the CSSOM
    <emilio> ... the less magic is CSSStyleDeclaration
    <emilio> lea: I think it's great, we have that object already
    <dholbert> emilio: I disagree. how can you make CSS Rules return something that isn't a CSS Rule?
    <dholbert> lea: cssstyledeclaration is the least surprising option. it already exists and fits this perfectly
    <dholbert> emilio: I disagree. Every time we introduce an @ rule, it causes things that [...]
    <dholbert> lea: can we resolve that TabAtkins can scribe whatever makes him happy, and we see if we can resolve on it?
    <emilio> lea: can we resolve on TabAtkins writing whatever he wants and prioritizing next steps on follow-up calls?
    <dholbert> TabAtkins: sounds good to me
    <lea> s/and we see if we can resolve on it?/and prioritize resolving on the additional issues ASAP, next week if possible?/
    <emilio> fantasai: we'd like not to introduce @nest as an author-facing constructs
    <lea> might be useful to do the straw poll anyway to get a sense of what people think, even if it doesn't guide the resolution
    <emilio> ... if this is a temporary step towards that then fine but...
    <emilio> astearns: Proposed: Let tab spec whatever, but note that user-facing @nest is something we want to get rid of
    <emilio> objections?
    <emilio> RESOLVED: Tab specs @nest, with a note about user-facing stuff being something we might want to get rid of
    <lea> TabAtkins please add mention the unresolved issues in the draft?
    <lea> s/add mention/mention/
    <fantasai> s/user-facing stuff/@nest rules as a usable syntactic construct/
  21. tabatkins commented on Apr 17, 2024

    @tabatkins
    Member

    To reiterate my points a bit from the call:

    • Fixing this problem in any reasonable way will affect (positively) approximately all CSS authors (by making properties in MQs/etc work better), and unblock CSS from evolving in certain ways that we want it to (adding mixins).
    • The issues brought up in the latter half of this thread are exclusively about the CSSOM, specifically reading and modifying it. I, personally, have never once read or modified the CSSOM in my entire webdev career; I've only ever done so to write WPTs.
    • So, to a first approximation, these issues affect nobody. ^_^ More precisely, the only audience I know of that actually reads/modifies the CSSOM in non-trivial ways (more than just, say, serializing an entire stylesheet and putting it somewhere else) are CSS tool authors. I'd estimate there to be a few hundred people in this category, across the entire world; a thousand on the extreme end of the possible range. This audience is also going to be significantly more experienced with coding in general.
    • None of the issues listed here are about a use-case being difficult or impossible, which is usually what we can use to justify solving a use-case for such a small audience. They are convenience features.
    • And the convenience itself is arguable in most cases. They're mostly about making the OM more consistent in some ways, but every single one comes at the cost of making it less consistent in other ways.

    So in summary, past the necessary complexity/magic that's at the core of the issue (grouping interleaved declarations in some way so they don't merge with the initial set of decls), any further complexity we add is, as far as I can tell, solely to add minor convenience to some use-cases for a miniscule audience of already-experienced developers. Thus, none of them justify the spec and impl complexity cost they would impose.

    I'm more than happy to be shown wrong on this regard - if you have an example of some change to my base proposal that would either give the "CSS tool authors" audience a large benefit (especially if it unblocks something that is currently hard or impossible), or that would give the "CSS general audience" even a mild benefit, or that would give some third audience I'm not aware of a benefit that is appropriately weighted against its size, then I'd joyfully consider it.

  22. astearns commented on Apr 17, 2024

    @astearns
    Member

    But let’s not make this a permathread to go over all the alternatives and options. This issue was specifically about changing the “shifting up” behavior, which we have resolved to undo (to great author benefit). Please open new issues on specific problems or alternative solutions so that we can have more focused discussion about them.

    @mdubet could you open an issue on the idea of using multiple CSSStyleDeclarations instead of a new @nest rule?

    @LeaVerou would it make sense to open a new issue to explore how far we could go in making things browser-internal and not exposed to developers?

    @kbabbitt if you think it is possible to solve the setProperty() problem while keeping the non-shifting behavior, please open a new issue

    (and anything else I have missed, please open a new issue)

  23. yisibl commented on Jul 15, 2024

    @yisibl
    Contributor

    @LeaVerou It looks like @nest has been removed from the specification again right? This history I think needs an article detailing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions