[csswg-drafts] [cssom] Can we lift the same document restriction on adoptedStylesheets? (#11403)

sorvell has just created a new issue for https://github.com/w3c/csswg-drafts:

== [cssom] Can we lift the same document restriction on  adoptedStylesheets? ==
When a element with a `shadowRoot` that has `adoptedStyleSheets` is moved between documents, these styleSheets are removed [per spec](https://drafts.csswg.org/cssom/#extensions-to-the-document-or-shadow-root-interface). This issue is also [referenced here](https://github.com/w3c/csswg-drafts/issues/10013#issuecomment-2169155120).

This is undesirable and requires significant fix-up code to prevent (~0.5KB, [example](https://lit.dev/playground/#gist=5ba46eeb474d335180697b882cb408c9)) and is causing real developer [pain points](https://github.com/lit/lit/issues/4868). If the element is a custom element, the logical place to fix the styling is `adoptedCallback`, but the `adoptedStyleSheets` have been removed by this point so a pre-processed cache of the of the adoptedStyleSheets must be maintained/managed. This is cumbersome, tricky to get right, and significant code to do correctly.

Note, using `<style>` elements in the `shadowRoot` does not trigger this issue.

I believe one concern that led to this restriction was breaking references to relative URLs in the stylesheet; however, [baseUrl](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet#baseurl) is now a constructor option. If this is the only reason they could not be shared, then if `baseURL` is specified, these sheets could be marked document shareable and not removed when the element is adopted to a new document.

This would make cross-document sharing of elements with shadowRoots significantly more feasible.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11403 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Saturday, 21 December 2024 00:32:38 UTC