Description
We keep hearing that the strong style encapsulation is a major hinderance - perhaps the primary obstacle - to using shadow DOM.
The problems faced are usually a variant of trying to use a web component in a legacy context where global styles of the page are expected to be applied deeply through out the DOM tree, or a modern context with tools that don't work with scoping, eg Tailwind.
I've see requests to workaround encapsulation formed in a number of ways:
- Turn off shadow DOM (as is an option in LitElement), but keep
<slot>
working (which obviously isn't). - Allow styles to apply from the outside
- Add a way to automatically inject page styles into shadow roots.
- Implement a custom CSS scoping mechanism for when shadow dom is off
- Some specific library, eg Tailwind, converted to work with shadow roots
- etc...
Would it be possible to address some of these difficulties with scoping more or less directly, by adding a new shadow root mode that allows selectors to reach into a shadow root from above? Something like:
this.attachShadow({mode: 'open-stylable'});
Application developers could then make sure that elements from the root of the page on down to where they need styles to apply use open-stylable shadow roots. Library authors could offer control over the mode for legacy situations, etc.
I'm not sure how combinators would work here. ie, would .a > .b {}
apply to <div class="a"><x-foo>#shadow<div class="b">
? It may be that's not even needed to be able to use most of the stylesheets in question, which often rely more heavily on classes than child/descendent selectors.
Would this be viable performance-wise?
Related to #864