Re: [WICG/webcomponents] [Proposal] Stylesheet Observer (Issue #1041)

Would it make sense to observe a `StyleSheetList` instead of a node (`Document` or `ShadowRoot`)?

```js
const observer = new StyleSheetObserver();
observer.observe(document.styleSheets);
observer.observe(document.adoptedStyleSheets);
observer.observe(shadowRoot.adoptedStyleSheets);
```

---

A related point that I [mentioned](https://github.com/w3c/csswg-drafts/issues/10013#issuecomment-2002269431) in https://github.com/w3c/csswg-drafts/issues/10013, but is also worth repeating here. One of the main use-cases for observing stylesheets is to keep stylesheets synced between `document` and a `shadowRoot`. From an author perspective, it would nice if we could just do this:

```js
shadowRoot.adoptedStyleSheets.push(document.styleSheets);
```

Since `document.styleSheets` is a stable `StyleSheetList` reference, the browser could internally observe changes to it and automatically keep it in sync, without requiring authors to wire up the logic manually.

For other, more advanced cases, `StyleSheetObserver` could still be useful.

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

Message ID: <WICG/webcomponents/issues/1041/2383978380@github.com>

Received on Monday, 30 September 2024 19:21:12 UTC