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

Declarative shadow root adoption #10933

Open
dead-claudia opened this issue Jan 20, 2025 · 0 comments
Open

Declarative shadow root adoption #10933

dead-claudia opened this issue Jan 20, 2025 · 0 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest

Comments

@dead-claudia
Copy link

dead-claudia commented Jan 20, 2025

What problem are you trying to solve?

There's no way for declarative shadow roots to declaratively adopt styles, forcing JS to be used to add them. This partially defeats the point of using declarative shadow DOM at all, since it means some styles' application are unavoidably blocked on scripting.

What solutions exist today?

None, really. You could shim it with this as the first script element, though:

<script defer>
for (let t of document.querySelectorAll("template[shadowrootadopt]")) {
    let adopt = t.getAttribute("shadowrootadopt")
    t.removeAttribute("shadowrootadopt")
    for (let id of adopt.trim().split(/ +/g)) {
        let elem = document.getElementById(id)
        if (elem?.matches("style, link[rel~=stylesheet]") && elem.sheet) {
            t.adoptedStyleSheets.push(elem.sheet)
        }
    }
}
</script>

How would you solve it?

Add a shadowrootadopt="...", a token list of adopted <style> and <link rel="stylesheet"> IDs.

Anything else?

No response

@dead-claudia dead-claudia added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest
Development

No branches or pull requests

1 participant