Re: [csswg-drafts] [css-cascade] Custom cascade origins (#4470)

The CSS Working Group just discussed `Custom Origins`.

<details><summary>The full IRC log of that discussion</summary>
&lt;fantasai> Topic: Custom Origins<br>
&lt;jensimmons> https://noti.st/jensimmons/QOEOYT/three-topics#srFUYHC<br>
&lt;astearns> github: https://github.com/w3c/csswg-drafts/issues/4470<br>
&lt;TabAtkins> jensimmons: Possibility of custom cascade origins, controlled by authors.<br>
&lt;TabAtkins> jensimmons: Part of a larger convo, which could be called "modernize the cascade"<br>
&lt;TabAtkins> jensimmons: Why modernize? Some folks argue that specificity was designed for a simpler time, when one or a small number of people wrote the CSS for a site. Today CSS is maintained over years by large teams, and the cascade gets really hard.<br>
&lt;TabAtkins> jensimmons: If a dev gets a ticket, they can't really rearchitect the whole page's cascade to fix that one thing.<br>
&lt;TabAtkins> jensimmons: Lots of ways people attack this.<br>
&lt;TabAtkins> jensimmons: (1) just do it right the first time<br>
&lt;TabAtkins> jensimmons: (2) OOCSS, SMACSS, BEM, etc<br>
&lt;TabAtkins> jensimmons: (3) Only ever use one class, to give identical specificity and remove the cascade.<br>
&lt;TabAtkins> jensimmons: (4) overuse !important<br>
&lt;TabAtkins> jensimmons: (5) CSS-in-JS, ignoring cascade again<br>
&lt;TabAtkins> jensimmons: Problem there is no way to control order CSS is loaded. No wonder the cascade is confusing!<br>
&lt;TabAtkins> jensimmons: (6) just inline-style everything, screw selectors<br>
&lt;TabAtkins> jensimmons: Why not use specificiy as designed?<br>
&lt;TabAtkins> jensimmons: IDs increase specificity, but can only use it once per page<br>
&lt;TabAtkins> jensimmons: Not great for components.<br>
&lt;TabAtkins> jensimmons: Element selectors work well for simple defaults, but too dependent on doc structure, and hard to use otherwise.<br>
&lt;TabAtkins> jensimmons: So leaves a lot of these teams only using classes, attributes, and !important<br>
&lt;TabAtkins> jensimmons: [shows example]<br>
&lt;TabAtkins> jensimmons: [Tailwind CSS]<br>
&lt;TabAtkins> jensimmons: [everything's inline, with no cascade]<br>
&lt;TabAtkins> jensimmons: A lot of possible ideas here too, web components, scoping, etc.<br>
&lt;TabAtkins> jensimmons: A project I did last year is how to protect CSS from this hate.<br>
&lt;TabAtkins> jensimmons: So we put together a hard-core course on teaching the cascade.<br>
&lt;TabAtkins> jensimmons: Miri Suzanne did a deep dive into the history/etc.<br>
&lt;TabAtkins> jensimmons: She began thinking about how we could change CSS to modernize the cascade and work better.<br>
&lt;TabAtkins> jensimmons: One of her ideas is to extend selectors, in #4690.<br>
&lt;astearns> https://github.com/w3c/csswg-drafts/issues/4690<br>
&lt;TabAtkins> jensimmons: Another idea is to allow authors to make custom cascade origins.<br>
&lt;TabAtkins> jensimmons: I didn't really know what a cascade origin was until Miri taught me.<br>
&lt;TabAtkins> jensimmons: [describes the cascade origins]<br>
&lt;fantasai> See https://www.w3.org/TR/css-cascade-4/#cascade-origin<br>
&lt;TabAtkins> jensimmons: Proposal is for custom origins. Say, create 3 named origins (get !important variants automatically that work as expected), and put styles in the chosen origin to get auto-overriding.<br>
&lt;TabAtkins> jensimmons: So use case.<br>
&lt;TabAtkins> jensimmons: Reset styles in one origin, design system in another, then one-off overrides into a third.<br>
&lt;TabAtkins> jensimmons: Or split apart the design system: reset -> defaults -> patterns > layouts -> components, all distinct origins.<br>
&lt;emilio> q+<br>
&lt;TabAtkins> jensimmons: Or CMS Core -> CMS Extensions -> Base theme -> site styles<br>
&lt;TabAtkins> jensimmons: Or a team trying to rewrite their CSS. Can't fix it all at once, but could put all their old code in one origin, and put their new code in a higher origin, to piecemeal fix it as they go.<br>
&lt;TabAtkins> jensimmons: Or Bootstrap -> 3rd party -> ad networks -> actual site styles<br>
&lt;TabAtkins> jensimmons: Adventages?<br>
&lt;TabAtkins> jensimmons: Coudl help with specificity wars between frameworks and author styles.<br>
&lt;TabAtkins> jensimmons: Could put !important back into its proper role, rather than being abused just to get a second origin.<br>
&lt;TabAtkins> jensimmons: Or just using origins as a type of !important; might be just as annoying?<br>
&lt;TabAtkins> jensimmons: Pulled some use-cases from Twitter (already mentioned)<br>
&lt;TabAtkins> jensimmons: So what do you think? Want to pursue?<br>
&lt;hober> q?<br>
&lt;florian> q+<br>
&lt;fremy> q+<br>
&lt;astearns> ack emilio<br>
&lt;fremy> q-<br>
&lt;TabAtkins> emilio: I'm a bit confused abuot !important.<br>
&lt;TabAtkins> emilio: If you want ad networks on an origin, and your styles on a higher origin, the ad networks could still override everything with !important style. Maybe that's not what you want?<br>
&lt;bkardell_> q+<br>
&lt;TabAtkins> emilio: Second, it may be invalid, but IDs *can* be repeated on the page...<br>
&lt;TabAtkins> emilio: There are ways for authors to use cascading origins that have better behavior - web components.<br>
&lt;fantasai> fantasai: They're really hard to use<br>
&lt;fantasai> TabAtkins: And also won't handle these use cases<br>
&lt;TabAtkins> TabAtkins: WC doesn't solve any 0f Jen's use-cases, tho.<br>
&lt;TabAtkins> emilio: When we discussed custom element default styles behavior, Apple was strongly against. Unsure if the'd still have complaints.<br>
&lt;fantasai> i/emilio/iank_: We should add declarative shadow roots<br>
&lt;TabAtkins> hober: I'l talk to Ryosuke/Antii, see if they have feelings on this.<br>
&lt;emilio> Though ++ to declarative shadow roots<br>
&lt;astearns> ack florian<br>
&lt;TabAtkins> florian: I think it's a brilliant idea.<br>
&lt;TabAtkins> florian: We've had the luxury of multiple origins here in CSS, letting us design thru problems. Authors haven't had that.<br>
&lt;TabAtkins> florian: I think it would be great. Almost want to stop talking about whether or not to do it and jus tstart talking syntax.<br>
&lt;TabAtkins> florian: Even as a singl eauthoe this seems useful.<br>
&lt;TabAtkins> q+<br>
&lt;astearns> ack fantasai<br>
&lt;TabAtkins> fantasai: I always want to say I love it.<br>
&lt;astearns> ack dbaron<br>
&lt;TabAtkins> dbaron: I'm also a big fan.<br>
&lt;TabAtkins> dbaron: There are multiple choices we coudl make about !important.<br>
&lt;TabAtkins> dbaron: Don't have to say they go in the opposite order. They could go in the same order, or be configurable, etc.<br>
&lt;fantasai> +1<br>
&lt;TabAtkins> dbaron: Maybe have the !important right after the normal origin.<br>
&lt;fantasai> essentially an origin can encapsulate its !important level<br>
&lt;TabAtkins> dbaron: So lots of options we could choose between, or let authors configure.<br>
&lt;AmeliaBR> +1 to dbaron says. Definitely don't want !important to automatically do reverse order.<br>
&lt;TabAtkins> fantasai: Along those lines, might have an origin with sub-origins.<br>
&lt;heycam> q+<br>
&lt;TabAtkins> fantasai: Which might have its !important held within the larger origin<br>
&lt;astearns> ack bkardell_<br>
&lt;TabAtkins> bkardell_: First, thanks for bringing it up.<br>
&lt;astearns> q+<br>
&lt;TabAtkins> bkardell_: I've had these same conversations and I think this is really healthy.<br>
&lt;fantasai> Examples (from slide 25):<br>
&lt;fantasai> Reset &lt; Design System &lt; Overrides<br>
&lt;fantasai> Reset &lt; Defaults &lt; Patterns &lt; Layouts &lt; Components<br>
&lt;fantasai> CMS Core &lt; CMS Extend &lt; Base Theme &lt; Site Styles<br>
&lt;fantasai> Old Styles &lt; New Styles<br>
&lt;astearns> q-<br>
&lt;fantasai> Bootstrap &lt; 3rd-party libs &lt; Ad network &lt; Site Styles<br>
&lt;TabAtkins> bkardell_: To discuss what people are actually doing, rather than just relying on education<br>
&lt;TabAtkins> bkardell_: I think CSS-in-JS does have an order...<br>
&lt;TabAtkins> jensimmons: They can, but don't always<br>
&lt;TabAtkins> bkardell_: wrt WC, they don't solve all problems, but they do solve some. They're already .2% of the web archive, despite only getting the last impl this week.<br>
&lt;TabAtkins> bkardell_: Do we really rely on origin for UA level? I thought we kept them low speicficity.<br>
&lt;TabAtkins> TabAtkins: We don't use IDs, no, but we do freey use attribute selectors, which can easily clash if it wasn't for the origin difference.<br>
&lt;jensimmons> slides (again): https://noti.st/jensimmons/QOEOYT/three-topics#srFUYHC<br>
&lt;fantasai> yes, we really rely on origin for UA level<br>
&lt;TabAtkins> bkardell_: I do believe we'r emissing something here. I don't know if this addresses or exacerbates the problem. At some level it addresses their complaints, but by doubling down on what they're complaining about.<br>
&lt;TabAtkins> jensimmons: Agree.<br>
&lt;astearns> ack TabAtkins<br>
&lt;fantasai> Scribnick: fantasai<br>
&lt;fantasai> TabAtkins: I totally like this idea<br>
&lt;fantasai> TabAtkins: had similar thoughts, but never did the use case exploration<br>
&lt;fantasai> TabAtkins: Definitely agree we should pursue this, and the use cases made me absolutely sure we should pursue this<br>
&lt;TabAtkins> ScribeNick: TabAtkins<br>
&lt;astearns> ack heycam<br>
&lt;TabAtkins> heycam: I think it's very important fo rus to try to address these problems.<br>
&lt;TabAtkins> heycam: A little of a shame that it's taken several years after people started complaining, biut glad we're addressing it now.<br>
&lt;TabAtkins> heycam: What I like about this is that it's so simple, and slots into the existing model.<br>
&lt;astearns> q+<br>
&lt;TabAtkins> heycam: Not super sure about whether it really will capture all of these use-cases, or might need more discussion with real proponents of CSS-in-JS to see how well it works.<br>
&lt;emilio> q+<br>
&lt;TabAtkins> heycam: I'd want to be more sure this is the right way to go for solving that.<br>
&lt;TabAtkins> heycam: But see th eother use-cases anyway.<br>
&lt;TabAtkins> astearns: I agree this is very nice it slots into our model, but a little concerned it's not the general author model.<br>
&lt;TabAtkins> astearns: You had to learn about the concept anyway.<br>
&lt;TabAtkins> astearns: So as Tess said, "origin" is an overloaded term, maybe we can come up with something else?<br>
&lt;TabAtkins> [various suggestions]<br>
&lt;astearns> ack astearns<br>
&lt;astearns> ack fantasai<br>
&lt;dbaron> "style sources"?<br>
&lt;TabAtkins> fantasai: Some discussion about this addressing all the cases; I don't think it does, biut it addresses quite a few, and addresses the organizational layer of many projects.<br>
&lt;TabAtkins> fantasai: So I think it fits well with how people put together their sites.<br>
&lt;TabAtkins> fantasai: There's other places in the cascade where specificity gets unwieldy. I don't think WC is great here; it adds a *ton* of encapsulation.<br>
&lt;TabAtkins> fantasai: Another proposal was scoped styles in CSS, which might also help.<br>
&lt;jensimmons> q?<br>
&lt;bkardell_> if we had this, would we need leaverou 's zero specificity pseudo still too?<br>
&lt;TabAtkins> fantasai: They let you say "within this sidebar, these styles win over other things".<br>
&lt;fantasai> s/things/things, regardless of specificity/<br>
&lt;TabAtkins> TabAtkins: I think declarative shadow dom addresses a lot of the problems with WC; I'd like to explore that more seriously first before we add something that is 98% identical to WC's model, but with 2% weird differences that make impl complicated.<br>
&lt;astearns> ack emilio<br>
&lt;fantasai> bkardell, you wouldn't need it for an entirely swath of styles, but would likely still be useful locally, for specific selectors or parts of selectors<br>
&lt;AmeliaBR> q+<br>
&lt;TabAtkins> emilio: I agree this is neat. Is there a concrete proposal? Is that at the stylesheet level, or allow 3rd party styles to choose their origin, etc?<br>
&lt;TabAtkins> emilio: Depending on details it might solve some use-cases but not vice-versa.<br>
&lt;TabAtkins> emilio: Also need to figure out how this interacts with shadow dom.<br>
&lt;leaverou> bkardell_: I believe so. This is great, but sometimes you need more fine-grained control. E.g. when theming *within* the same origin<br>
&lt;TabAtkins> emilio: Shadow DOM introduces a stack of origins; introducing this naively makes it a matrix, which is harder.<br>
&lt;jensimmons> q?<br>
&lt;astearns> ack AmeliaBR<br>
&lt;TabAtkins> AmeliaBR: echo Emilio's concern that we need details to see exactly how this sort of thing works.<br>
&lt;TabAtkins> AmeliaBR: Coming up with specific proposals and cross-reffing them with specific use-cases would be helpful.<br>
&lt;TabAtkins> AmeliaBR: So we should work from the use-cases to what features we actually need.<br>
&lt;astearns> ack fantasai<br>
&lt;TabAtkins> fantasai: For "how do you control", an easy way to think of it would be the person importing the sytlesheet bea ble to say what level it imports at.<br>
&lt;TabAtkins> fantasai: And within each level, maybe you can have sub-ordering.<br>
&lt;florian> q+<br>
&lt;TabAtkins> fantasai: And with a nesting block that lets you specify the layer within a single file.<br>
&lt;TabAtkins> fantasai: Using numbers to establish the ordering might work if there's only one controller; multiple controllers gives you the z-index wars.<br>
&lt;faceless2> q+<br>
&lt;TabAtkins> emilio: My concern with nubmers or letting stylesheets choose their own levels becomes a z-index fight.<br>
&lt;astearns> ack florian<br>
&lt;TabAtkins> florian: One thing I'm a little concerned is how we figure out the syntax to have a migration path toward this from legacy CSS.s<br>
&lt;TabAtkins> florian: In particular, a syntax ignorable by old browsers is bad because the cascade will be all mushed up; but making it hide rules from old browsers means they'll just miss a lot of code.<br>
&lt;TabAtkins> florian: Writing everything twice is bad, but not having an upgrade path is bad.<br>
&lt;astearns> ack faceless2<br>
&lt;astearns> ack faceless<br>
&lt;TabAtkins> faceless2: What if you had two toolkits, importing the same stylesheet at different levels?<br>
&lt;astearns> zakim, close queue<br>
&lt;Zakim> ok, astearns, the speaker queue is closed<br>
&lt;fantasai> TabAtkins: Same as importing a style sheet twice, it's just present in both places<br>
&lt;fantasai> TabAtkins: cascades together; effectively later one wins<br>
&lt;TabAtkins> jensimmons: So got a lot of good issues and concerns.<br>
&lt;bkardell_> +1 to talk about "this set of problems" for sure<br>
&lt;TabAtkins> jensimmons: I do think it's worth looking deeply at the solutions we might need for the complete set of problems, not just what this particular solution could address, so we can tell if this is a good idea in the totality of a complete solution.<br>
&lt;TabAtkins> jensimmons: I've even convinced myself that if we ship this today by itself, it could get abused pretty badly.<br>
&lt;TabAtkins> jensimmons: (similar to people abusing Flexbox to do grids)<br>
&lt;TabAtkins> jensimmons: Putting this on Twitter, I got a lot of trepidation from folks. Powerful tool, could be bad.<br>
&lt;TabAtkins> jensimmons: But I got that people who really knew CSS the most thought this was a terrific idea.<br>
&lt;TabAtkins> jensimmons: I think it does require some teaching, but it's not that complicated.<br>
&lt;TabAtkins> jensimmons: So I'm hearing a tentative "yeah, this is good", but I think there is a bigger metaproject to modernize the cascade.<br>
&lt;TabAtkins> jensimmons: Also, Miri has been very active in Sass to push CSS to be a featureful language; did crazy things with Sass variables back in the day.<br>
&lt;TabAtkins> jensimmons: So I'd like to invite her as an IE.<br>
&lt;TabAtkins> [intentionally not minuting]<br>
&lt;TabAtkins> fantasai: Where to put it?<br>
&lt;TabAtkins> TabAtkins: Suggest putting it in WICG until it gels, then merge it into Cascade 5.<br>
&lt;fantasai> i/fantasai/astearns: So sounds like interest in the room, try to move proposal forward/<br>
&lt;TabAtkins> jensimmons: And I want to get some highly-skilled authors involved in the convo too, so hopefully WICG works there.<br>
</details>


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

Received on Wednesday, 22 January 2020 17:38:31 UTC