- From: Keith Cirkel <notifications@github.com>
- Date: Fri, 31 Jan 2025 09:09:07 -0800
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/1041/2627829440@github.com>
I'm not sure the use cases warrant a sophisticated observer object like `StyleSheetObserver`, so one way we could solve this is to dispatch an event on the `document` or `shadowroot` whenever `adoptedStyleSheets` or `stylesheets` is changed. So for example:
```js
document.addEventListener('stylesheetschanged', e => {
console.log(document.styleSheets);
});
document.addEventListener('adoptedstylesheetschanged', e => {
console.log(document.adoptedStyleSheets);
});
document.querySelector('my-element').shadowRoot.addEventListener('stylesheetschanged', e => {
console.log(e.target.styleSheets);
});
document.querySelector('my-element').shadowRootaddEventListener('adoptedstylesheetschanged', e => {
console.log(e.target.adoptedStyleSheets);
});
```
There are some tricky timing bits here though:
- We'd probably need to _queue an event_ for this, which means it would be Task timings (think `setTimeout(..., 0)`. This would be a longer timing than a supposed `StylesheetObserver` which would probably borrow mutation timing.
- `adoptedStyleSheets` wouldn't need to use a queued task but having different timing to `styleSheets` would be weird.
--
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1041#issuecomment-2627829440
You are receiving this because you are subscribed to this thread.
Message ID: <WICG/webcomponents/issues/1041/2627829440@github.com>
Received on Friday, 31 January 2025 17:09:11 UTC