diff --git a/.changeset/dry-eggs-play.md b/.changeset/dry-eggs-play.md new file mode 100644 index 0000000000..962e26fbff --- /dev/null +++ b/.changeset/dry-eggs-play.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: improve text node output diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index 3de77c8303..8c3cb748c4 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -1531,6 +1531,7 @@ function process_children(nodes, parent, { visit, state }) { expression = b.call('$.sibling', text_id); } + let is_fragment = false; for (let i = 0; i < nodes.length; i += 1) { const node = nodes[i]; @@ -1538,7 +1539,12 @@ function process_children(nodes, parent, { visit, state }) { sequence.push(node); } else { if (sequence.length > 0) { - flush_sequence(sequence, true); + flush_sequence(sequence, is_fragment); + // Ensure we move to the next sibling for the case where we move reference within a fragment + if (!is_fragment && sequence.length === 1 && sequence[0].type === 'ExpressionTag') { + expression = b.call('$.sibling', expression); + is_fragment = true; + } sequence = []; } diff --git a/packages/svelte/tests/runtime-runes/samples/each-text-template/_config.js b/packages/svelte/tests/runtime-runes/samples/each-text-template/_config.js new file mode 100644 index 0000000000..439863e4d9 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/each-text-template/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: `

A
B
C

` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/each-text-template/main.svelte b/packages/svelte/tests/runtime-runes/samples/each-text-template/main.svelte new file mode 100644 index 0000000000..5d91831d0e --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/each-text-template/main.svelte @@ -0,0 +1,9 @@ + + +

+{#each array as a} + {a}
+{/each} +