Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS tree-scoped at-rule names and references (for @font-face, @keyframes, etc.) #659

Closed
1 task done
xiaochengh opened this issue Jul 23, 2021 · 6 comments
Closed
1 task done
Assignees
Labels
Progress: propose closing we think it should be closed but are waiting on some feedback or consensus Review type: small delta Topic: CSS Venue: CSS WG

Comments

@xiaochengh
Copy link

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:

  • I have reviewed the TAG's Web Platform Design Principles
  • Relevant time constraints or deadlines: August 12, 2021
  • The group where the work on this specification is currently being done: CSSWG
  • The group where standardization of this work is intended to be done (if current group is a community group or other incubation venue): CSSWG
  • Major unresolved issues with or opposition to this specification: I'm not aware of any
  • This work is being funded by: Google

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

@tabatkins
Copy link

tabatkins commented Jul 23, 2021

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.

@torgo
Copy link
Member

torgo commented Jul 27, 2021

@xiaochengh from a multi-stakeholder PoV: from the linked discussion in CSS it looks like Firefox is also implementing. Can you confirm?

@torgo torgo added the Progress: propose closing we think it should be closed but are waiting on some feedback or consensus label Jul 28, 2021
@LeaVerou
Copy link
Member

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?

@tabatkins
Copy link

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).

@xiaochengh
Copy link
Author

@torgo I've requested for Firefox's position here: mozilla/standards-positions#556

Right now they haven't confirmed yet

@torgo torgo modified the milestones: 2021-07-26-week, 2021-08-09-week Aug 5, 2021
@plinss plinss changed the title Request for review: CSS tree-scoped at-rule names and references (for @font-face, @keyframes, etc.) CSS tree-scoped at-rule names and references (for @font-face, @keyframes, etc.) Aug 23, 2021
@hober
Copy link
Contributor

hober commented Aug 25, 2021

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.

@hober hober closed this as completed Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Progress: propose closing we think it should be closed but are waiting on some feedback or consensus Review type: small delta Topic: CSS Venue: CSS WG
Projects
None yet
Development

No branches or pull requests

6 participants