Skip to content

Commit

Permalink
fix hydrating each else (sveltejs#4253)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and jesseskinner committed Feb 27, 2020
1 parent 14b712c commit 3a5df9c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/compiler/compile/render_dom/wrappers/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
4 changes: 4 additions & 0 deletions test/hydration/samples/each-else/_after.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Hello, world</h1>
<p>
weird
</p>
4 changes: 4 additions & 0 deletions test/hydration/samples/each-else/_before.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Hello, world</h1>
<p>
weird
</p>
15 changes: 15 additions & 0 deletions test/hydration/samples/each-else/main.svelte
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 3a5df9c

Please sign in to comment.