-
-
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 are being stripped from output #6805
Comments
I'm curious what tools you are referring to. Can you give an example? |
Do the comments also get stripped away if you add |
An common example would be Microsoft's conditional comments, but there are also CMS tools that make use of comments. I'm working on a project that needs access to comments in the output HTML. Personally, I think a framework should leave your HTML intact where at all possible. You have to jump through some hoops with React too, which isn't much fun: https://stackoverflow.com/questions/40381851/insert-html-comments-in-react. |
I'll try the setting, @stephane-vanraes. Thanks. |
They probably belong hard coded to the
I'm sill curious for an actual example and why this is a problem with Svelte?
Svelte is a compiler that turns the HTML-like components into JavaScript. Not sure what "output HTML" you are referring to.
Works in Svelte identical: <script>
let name = 'world';
</script>
{@html '<!--Hello-->'}
<h1>Hello {name}!</h1> https://svelte.dev/repl/d6f3f01f53ec4c8bb7b1dd05291e3a16?version=3.43.1
The setting is for SSR only according to the docs. |
Aha, the `{@html ''} syntax looks like a reasonable workaround, thank you. It's a shame that this doesn't happen automatically when the parser encounters an html comment. |
It reduces bundle size and improves performance and virtually nobody needs them. I'm still very curious if you can explain your use-case as I haven't encountered this ever. The last time I had to use comments was with Knockout and it's been a while. |
I can't share my use case just yet as it's not ready for public consumption, but I believe CouchCMS used html comments to annotate documents. Regardless of my personal use case, from a user perspective, a Svelte file looks like HTML — shouldn't it behave like HTML? HTML comments are a core part of writing HTML, so it's jarring as a user when they are stripped from he output. I agree that having an option to strip them from output is useful, but an alternative syntax for those would be preferred, much like how Sass — and soon Atsro — use |
Just realised that the |
That was introduced in #4444 so unless you have a suggested way to handle hydration of |
@Conduitry That makes sense. I would opt for making comments a first class citizen that get parsed, that way hydration could work as expected due to a comment nodes existence. |
I'm interested in adding HTML comments to Svelte output too. My use case is using SvelteKit to statically generate HTML emails.
In my case, the output HTML would be the HTML files added to the build folder with Since some styles are Outlook-specific, it's necessary to nest those styles in comments like this: <!--[if mso]>
<style>
/* Outlook styles go here */
</style>
<![endif]--> (see GitHub's email design system) The {@html '<!--[if mso]>'}
<slot />
{@html '<![endif]-->'} |
I'd like to add that it can be helpful during development to keep comments when using CSS utility libraries (Tailwind, for example), the downside of such libraries is that when looking at complex markup there are no identifying class names. It would be nice to retain comments during development but stripped for production. |
We are also having a tooling integration (work-in-progress) that relies on comments during development (not production). Would be great to preserve comments like in Vue.js (where I came from, Vue.js preserves comments by default during development and not in production). If comments are not preserved, I was wondering what |
In Svelte 5, comments are also preserved when client-side rendering and using the |
Describe the bug
It seems that HTML comments are being stripped from output. This is problematic when using tools that rely on HTML comments as directives.
Reproduction
Logs
No response
System Info
Severity
blocking all usage of svelte
The text was updated successfully, but these errors were encountered: