Skip to content

Commit 94aab90

Browse files
authored
fix: improve text node output (#10081)
* fix: improve text node output * revert
1 parent e9b0908 commit 94aab90

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

.changeset/dry-eggs-play.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: improve text node output

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,14 +1531,20 @@ function process_children(nodes, parent, { visit, state }) {
15311531
expression = b.call('$.sibling', text_id);
15321532
}
15331533

1534+
let is_fragment = false;
15341535
for (let i = 0; i < nodes.length; i += 1) {
15351536
const node = nodes[i];
15361537

15371538
if (node.type === 'Text' || node.type === 'ExpressionTag') {
15381539
sequence.push(node);
15391540
} else {
15401541
if (sequence.length > 0) {
1541-
flush_sequence(sequence, true);
1542+
flush_sequence(sequence, is_fragment);
1543+
// Ensure we move to the next sibling for the case where we move reference within a fragment
1544+
if (!is_fragment && sequence.length === 1 && sequence[0].type === 'ExpressionTag') {
1545+
expression = b.call('$.sibling', expression);
1546+
is_fragment = true;
1547+
}
15421548
sequence = [];
15431549
}
15441550

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<p>A<br>B<br>C<br></p>`
5+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let array = $state(['A', 'B', 'C']);
3+
</script>
4+
5+
<p>
6+
{#each array as a}
7+
{a}<br/>
8+
{/each}
9+
</p>

0 commit comments

Comments
 (0)