Skip to content

Commit 3a5df9c

Browse files
tanhauhaujesseskinner
authored andcommitted
fix hydrating each else (sveltejs#4253)
1 parent 14b712c commit 3a5df9c

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Expose compiler version in dev events ([#4047](https://github.com/sveltejs/svelte/issues/4047))
77
* Don't run actions before their element is in the document ([#4166](https://github.com/sveltejs/svelte/issues/4166))
88
* Fix reactive assignments with destructuring and stores where the destructured value should be undefined ([#4170](https://github.com/sveltejs/svelte/issues/4170))
9+
* Fix hydrating `{:else}` in `{#each}` ([#4202](https://github.com/sveltejs/svelte/issues/4202))
910
* Do not automatically declare variables in reactive declarations when assigning to a member expression ([#4212](https://github.com/sveltejs/svelte/issues/4212))
1011

1112
## 3.16.7

src/compiler/compile/render_dom/wrappers/EachBlock.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,23 @@ export default class EachBlockWrapper extends Wrapper {
264264
block.chunks.init.push(b`
265265
if (!${this.vars.data_length}) {
266266
${each_block_else} = ${this.else.block.name}(#ctx);
267+
}
268+
`);
269+
270+
block.chunks.create.push(b`
271+
if (${each_block_else}) {
267272
${each_block_else}.c();
268273
}
269274
`);
270275

276+
if (this.renderer.options.hydratable) {
277+
block.chunks.claim.push(b`
278+
if (${each_block_else}) {
279+
${each_block_else}.l(${parent_nodes});
280+
}
281+
`);
282+
}
283+
271284
block.chunks.mount.push(b`
272285
if (${each_block_else}) {
273286
${each_block_else}.m(${initial_mount_node}, ${initial_anchor_node});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1>Hello, world</h1>
2+
<p>
3+
weird
4+
</p>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1>Hello, world</h1>
2+
<p>
3+
weird
4+
</p>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script>
2+
export let name = "world";
3+
export let array = [];
4+
</script>
5+
6+
<h1>Hello, {name}</h1>
7+
{#each array as elem}
8+
<p>
9+
item
10+
</p>
11+
{:else}
12+
<p>
13+
weird
14+
</p>
15+
{/each}

0 commit comments

Comments
 (0)