sveltejs / prettier-plugin-svelte

Format your svelte components using prettier.
MIT License
714 stars 95 forks source link

HTML comment is duplicated on format #400

Closed drzax closed 5 months ago

drzax commented 10 months ago

This looks to be a very similar issue to #205.

The following works as a minimum repro in Svelte for VS Code v107.10.0

<div>
  <!-- this is duplicated on format -->
  <style></style>
</div>

But both of the following work as expected

<div>
  <!-- this is *not* duplicated on format -->
  <p>Hi</p>
</div>
<!-- this is *not* duplicated on format -->
<style></style>

So it appears to be the combination of the <style> tag and nested structure that triggers the bug.

alexlafroscia commented 9 months ago

I'm seeing this as well, but with a comment preceding a <script> tag rather than a <style> tag.

Interestingly, it only happens when that <script> tag exists within a <svelte:head> tag, like so:

<svelte:head>
  <!-- Fathom Analytics -->
  <script
    src="https://xxx.alexlafroscia.com/script.js"
    data-site="xxx"
    data-spa="auto"
    defer
  ></script>
</svelte:head>

The <!-- Fathom Analytics --> line is repeated each time Prettier formats the file