From eb5e6bb7aed6719b4d0b928bee0ae8a13cfa34df Mon Sep 17 00:00:00 2001 From: Nico Beierle Date: Tue, 19 Jul 2022 11:00:00 +0200 Subject: [PATCH] fix undefined value when remount keyed input element with spread props --- .../compile/render_dom/wrappers/Element/index.ts | 4 +++- .../spread-element-input-each-block-keyed/_config.js | 11 +++++++++++ .../spread-element-input-each-block-keyed/main.svelte | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/spread-element-input-each-block-keyed/_config.js create mode 100644 test/runtime/samples/spread-element-input-each-block-keyed/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index eed7c6f4ee..459435bb75 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -832,7 +832,9 @@ export default class ElementWrapper extends Wrapper { const type = this.node.get_static_attribute_value('type'); if (type === null || type === '' || type === 'text' || type === 'email' || type === 'password') { block.chunks.mount.push(b` - ${this.var}.value = ${data}.value; + if ('value' in ${data}) { + ${this.var}.value = ${data}.value; + } `); block.chunks.update.push(b` if ('value' in ${data}) { diff --git a/test/runtime/samples/spread-element-input-each-block-keyed/_config.js b/test/runtime/samples/spread-element-input-each-block-keyed/_config.js new file mode 100644 index 0000000000..2f38ddc384 --- /dev/null +++ b/test/runtime/samples/spread-element-input-each-block-keyed/_config.js @@ -0,0 +1,11 @@ +export default { + test({ assert, component, target }) { + const [input1, input2] = target.querySelectorAll('input'); + assert.equal(input1.value, 'value1'); + assert.equal(input2.value, 'value2'); + + component.items = component.items.reverse(); + assert.equal(input1.value, 'value1'); + assert.equal(input2.value, 'value2'); + } +}; diff --git a/test/runtime/samples/spread-element-input-each-block-keyed/main.svelte b/test/runtime/samples/spread-element-input-each-block-keyed/main.svelte new file mode 100644 index 0000000000..b89a400495 --- /dev/null +++ b/test/runtime/samples/spread-element-input-each-block-keyed/main.svelte @@ -0,0 +1,7 @@ + + +{#each items as item (item)} + +{/each}