mirror of https://github.com/sveltejs/svelte
fix: prevent crash on async custom element attributes (#18661)
attributes setter logic wasn't async-aware --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/18668/head
parent
248a2e1db4
commit
9414eaa41b
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: allow custom elements to receive async values as props
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ target, assert }) {
|
||||||
|
await tick();
|
||||||
|
const [element] = target.querySelectorAll('async-custom-element');
|
||||||
|
|
||||||
|
assert.htmlEqual(element.innerHTML, `Hello foobar!`);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
<script>
|
||||||
|
class MyCustomElement extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this._foo = null;
|
||||||
|
this._bar = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} foo
|
||||||
|
*/
|
||||||
|
set foo(foo) {
|
||||||
|
this._foo = foo;
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} foo
|
||||||
|
*/
|
||||||
|
set bar(bar) {
|
||||||
|
this._bar = bar;
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
connectedCallback() {
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
this.innerHTML = "Hello " + this._foo + this._bar + "!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!customElements.get('async-custom-element')) {
|
||||||
|
customElements.define("async-custom-element", MyCustomElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
const foo = $derived(await "foo");
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<async-custom-element {foo} bar={await 'bar'}></async-custom-element>
|
||||||
Loading…
Reference in new issue