mirror of https://github.com/sveltejs/svelte
fix: ensure components always return an object (#12290)
Closes #12287 --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/12308/head
parent
831552f4b3
commit
e42bb61296
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure component always returns an object
|
@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
export const a = {};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>a</div>
|
@ -0,0 +1 @@
|
|||||||
|
<div>b</div>
|
@ -0,0 +1,26 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<button>a</button><button>b</button><div>a</div>`,
|
||||||
|
compileOptions: {
|
||||||
|
dev: false
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target, logs, ok }) {
|
||||||
|
const [btn1, btn2] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
btn2.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>a</button><button>b</button><div>b</div>`);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
btn1.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>a</button><button>b</button><div>a</div>`);
|
||||||
|
assert.deepEqual(logs, [{ a: {} }, {}, { a: {} }]);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,24 @@
|
|||||||
|
<script>
|
||||||
|
import ComponentA from './ComponentA.svelte';
|
||||||
|
import ComponentB from './ComponentB.svelte';
|
||||||
|
|
||||||
|
let type = $state(ComponentA);
|
||||||
|
let elem = $state.frozen();
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
console.log(elem);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onclick={() => {
|
||||||
|
type = ComponentA;
|
||||||
|
}}>a</button
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
onclick={() => {
|
||||||
|
type = ComponentB;
|
||||||
|
}}>b</button
|
||||||
|
>
|
||||||
|
|
||||||
|
<svelte:component this={type} bind:this={elem}>Content</svelte:component>
|
Loading…
Reference in new issue