mirror of https://github.com/sveltejs/svelte
fix: improve unowned derived signal behaviour (#11408)
parent
4d051962f3
commit
0f4f3d7df0
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: improve unowned derived signal behaviour
|
@ -0,0 +1,14 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, logs }) {
|
||||
let [btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.deepEqual(logs, ['computing', 'a', 'a', 'computing', 'bb', 'bb']);
|
||||
}
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
<script>
|
||||
function run(){
|
||||
let cond = $state(true);
|
||||
let a = $state("a");
|
||||
let b = $state("b");
|
||||
let c = $derived.by(() => {
|
||||
console.log('computing')
|
||||
return cond ? a : b
|
||||
});
|
||||
|
||||
console.log(c);
|
||||
b = "bb";
|
||||
console.log(c)
|
||||
cond = false;
|
||||
console.log(c)
|
||||
a = "aaa";
|
||||
console.log(c)
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={run}>RUN THE THING</button>
|
Loading…
Reference in new issue