fix: preserve property case for custom elements

Fixes #5184
pull/5193/head
Soc Sieng 5 years ago
parent fb8bab8164
commit 8eccbfd96d
No known key found for this signature in database
GPG Key ID: 71C4555515898962

@ -82,10 +82,12 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
const element = this.parent; const element = this.parent;
const { name, property_name, should_cache, is_indirectly_bound_value } = this; const { name, property_name, should_cache, is_indirectly_bound_value } = this;
const is_custom_element = /-/.test(element.node.name);
// xlink is a special case... we could maybe extend this to generic // xlink is a special case... we could maybe extend this to generic
// namespaced attributes but I'm not sure that's applicable in // namespaced attributes but I'm not sure that's applicable in
// HTML5? // HTML5?
const method = /-/.test(element.node.name) const method = is_custom_element
? '@set_custom_element_data' ? '@set_custom_element_data'
: name.slice(0, 6) === 'xlink:' : name.slice(0, 6) === 'xlink:'
? '@xlink_attr' ? '@xlink_attr'
@ -130,10 +132,12 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
? b`@prop_dev(${element.var}, "${property_name}", ${should_cache ? this.last : value});` ? b`@prop_dev(${element.var}, "${property_name}", ${should_cache ? this.last : value});`
: b`${element.var}.${property_name} = ${should_cache ? this.last : value};`; : b`${element.var}.${property_name} = ${should_cache ? this.last : value};`;
} else { } else {
// use this.node.name when the element is a custom element to preserve property case-sensitivity
const custom_element_aware_name = is_custom_element ? this.node.name : name;
block.chunks.hydrate.push( block.chunks.hydrate.push(
b`${method}(${element.var}, "${name}", ${init});` b`${method}(${element.var}, "${custom_element_aware_name}", ${init});`
); );
updater = b`${method}(${element.var}, "${name}", ${should_cache ? this.last : value});`; updater = b`${method}(${element.var}, "${custom_element_aware_name}", ${should_cache ? this.last : value});`;
} }
if (is_indirectly_bound_value) { if (is_indirectly_bound_value) {

@ -6,4 +6,4 @@
export let items = ['a', 'b', 'c']; export let items = ['a', 'b', 'c'];
</script> </script>
<my-widget class="foo" {items}/> <my-widget class="foo" widgetItems={items}/>

@ -1,8 +1,8 @@
<svelte:options tag="my-widget"/> <svelte:options tag="my-widget"/>
<script> <script>
export let items = []; export let widgetItems = [];
</script> </script>
<p>{items.length} items</p> <p>{widgetItems.length} items</p>
<p>{items.join(', ')}</p> <p>{widgetItems.join(', ')}</p>

Loading…
Cancel
Save