From c2a8e3688f8b5b908d234dbb1758ba8f6ac1e464 Mon Sep 17 00:00:00 2001 From: AlbertLucianto Date: Mon, 4 Nov 2019 21:51:02 +0800 Subject: [PATCH] fix trying to update unmounted input --- src/compiler/compile/render_dom/wrappers/Element/Binding.ts | 1 + test/js/samples/capture-inject-dev-only/expected.js | 2 +- test/js/samples/component-static-var/expected.js | 2 +- test/js/samples/input-no-initial-value/expected.js | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts index 90727743fa..e9c06f8ca8 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts @@ -97,6 +97,7 @@ export default class BindingWrapper { const type = parent.node.get_static_attribute_value('type'); if (type === null || type === "" || type === "text" || type === "email" || type === "password") { + update_conditions.push(parent.var); update_conditions.push(x`(${parent.var}.${this.node.name} !== ${this.snippet})`); } } diff --git a/test/js/samples/capture-inject-dev-only/expected.js b/test/js/samples/capture-inject-dev-only/expected.js index 66e5b75fa3..2f7adf5cb5 100644 --- a/test/js/samples/capture-inject-dev-only/expected.js +++ b/test/js/samples/capture-inject-dev-only/expected.js @@ -39,7 +39,7 @@ function create_fragment(ctx) { p(changed, ctx) { if (changed.foo) set_data(t0, ctx.foo); - if (changed.foo && input.value !== ctx.foo) { + if (changed.foo && input && input.value !== ctx.foo) { set_input_value(input, ctx.foo); } }, diff --git a/test/js/samples/component-static-var/expected.js b/test/js/samples/component-static-var/expected.js index e1372a7b6d..a7158324cc 100644 --- a/test/js/samples/component-static-var/expected.js +++ b/test/js/samples/component-static-var/expected.js @@ -49,7 +49,7 @@ function create_fragment(ctx) { if (changed.z) bar_changes.x = ctx.z; bar.$set(bar_changes); - if (changed.z && input.value !== ctx.z) { + if (changed.z && input && input.value !== ctx.z) { set_input_value(input, ctx.z); } }, diff --git a/test/js/samples/input-no-initial-value/expected.js b/test/js/samples/input-no-initial-value/expected.js index f3067156b5..57cc42b474 100644 --- a/test/js/samples/input-no-initial-value/expected.js +++ b/test/js/samples/input-no-initial-value/expected.js @@ -44,7 +44,7 @@ function create_fragment(ctx) { append(form, button); }, p(changed, ctx) { - if (changed.test && input.value !== ctx.test) { + if (changed.test && input && input.value !== ctx.test) { set_input_value(input, ctx.test); } },