mirror of https://github.com/sveltejs/svelte
fix: do not defer unmount; immediately unmount components (#16624)
* fix: do not defer unmount; immediately unmount components * fix: add changeset * Update .changeset/few-geese-itch.md Co-authored-by: Jeremiasz Major <jrh.mjr@gmail.com> * add test * update changeset --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Jeremiasz Major <jrh.mjr@gmail.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/16633/head
parent
036d4588ab
commit
95e5175581
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: destroy dynamic component instance before creating new one
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
$effect.pre(() => {
|
||||
console.log('create A');
|
||||
return () => console.log('destroy A');
|
||||
});
|
||||
</script>
|
||||
|
||||
<h1>A</h1>
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
$effect.pre(() => {
|
||||
console.log('create B');
|
||||
return () => console.log('destroy B');
|
||||
});
|
||||
</script>
|
||||
|
||||
<h1>B</h1>
|
@ -0,0 +1,13 @@
|
||||
import { test } from '../../test';
|
||||
import { flushSync } from 'svelte';
|
||||
|
||||
export default test({
|
||||
mode: ['client', 'hydrate'],
|
||||
|
||||
async test({ assert, target, logs }) {
|
||||
const [button] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => button.click());
|
||||
assert.deepEqual(logs, ['create A', 'destroy A', 'create B']);
|
||||
}
|
||||
});
|
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
import A from './A.svelte';
|
||||
import B from './B.svelte';
|
||||
|
||||
let condition = $state(true);
|
||||
let Component = $derived(condition ? A : B);
|
||||
</script>
|
||||
|
||||
<button onclick={() => condition = !condition}>
|
||||
toggle ({condition})
|
||||
</button>
|
||||
|
||||
<Component />
|
Loading…
Reference in new issue