Svelte: Incorrect HTML is generated

Created on 21 Sep 2017  Â·  4Comments  Â·  Source: sveltejs/svelte

Hello.

I have HTML:

<div>
    <span><i></i></span>
    <span><i></i></span>
</div>

But Svelte outputs it in the following way:

<div>
    <span><i></i></span>
    <i>
        <span><i></i></span>
    </i>
</div>

I'm using version 1.4.0.

You can see it there: https://svelte.technology/repl?version=1.40.0&gist=5061e03f1ec98ae67e0e7d7a3da4963e

bug

All 4 comments

Wow, that's nuts. This works...

div.innerHTML = "<span><i></i></span>\n\t<span><i></i></span>";

...but this (the code that's being generated) fails:

div.innerHTML = "<span><i/></span>\n\t<span><i/></span>";

I wonder what condition determines whether you can use a self-closing tag versus when you must have an opening and a closing tag.

https://stackoverflow.com/questions/3558119/are-non-void-self-closing-tags-valid-in-html5 It sounds like according to the spec only void elements are allowed to be self-closing. I don't know how that corresponds to this weird behavior exactly, but it would probably be wise to only output self-closing elements for things we know are void elements - or actually to just output the lone tag e.g. <input> instead of <input/> to save a character.

@Conduitry your branch working for me very well.

Released 1.40.1 with the fix — thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clitetailor picture clitetailor  Â·  3Comments

davidcallanan picture davidcallanan  Â·  3Comments

lnryan picture lnryan  Â·  3Comments

matt3224 picture matt3224  Â·  3Comments

1u0n picture 1u0n  Â·  3Comments