-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
HTML comments break CSS :empty pseudo selector #14299
Comments
Ah this is indeed an implementation leak of the way we construct code (we need anchor comments to properly insert and remove html blocks), and tbh I'm not totally sure if there's something we can do about this. The |
What about |
That option is only about comments the developer put in their components. The internal comments cannot be removed |
Is there an issue for the |
No need, already investigating it |
This is actually a browser implementation bug, I think. Which sounds crazy, because all browsers implement this incorrectly, although the spec changed several years ago. If you remove the whitespace in the fiddle, it works correctly: https://jsfiddle.net/074s1e9h/ If svelte removes all whitespace outside of comments, |
This is actually caused by the whitespace between the EDIT: I mean, in this case that's the problem. It's still the general problem of whitespaces and comments interacting with In this specific instance, it is one case where something like a |
Oh wow you're right, it's has nothing to do with the comments, it's the whitespace - thanks for pointing that out! So yeah, avoiding the whitespace between the if elements fixes this. It's a good question whether or not we should treat whitespace between control flow blocks as signification. We're already treating whitespace between sibiling elements as significant, so from that perspective the behavior is consistent. |
I think it's most (except <div>{''}<!-- put a space before/after comment -->{''}</div>
<style>
div {
width: 10%;
height: 10%;
background-color: red;
}
div:empty {
background-color: green;
}
</style> If you remove one or both of the |
The rule is "whitespace between siblings is preserved (trimmed down to one space), whitespace at the start/end is removed" |
Describe the bug
When using conditionals in Svelte the result leaves empty comments inside the node. Since comments are considered childNodes this breaks the CSS selector
:empty
.We could use
:not(:has(*))
as a workaround but the css output looks like this:That said, I'd prefer not use use
:not(:has(*))
since it's very inefficient.I've also tried setting
preserveComments=false
in my compiler options but it doesn't seems to do anything (in development anyway). Perhaps this has re-emerged as an issue: #4730 ?Reproduction
https://svelte.dev/playground/d1989f455149482ca0d9202e915b743f?version=5.1.16
https://jsfiddle.net/jwerre/pcqt215b/10/
System Info
System: OS: macOS 15.0.1 CPU: (10) arm64 Apple M1 Max Memory: 1.21 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.18.0 - /opt/homebrew/bin/node Yarn: 1.22.22 - ~/.npm-global/bin/yarn npm: 10.8.2 - /opt/homebrew/bin/npm Browsers: Chrome: 130.0.6723.117 Edge: 117.0.2045.40 Safari: 18.0.1
Severity
annoyance
The text was updated successfully, but these errors were encountered: