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

Support ":host" selector #33

Open
doits opened this issue Feb 5, 2025 · 3 comments
Open

Support ":host" selector #33

doits opened this issue Feb 5, 2025 · 3 comments

Comments

@doits
Copy link

doits commented Feb 5, 2025

The following css works:

:root {
  --some-variable: #f00;
}

But once a :host is added it breaks:

:root, :host {
  --some-variable: #f00;
}

WARNING: Invalid or unsupported selector, ':root,:host'

--some-variable is not available anymore.

Same goes for selectors like html, :host etc..

I think it should simply ignore :host (which has no meaning here because there is no shadow dom afaik) but apply the remaining ones (:root and html in my example).

@liZe
Copy link
Member

liZe commented Feb 6, 2025

Hi, and thanks for the bug report!

:host is not supported (yet!) by WeasyPrint.

I think it should simply ignore :host (which has no meaning here because there is no shadow dom afaik) but apply the remaining ones (:root and html in my example).

This behavior is actually correct and specified, all browsers do the same for selectors they don’t support. You can for example try :root, :unsupported { color: blue } and see that all browsers display black text. So, that’s not a bug in the way we handle selectors, that’s "just" a missing feature.

If you want WeasyPrint to support CSS Scoping (that defines :host), we can move this issue to cssselect2 where it belongs.

@doits
Copy link
Author

doits commented Feb 7, 2025

Thanks for the information! I didn't know this is well defined behaviour, sorry for the noise. This can be closed then.


The background for this issue is that a css genarator (tailwindcss v4) is generating css with :host selectors. It has some other incompatibilities by default, but with some tailwindcss tweaks I can get it to work with the one exception of the :host selector: It outputs selectors like :root, :host { and there isn't an option not to output :host. Right now I simply run a regexp over the generated css (s/, :host {/ {/), which I think I have to continue for the time being.

@doits doits closed this as completed Feb 7, 2025
@liZe
Copy link
Member

liZe commented Feb 7, 2025

The background for this issue is that a css genarator (tailwindcss v4) is generating css with :host selectors. It has some other incompatibilities by default, but with some tailwindcss tweaks I can get it to work with the one exception of the :host selector: It outputs selectors like :root, :host { and there isn't an option not to output :host. Right now I simply run a regexp over the generated css (s/, :host {/ {/), which I think I have to continue for the time being.

Thanks a lot for sharing this information. :host is supported by browsers since 2016~2018, it will probably be used by many other frameworks and we should support it in cssselect2. Let’s move this issue over there.

@liZe liZe reopened this Feb 7, 2025
@liZe liZe changed the title ":host" should not break remaining css selectors Support ":host" selector Feb 7, 2025
@liZe liZe transferred this issue from Kozea/WeasyPrint Feb 7, 2025
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

2 participants