Skip to content

shadowrootadoptedstylesheets on <template>#12339

Open
KurtCattiSchmidt wants to merge 6 commits intowhatwg:mainfrom
KurtCattiSchmidt:sas-fetch
Open

shadowrootadoptedstylesheets on <template>#12339
KurtCattiSchmidt wants to merge 6 commits intowhatwg:mainfrom
KurtCattiSchmidt:sas-fetch

Conversation

@KurtCattiSchmidt
Copy link
Copy Markdown
Contributor

@KurtCattiSchmidt KurtCattiSchmidt commented Apr 6, 2026

  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • Corresponding HTML AAM & ARIA in HTML issues & PRs:
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)


/indices.html ( diff )
/infrastructure.html ( diff )
/parsing.html ( diff )
/scripting.html ( diff )
/webappapis.html ( diff )

@KurtCattiSchmidt KurtCattiSchmidt added the agenda+ To be discussed at a triage meeting label Apr 8, 2026
@noamr
Copy link
Copy Markdown
Collaborator

noamr commented Apr 16, 2026

From an initial look this seems to be on the right track. I need to spend some time on the details though.
cc @emilio

@keithamus
Copy link
Copy Markdown
Member

Right now all of the shadowroot* properties map to attachShadow({}) properties. Do we want to add adoptedStyleSheets to ShadowRootInit?

@noamr
Copy link
Copy Markdown
Collaborator

noamr commented Apr 16, 2026

Right now all of the shadowroot* properties map to attachShadow({}) properties. Do we want to add adoptedStyleSheets to ShadowRootInit?

Note that the current properties of ShadowRootInit become read only on the ShadowRoot, unlike adoptedStylesheets whch is a mutable array-like thing.

So I think it might be nice to include it in the init dictionary but I could also see why it's not necessary.

@KurtCattiSchmidt
Copy link
Copy Markdown
Contributor Author

Right now all of the shadowroot* properties map to attachShadow({}) properties. Do we want to add adoptedStyleSheets to ShadowRootInit?

Agreed with @noamr's response here - since there's already an adoptedStyleSheets property on the imperative version that references a mutable array, we don't need to add it again to ShadowRootInit.

Think of shadowrootadoptedstylesheets as a purely declarative thing, since it's lacking in the declarative version but present in the imperative version.

Copy link
Copy Markdown
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, might be me misunderstanding CSS modules, but I'd figure I'd ask...

Comment thread source
&lt;/template>
&lt;/div>
&lt;div id="host_shadowrootadoptedstylesheets_attribute">
&lt;template shadowrootmode="open" shadowrootadoptedstylesheets="foo">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how is this example guaranteed to work? The modulemap uses fetch, right? And that's asynchronous per spec. What guarantees that the data: uri is available by the time the adoption happens?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I read, the modulemap marks the module as "fetching", adopts an empty stylesheet, and calls the equivalent of replaceSync on the adopted empty stylesheet when the stylesheet response arrives.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so there is a (very unlikely) chance of FOUC, but no chance of it not working right? Makes sense, might be worth a note?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note to the example, thanks for looking @emilio!

<p class="note">Note that these two examples are functionally equivalent, but the example with
  <span data-x="attr-template-shadowrootadoptedstylesheets">shadowrootadoptedstylesheets</span>
  might initially render without styles applied.</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agenda+ To be discussed at a triage meeting

Development

Successfully merging this pull request may close these issues.

4 participants