From e4daaccd06cfe8fe1f4885fcb10942132153b521 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Wed, 22 Jan 2020 19:32:24 +0800 Subject: [PATCH] fix nested block not reactive (#4294) --- CHANGELOG.md | 4 +++ src/compiler/compile/render_dom/Block.ts | 3 ++ .../component-slot-nested-if/Display.svelte | 2 ++ .../component-slot-nested-if/Input.svelte | 6 ++++ .../component-slot-nested-if/_config.js | 30 +++++++++++++++++++ .../component-slot-nested-if/main.svelte | 10 +++++++ 6 files changed, 55 insertions(+) create mode 100644 test/runtime/samples/component-slot-nested-if/Display.svelte create mode 100644 test/runtime/samples/component-slot-nested-if/Input.svelte create mode 100644 test/runtime/samples/component-slot-nested-if/_config.js create mode 100644 test/runtime/samples/component-slot-nested-if/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e61719d0..60153dcaba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## Unreleased + +* Fix updating a `` 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)) diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index 68d28024fe..62bdc5bdd9 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -160,6 +160,9 @@ export default class Block { }); this.has_update_method = true; + if (this.parent) { + this.parent.add_dependencies(dependencies); + } } add_element( diff --git a/test/runtime/samples/component-slot-nested-if/Display.svelte b/test/runtime/samples/component-slot-nested-if/Display.svelte new file mode 100644 index 0000000000..d9034e4be2 --- /dev/null +++ b/test/runtime/samples/component-slot-nested-if/Display.svelte @@ -0,0 +1,2 @@ +Display: + \ No newline at end of file diff --git a/test/runtime/samples/component-slot-nested-if/Input.svelte b/test/runtime/samples/component-slot-nested-if/Input.svelte new file mode 100644 index 0000000000..fd8f22db00 --- /dev/null +++ b/test/runtime/samples/component-slot-nested-if/Input.svelte @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/test/runtime/samples/component-slot-nested-if/_config.js b/test/runtime/samples/component-slot-nested-if/_config.js new file mode 100644 index 0000000000..89dfd006cc --- /dev/null +++ b/test/runtime/samples/component-slot-nested-if/_config.js @@ -0,0 +1,30 @@ +export default { + html: ` + + `, + 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, + ` + + Display: a + ` + ); + + input.value = 'abc'; + await input.dispatchEvent(new window.Event('input')); + + assert.htmlEqual( + target.innerHTML, + ` + + Display: abc + ` + ); + }, +}; diff --git a/test/runtime/samples/component-slot-nested-if/main.svelte b/test/runtime/samples/component-slot-nested-if/main.svelte new file mode 100644 index 0000000000..727927b157 --- /dev/null +++ b/test/runtime/samples/component-slot-nested-if/main.svelte @@ -0,0 +1,10 @@ + + + + {#if foo} + {foo} + {/if} +