Skip to content

Commit 6a9e1d5

Browse files
authored
Merge pull request #704 from sveltejs/gh-700
use anchor comments to preserve order in keyed each blocks with components
2 parents b2dd6e3 + 007aee1 commit 6a9e1d5

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/generators/dom/visitors/EachBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function keyed(
163163
block.addVariable(head);
164164
block.addVariable(last);
165165

166-
if (node.children[0] && node.children[0].type === 'Element') {
166+
if (node.children[0] && node.children[0].type === 'Element' && !generator.components.has(node.children[0].name)) {
167167
// TODO or text/tag/raw
168168
node._block.first = node.children[0]._state.parentNode; // TODO this is highly confusing
169169
} else {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>{{title}}</p>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default {
2+
data: {
3+
titles: [{ name: 'b' }, { name: 'c' }]
4+
},
5+
6+
html: `
7+
<p>b</p>
8+
<p>c</p>
9+
`,
10+
11+
test (assert, component, target) {
12+
component.set({
13+
titles: [{ name: 'a' }, { name: 'b' }, { name: 'c' }]
14+
});
15+
16+
assert.htmlEqual(target.innerHTML, `
17+
<p>a</p>
18+
<p>b</p>
19+
<p>c</p>
20+
`);
21+
22+
component.destroy();
23+
}
24+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{#each titles as title @name}}
2+
<Nested title="{{title.name}}"/>
3+
{{/each}}
4+
5+
<script>
6+
import Nested from './Nested.html';
7+
8+
export default {
9+
components: {
10+
Nested
11+
}
12+
};
13+
</script>

0 commit comments

Comments
 (0)