Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cssom] Can we lift the same document restriction on adoptedStylesheets? #11403

Open
sorvell opened this issue Dec 21, 2024 · 0 comments
Open

Comments

@sorvell
Copy link

sorvell commented Dec 21, 2024

When a element with a shadowRoot that has adoptedStyleSheets is moved between documents, these styleSheets are removed per spec. This issue is also referenced here.

This is undesirable and requires significant fix-up code to prevent (~0.5KB, example) and is causing real developer pain points. 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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant