Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nested block not reactive #4294

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>