-
Notifications
You must be signed in to change notification settings - Fork 299
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
Should there be a declarative version of adoptedStyleSheets? #910
Comments
why wouldn't a |
That (or an enclosed The downsides of this approach, which this issue tries to tackle, are:
|
To take a step back, is the problem reusing a style sheet across distinct shadow trees or is the problem reusing a shadow tree? The latter is the concern I heard @fantasai raise during the meeting. |
Both of these concerns were raised at the meeting, but this issue is about the former: re-using styles. The latter, re-using shadow trees, is (much!) better solved by Template Instantiation, in my opinion. Declarative Shadow DOM is just like the rest of HTML - if you want two identical chunks of DOM, copy/paste the HTML for them. Or use templates (or template instantiation) to stamp out copies of HTML. |
Aren't |
Note that @justinfagnani proposed something for this a while back here: WICG/webcomponents#939 |
@mfreed7 I was reading through your comment above and I'm not sure I understand how this meaningfully differs from a I understand that this (1) helps avoid duplication of |
Here’s an idea for what this might look like. Inline CSS module: <style type="module">
p { color: hotpink; }
</style> External CSS module: <style type="module" src="external.css"></style> By default it should be adopted by the document (into But if these CSS modules are included inside declarative shadow DOM, then they would be automatically adopted by the shadow root. And then ideally there’s a declarative way to instantiate templates, which could be reused to also share CSS modules across shadow-roots (and with the document too). Hypothetical HTML module syntax<template type="module" id="foo">
<style type="module" src="external.css"></style>
<slot></slot>
</template> <my-component>
<template shadowrootmode="open" from="foo"></template>
<p>Hello</p>
</my-component> If declarative shadow DOM requires repetition, then it's probably fine for declarative adopted stylesheets to also do the same. A proper solution for template reuse can solve repetition of HTML/CSS together in the future and independently of this particular issue. Edit: |
Helping to close the circle: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/ShadowDOM/explainer.md cc: @dandclark |
I ran into a performance issue today where I have 100 cards in a grid, and each card mounts a webcomponent with shadow containing a |
Once declarative Shadow DOM is a thing, it would be very nice to be able to declaratively specify a (shared)
adoptedStyleSheets
value, by reference. This would avoid the need to repeat<style>
or<link>
tags for each declarative Shadow Root.It would seem that several things are needed here:
<style>
tag with an id.What other ideas are there for how to add
adoptedStyleSheets
support to declarative Shadow DOM?The text was updated successfully, but these errors were encountered: