Description
What problem are you trying to solve?
Developers using Declarative Shadow DOM (DSD) do not have a way to share declarative stylesheets without using script. There are many workarounds, but none are ideal.
What solutions exist today?
If a developer wants to share styles between the light DOM and DSD, they can either:
a. Duplicate individual inline style rules between shadow roots. This is problematic because it often leads to lots of duplicated style definitions.
b. Use <link rel>
tags for shared CSS files in each shadow root. This is problematic because external stylesheets are an asynchronous render-blocking resource, and could cause an FOUC.
c. Use the Javascript adoptedStyleSheets
property on the declarative shadow root to share stylesheets. This is problematic because it can cause an FOUC and only works with Javascript enabled.
None of these options are ideal.
How would you solve it?
Declarative CSS Modules allow developers to define style sheets that by default do not apply to the main document, but instead are stored in the global Module Map. An adoptedstylesheets
attribute on the <template>
element will allow developers to opt Declarative Shadow DOM elements into sharing these stylesheets via module syntax.
Proposed syntax:
<script type="css-module" specifier="/foo.css">
#content {
color: red;
}
</script>
<my-element>
<template shadowrootmode="open" adoptedstylesheets="/foo.css">
<!-- ... -->
</template>
</my-element>
The <script>
tag allows for styles to be defined without impacting the main document. The adoptedstylesheets
attribute on the <template>
element will look up the module specifier and associate it with the referenced <style>
block.
Explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/ShadowDOM/explainer.md
Anything else?
No response