fix hydrating each else ()

pull/4257/head
Tan Li Hau 5 years ago committed by Conduitry
parent a422d2aba5
commit 7c3e34c00b

@ -6,6 +6,7 @@
* Expose compiler version in dev events ([#4047](https://github.com/sveltejs/svelte/issues/4047))
* Don't run actions before their element is in the document ([#4166](https://github.com/sveltejs/svelte/issues/4166))
* Fix reactive assignments with destructuring and stores where the destructured value should be undefined ([#4170](https://github.com/sveltejs/svelte/issues/4170))
* Fix hydrating `{:else}` in `{#each}` ([#4202](https://github.com/sveltejs/svelte/issues/4202))
* Do not automatically declare variables in reactive declarations when assigning to a member expression ([#4212](https://github.com/sveltejs/svelte/issues/4212))
## 3.16.7

@ -264,10 +264,23 @@ export default class EachBlockWrapper extends Wrapper {
block.chunks.init.push(b`
if (!${this.vars.data_length}) {
${each_block_else} = ${this.else.block.name}(#ctx);
}
`);
block.chunks.create.push(b`
if (${each_block_else}) {
${each_block_else}.c();
}
`);
if (this.renderer.options.hydratable) {
block.chunks.claim.push(b`
if (${each_block_else}) {
${each_block_else}.l(${parent_nodes});
}
`);
}
block.chunks.mount.push(b`
if (${each_block_else}) {
${each_block_else}.m(${initial_mount_node}, ${initial_anchor_node});

@ -0,0 +1,4 @@
<h1>Hello, world</h1>
<p>
weird
</p>

@ -0,0 +1,4 @@
<h1>Hello, world</h1>
<p>
weird
</p>

@ -0,0 +1,15 @@
<script>
export let name = "world";
export let array = [];
</script>
<h1>Hello, {name}</h1>
{#each array as elem}
<p>
item
</p>
{:else}
<p>
weird
</p>
{/each}
Loading…
Cancel
Save