fix: port over props that were set prior to initialization (#9701)

...and then delete the property descriptor that shadows the prototype descriptor
fixes #9487
pull/9719/head
Simon H 7 months ago committed by GitHub
parent d15bc822e0
commit 31d939fefa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: port over props that were set prior to initialization

@ -270,6 +270,13 @@ if (typeof HTMLElement === 'function') {
this.$$d[name] = get_custom_element_value(name, attribute.value, this.$$p_d, 'toProp');
}
}
// Port over props that were set programmatically before ce was initialized
for (const key in this.$$p_d) {
if (!(key in this.$$d) && this[key] !== undefined) {
this.$$d[key] = this[key]; // don't transform, these were set through JavaScript
delete this[key]; // remove the property that shadows the getter/setter
}
}
this.$$c = new this.$$ctor({
target: this.shadowRoot || this,
props: {

@ -0,0 +1,9 @@
<svelte:options
customElement={null}
/>
<script>
export let prop;
</script>
<p>{prop}</p>

@ -0,0 +1,23 @@
import * as assert from 'assert.js';
import { tick } from 'svelte';
import Main from './main.svelte';
export default async function (target) {
target.innerHTML = '<custom-element red white></custom-element>';
const ce = target.querySelector('custom-element');
ce.prop = 1;
customElements.define('custom-element', Main.element);
await tick();
await tick();
const ce_root = target.querySelector('custom-element').shadowRoot;
const p = ce_root.querySelector('p');
assert.equal(p.textContent, '1');
ce.prop = 2;
await tick();
await tick();
assert.equal(p.textContent, '2');
}
Loading…
Cancel
Save