Svelte: Whitespace inside elements is not being preserved inside loops

Created on 19 Jul 2017  路  6Comments  路  Source: sveltejs/svelte

Most helpful comment

In that gist, if you take out the second paragraph about "^ Those letters should all have a space between them", then spaces do appear between the letters, which is kind of hilarious.

edit: Also, perhaps more helpful for debugging, if you make sure there's no whitespace between the paragraph the each block (so you have {{/each}}<p> or {{/each}}foo<p>), the spaces appear. This seems in line with what's intended, given the comment

    // We want to remove trailing whitespace inside an element/component/block,
    // *unless* there is no whitespace between this node and its next sibling

but I don't know what the goal of this rule is.

All 6 comments

thanks, fixed in 1.26

So, weird thing - it doesn't look like this was actually fixed: https://svelte.technology/repl?version=1.34.0&gist=10dd087fc24ff3dbf326c06b04e0611a

I'm not sure how this is possible, since that test case in #718 seems to match it pretty exactly, but that repl still shows the issue even in 1.26.0.

In that gist, if you take out the second paragraph about "^ Those letters should all have a space between them", then spaces do appear between the letters, which is kind of hilarious.

edit: Also, perhaps more helpful for debugging, if you make sure there's no whitespace between the paragraph the each block (so you have {{/each}}<p> or {{/each}}foo<p>), the spaces appear. This seems in line with what's intended, given the comment

    // We want to remove trailing whitespace inside an element/component/block,
    // *unless* there is no whitespace between this node and its next sibling

but I don't know what the goal of this rule is.

Been taking another look at this, and I'm still confused. I'm not sure what exactly the nextSibling is meant to be in relation to the current Node. In @TehShrike's REPL example above, it's the '\n\n' _after_ the EachBlock. Since the nextSibling exists and is a Text node beginning with whitespace, we strip the whitespace at the end of the <span>. It seems like in this case for the shouldTrim to be correct, nextSibling would have to be null.

v3 repro from #2905:

{#each ['dog', 'hen', 'fox', 'cat', 'pig', 'ant', 'cow', 'koi'] as value}
    <span>{value} </span>
{/each}
<!-- Type or insert anything here to break spacing of list. -->

Fixed in 3.5.4 (finally!!)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juniorsd picture juniorsd  路  3Comments

Rich-Harris picture Rich-Harris  路  3Comments

matt3224 picture matt3224  路  3Comments

1u0n picture 1u0n  路  3Comments

mmjmanders picture mmjmanders  路  3Comments