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

Define how origin is determined for a constructed stylesheet #18

Closed
TakayoshiKochi opened this issue Feb 6, 2018 · 4 comments
Closed
Labels
needs resolution Needs consensus/resolution before shipping

Comments

@TakayoshiKochi
Copy link
Member

Copied from inline ISSUE 5 in the section "Applying Styles In All Contexts".

One of the major "misuses" of the >>> combinator is to apply "default styles" to a component wherever it lives in the tree, no matter how deeply nested it is inside of components. The use-case for this is to provide the equivalent of the user-agent stylesheet, but for custom elements (thus, the styles by necessity must come from the author).
Unfortunately, this is extremely slow, and there’s not a whole lot that can be done about that—>>> combinators are slow by their nature. Note, though, that the UA and user stylesheets automatically apply in all shadows; it’s only the author stylesheet that is limited to the context it’s created in.

(At this point, one might point out that this is already handled by just setting up styles during element construction. This doesn’t help for cases where a component is purposely authored to be styled by the end-user; forcing users of components to go muck around in their components' source code is a non-starter.)

One possible solution here is to add another origin, the "author default" origin, which sits between "user" and "author", and applies in all shadow roots automatically. We can add a list for these stylesheets, akin to document.styleSheets, and allow you to insert constructed stylesheets into it. Or maybe add an .origin attribute to CSSStyleSheet, defaulting to "author"?

Maybe it only applies to the context you’re in and descendant contexts? Need to investigate; probably bad to let a component apply automatic styles to the outer page via this mechanism.

By default, the added stylesheet via .moreStyleSheets property would have "author" origin, but do we also need other ("user", or "author default") origins?

We may have other interfaces to add stylesheets to different origins, or have CSSStyleSheet have .origin property?

TakayoshiKochi added a commit to TakayoshiKochi/construct-stylesheets that referenced this issue Feb 6, 2018
All 5 inline issues are migrated to GitHub.

WICG#2
Shall we allow asynchronous style sheet parsing?

WICG#3
moreStyleSheets needs better name

WICG#4
Shall we include added stylesheets in `document.styleSheets`?

WICG#5
StyleSheetList will need to define a constructor, accepting a `sequence<StyleSheet>`.

WICG#18
Define how origin is determined for a constructed stylesheet
@platosha
Copy link

It was proposed before to add a “default” origin, and use an @default at-rule as an interface to add styles. Would that be an option?

Personally, I find using a dedicated at-rule reasonable. As it was mentioned here, there are reasons to ban using combinators in selectors for stylesheets with a default origin. Without an at-rule wrapping it would be weird to have special limitations on selectors in these stylesheets, unlike anywhere else.

@TakayoshiKochi
Copy link
Member Author

Unfortunately people are reluctant to add a new cascading origin (esp. people at Apple) so @default will not happen as it is in the quoted document, at least in near future, I'd say.

@TakayoshiKochi TakayoshiKochi added the needs resolution Needs consensus/resolution before shipping label Apr 17, 2018
@TakayoshiKochi
Copy link
Member Author

TakayoshiKochi commented May 22, 2018

This depends on the resolution of WICG/webcomponents#468, and Google will try implementing 2 ways (one for using fake-shadow root, which is "author" origin, and the other for default styles for custom elements which is "user agent" origin).

@TakayoshiKochi
Copy link
Member Author

Whatever WICG/webcomponents#468 resolves, this depends on where the constructed stylesheet is applied, and construction itself is independent of "origin" definition, as we already removed .moreStyleSheets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs resolution Needs consensus/resolution before shipping
Projects
None yet
Development

No branches or pull requests

2 participants