mirror of https://github.com/sveltejs/svelte
fix: improve behaviour of unowned derived signals (#11521)
parent
70419daf5f
commit
30caaef2e5
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: improve behaviour of unowned derived signals
|
@ -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 C', 'computing B', 'a', 'foo', 'computing B', 'aaa', 'foo']);
|
||||
}
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
function run(){
|
||||
let a = $state('a');
|
||||
let b = $derived.by(() => {
|
||||
console.log('computing B', a);
|
||||
return 'foo';
|
||||
});
|
||||
let c = $derived.by(() => {
|
||||
console.log('computing C');
|
||||
return b;
|
||||
});
|
||||
|
||||
console.log(c);
|
||||
a = "aaa";
|
||||
console.log(c);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={run}>RUN THE THING</button>
|
Loading…
Reference in new issue