mirror of https://github.com/sveltejs/svelte
fix: improve handling of unowned derived signal (#11712)
parent
fba6b5676b
commit
09addad9ae
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: improve handling of unowned derived signal
|
@ -0,0 +1,23 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client'],
|
||||
async test({ assert, target, logs }) {
|
||||
let [btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.deepEqual(logs, ['recalculating']);
|
||||
}
|
||||
});
|
@ -0,0 +1,18 @@
|
||||
<script context="module">
|
||||
let visible = $state(true);
|
||||
|
||||
function toggleVisibility() {
|
||||
visible = !visible;
|
||||
}
|
||||
|
||||
let unchangedState = $state("unchanged state");
|
||||
let derived = $derived.by(() => {
|
||||
console.log("recalculating");
|
||||
return unchangedState;
|
||||
});
|
||||
</script>
|
||||
|
||||
<button onclick={toggleVisibility}>Toggle Visibility</button>
|
||||
{#if visible}
|
||||
<p>{derived}</p>
|
||||
{/if}
|
Loading…
Reference in new issue