mirror of https://github.com/sveltejs/svelte
fix: handle duplicate signal dependencies gracefully (#12261)
* fix: further avoid duplicate signal dependencies visitor another approach tune tune * add test * clean up test * early return to reduce indentation, use var over let/const --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/12268/head
parent
ccacfc7955
commit
d2530ed4a1
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: handle duplicate signal dependencies gracefully
|
@ -0,0 +1,37 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
let [btn1, btn2] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => btn1?.click());
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle a</button>
|
||||
<button>toggle b</button>
|
||||
false/true/true
|
||||
`
|
||||
);
|
||||
|
||||
flushSync(() => btn2?.click());
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle a</button>
|
||||
<button>toggle b</button>
|
||||
`
|
||||
);
|
||||
|
||||
flushSync(() => btn2?.click());
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle a</button>
|
||||
<button>toggle b</button>
|
||||
false/true/true
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
let a = $state(true);
|
||||
let b = $state({ c: true });
|
||||
|
||||
const x = $derived(b);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (a = !a)}>toggle a</button>
|
||||
<button onclick={() => (b = b ? null : { c: true })}>toggle b</button>
|
||||
|
||||
{#if x}
|
||||
{a}/{x.c}/{x.c}
|
||||
{/if}
|
Loading…
Reference in new issue