#659: CSS tree-scoped at-rule names and references (for @font-face, @keyframes, etc.)
Discussions
Comment by @tabatkins Jul 23, 2021 (See Github)
This is being requested for TAG feedback because it is a CSS-wide behavior change (well, behavior definition), and interacts with shadows and their information-hiding/componentization, so want to make sure we're not missing anything wrt platform consistency or other issues.
The examples Xiaocheng cites are indeed a great in-depth explanation of the behavior, but in short, the behavior is:
-
Whenever a property references an at-rule by name, the keyword for the name is a "tree-scoped reference", and remembers what tree its stylesheet is in. When it needs to find the referenced at-rule, it looks in that tree specifically, even if it's been inherited or assigned to elements deeper in nested shadows.
This ensures that components can't accidentally clash with at-rules defined outside of themselves, unintentionally changing the meaning of inherited or ::part()-inserted values. (Without this, a well-behaved component would have to give their at-rules UUID-ish names to have a high likelihood of avoiding clashes.)
-
If a tree-scoped reference can't find the named at-rule in its remembered tree, it walks up the tree-of-trees to find the name in an ancestor scope. (Or, put another way, at-rules "inherit" down into shadows.)
This mimics the implicit information-leakage that CSS already purposely allows with property inheritance, particularly inheritance of custom properties. It also means that a page can use in-house components that reference things like @font-faces it knows will exist in the outer document. Accidental clashes can only occur if a component is expecting this "inheritance" to work, but is nested inside of a foreign component that also uses the same name; this is the exact same failure scenario that custom properties have.
Discussed
Jul 26, 2021 (See Github)
[is this a small delta?]
Lea: seems very reasonable to me, but not sure what the delta is.
Dan: I'm on it because Chris H pinged. If it is a small delta we want to move it quickly. But it looks like maybe it isn't a small delta. But not a CSS expert.
Tess: been a long time since I looked at this issue.
Peter: seems reasonable to me.. I've relied on things with @font-face propagating down ..
Tess: it's the right direction.. shadow tree gets to know about its context
Peter: nothing leaks upwards
Tess: I think i'ts good. Can't remember specifics from the discussion which happened over several years. A ton of gotchas. This is probably how it should work.
Peter: I agree
Sangwhan: prsumably CSS variables have scoping
Lea: they inherit down shadow trees - this was influenced by how variables behave.
Rossen: this looks pretty good
Peter: close this as satisfied?
Lea: I'm in favour of that. [writes closing comment]
Rossen: only thing I see - closing argument - don't recall we had resolution over email. Not a showstopper just an FYI. I have no evidence of an email resolution.
Discussed
Jul 26, 2021 (See Github)
Sangwhan: this is a long discussion for a small delta
Dan: but it is a reslolved change to CSS. Possibly not a small delta. Discuss at plenary where we have more CSS voices?
Sangwhan: don't think it's controversial..?
Dan: multi stakeholder? [leaves comment]
[punted to the plenary]
Comment by @torgo Jul 27, 2021 (See Github)
@xiaochengh from a multi-stakeholder PoV: from the linked discussion in CSS it looks like Firefox is also implementing. Can you confirm?
Comment by @LeaVerou Jul 28, 2021 (See Github)
Hi @xiaochengh @tabatkins!
We looked at this during the plenary today and overall we are happy with the direction this is going and think the proposed reference mechanism is intuitive. However, we noticed that the linked resolution is tentative, has there been another resolution? If so, could you link to it?
Comment by @tabatkins Jul 28, 2021 (See Github)
It was only tentative in the sense that if we found any compat constraints due to existing wild behavior, we might need to capture that as a special case. As you can see from the partially-filled-in table at https://wiki.csswg.org/spec/css-scoping, there's zero agreement and a lot of cases simply don't work at all today, but the bits of behavior that do work are largely consistent with the resolved/specified behavior, so most code that works today should probably continue to work.
We haven't had a further resolution since that, since compact impact would need to be assessed to go further (and Chrome is gonna be the first to start implementing these behaviors).
Comment by @xiaochengh Jul 28, 2021 (See Github)
@torgo I've requested for Firefox's position here: https://github.com/mozilla/standards-positions/issues/556
Right now they haven't confirmed yet
Discussed
Aug 9, 2021 (See Github)
Peter: needs Lea as well?
Discussed
Aug 23, 2021 (See Github)
Tess: my recollection - where it ended up - the purpose of the shadow dom is encapsulation - this design doesn't bring encapsulation. But intuitively matches.. ... it's what web developers who aren't familiar with programming languages expects - and what people familiar with lexically scoped languages expect. It's intuitive. Some slight oddities. But I'm happy with it. I see in the Moz standards position thread therw was some discussion. I can't say "great" before we get input from people familiar with implementation of CSS features and can look at it and say "this introduces a fundamental complexity" or something similar. I think the working group is getting this feedback. The right people are engaged. From an authoring perspective i think it's great.
Rossen: I agree with Tess regarding the authoring excpectations. It will enforce good practice. From an implementation PoV, it feels like we have 2 opposing efforts - 1 to encapsulate for performance benefits - 2 (this) the reverse look-up problem: as you find things in such a subtree then you have to go back and find it. Do we preemptively propogate properties and values down? That comes with some expense. Since it's "automatic" it will come at some cost for implementers and run-times. It's not all great.
Dan: what should we do? Wait?
Tess: I would be comfortable closing it as long as we said "We'd like to encourage the wg to solicit implementation complexity feedback from folks familiar with CSS implementation in browsers."
Comment by @hober Aug 25, 2021 (See Github)
We discussed this in our plenary session today, and overall we're really happy with where this has ended up in terms of the authoring experience. It would be hard to come up with a solution more intuitive to component authors. We note that this may have implementation complexity impact, so we encourage the WG to solicit implementor feedback from engineers familiar with the innards of each of the three engines.
OpenedJul 23, 2021
Ya ya yawm TAG!
I'm requesting a TAG review of CSS tree-scoped at-rule names and references (for @font-face, @keyframes, etc.).
It has been a long standing issue on how name-defining at-rules (@font-face etc.) should be handled across shadow tree boundaries. The existing behaviors either break shadow tree encapsulation, or do not allow such at-rules in shadow trees at all. They are non-interoperable between browsers, and even inconsistent in the same browser between different rules.
Following a recent CSSWG resolution, a new and reasonable behavior has been proposed. Chromium is planning to implement this new behavior, starting with the @counter-style rule. So I'm requesting a TAG review of this new spec.
Further details:
We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @-notify @xiaochengh