Skip to content

Commit

Permalink
fix nested block not reactive (sveltejs#4294)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and taylorzane committed Dec 17, 2020
1 parent 4a9ddc7 commit d1849c6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Svelte changelog

## Unreleased

* Fix updating a `<slot>` inside an `{#if}` or other block ([#4292](https://github.com/sveltejs/svelte/issues/4292))

## 3.17.2

* Fix removing attributes during hydration ([#1733](https://github.com/sveltejs/svelte/issues/1733))
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/compile/render_dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ export default class Block {
});

this.has_update_method = true;
if (this.parent) {
this.parent.add_dependencies(dependencies);
}
}

add_element(
Expand Down
2 changes: 2 additions & 0 deletions test/runtime/samples/component-slot-nested-if/Display.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Display:
<slot></slot>
6 changes: 6 additions & 0 deletions test/runtime/samples/component-slot-nested-if/Input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
let val;
</script>

<input bind:value={val} />
<slot {val}></slot>
30 changes: 30 additions & 0 deletions test/runtime/samples/component-slot-nested-if/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default {
html: `
<input>
`,
async test({ assert, target, snapshot, component, window }) {
const input = target.querySelector('input');

input.value = 'a';
await input.dispatchEvent(new window.Event('input'));

assert.htmlEqual(
target.innerHTML,
`
<input>
Display: a
`
);

input.value = 'abc';
await input.dispatchEvent(new window.Event('input'));

assert.htmlEqual(
target.innerHTML,
`
<input>
Display: abc
`
);
},
};
10 changes: 10 additions & 0 deletions test/runtime/samples/component-slot-nested-if/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import Input from "./Input.svelte";
import Display from "./Display.svelte";
</script>

<Input let:val={foo}>
{#if foo}
<Display>{foo}</Display>
{/if}
</Input>

0 comments on commit d1849c6

Please sign in to comment.