Re: [WICG/webcomponents] Declarative CSS Module Scripts (#939)

Apologies @justinfagnani if I've missed your point, but the example at https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/AtSheet/explainer.md#importing-a-base-set-of-inline-styles-into-a-declarative-shadow-dom seems to demonstrate how to "emit inline styles into HTML as they're encountered while SSR'ing the component tree, and reference them from other use sites.", aside from a [nit about exactly how to reference them](https://github.com/w3c/csswg-drafts/issues/11509#issuecomment-2599841044). Specifically, when the SSR discovers that it's going to need a new style block named 'foo' in a piece of declarative shadow dom, it emits

```html
<style>
@sheet foo {
  div {
    color: red;
  }
}
</style>
<template shadowrootmode="open" adoped-style-sheets="foo">
  <span>I'm in the shadow DOM</span>
</template>
```

(If you need to emit the style _inside_ the DSD, it seems like it would also work to use `<link rel=stylesheet someNewAttribute=foo>`.)

[Open Issue #5](https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/AtSheet/explainer.md#open-issues) is important here: SSR is going to want to be able to do a structure like:

```html
<template shadowrootmode="open">
  <!-- Component 1 stuff ...-->
  <!-- Oh, here comes a component that needs some shared style. -->
  <style>@sheet shared-component-style { ... }</style>
  <template shadowrootmode="open" adopted-style-sheets="foo">
    <!-- Shared component shadow DOM -->
  </template>
</template>
<!-- Here comes another copy of the component that needs shared style. -->
<!-- DON'T re-emit the style -->
<template shadowrootmode="open" adopted-style-sheets="foo inside the above shadow DOM">
  <!-- Shared component shadow DOM -->
</template>
```

That second reference to `foo` needs to be able to navigate to the `@sheet` in shadow DOM. It probably doesn't need to use the exact same syntax, but it needs to be able to name it somehow.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/939#issuecomment-2599848536
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/939/2599848536@github.com>

Received on Saturday, 18 January 2025 19:25:03 UTC