mirror of https://github.com/sveltejs/svelte
fix: ensure local prop value is read during teardown (#13611)
* fix: ensure local prop value is read during teardown * add test * cleanup * less overheadpull/13603/head
parent
829be3d611
commit
68a2263415
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure local prop value is read during teardown
|
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
let { x } = $props();
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
console.log('init')
|
||||||
|
|
||||||
|
x = () => {
|
||||||
|
console.log('teardown')
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
x();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
@ -0,0 +1,19 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, logs, target }) {
|
||||||
|
const [btn1] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
btn1?.click();
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
btn1?.click();
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
btn1?.click();
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.deepEqual(logs, ['init', 'teardown', 'init', 'teardown']);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
import Component from "./Component.svelte";
|
||||||
|
|
||||||
|
let toggle = $state(true);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => toggle = !toggle}>toggle</button>
|
||||||
|
|
||||||
|
{#if toggle}
|
||||||
|
<Component />
|
||||||
|
{/if}
|
||||||
|
|
Loading…
Reference in new issue