mirror of https://github.com/sveltejs/svelte
fix: improve signal consumer tracking behavior (#10121)
parent
092370b43f
commit
d16f17c306
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: improve signal consumer tracking behavior
|
@ -0,0 +1,40 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>Add Item</button>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [btn1] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn1.click();
|
||||
btn1.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>Add Item</button><button>Index 0\n|\nItem 0</button><button>Index 1\n|\nItem 1</button>`
|
||||
);
|
||||
|
||||
let [btn2, btn3, btn4] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn4.click();
|
||||
btn3.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>Add Item</button>`);
|
||||
|
||||
let [btn5] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => {
|
||||
btn5.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>Add Item</button><button>Index 0\n|\nItem 2</button>`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,18 @@
|
||||
<script>
|
||||
let arr = $state([]);
|
||||
let counter = 0
|
||||
|
||||
function addItem() {
|
||||
arr.push(`${counter++}`)
|
||||
}
|
||||
|
||||
function removeItem(i) {
|
||||
arr.splice(i, 1)
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={addItem}>Add Item</button>
|
||||
|
||||
{#each arr as item, i}
|
||||
<button onclick={() => removeItem(i)}>Index {i} | Item {item}</button>
|
||||
{/each}
|
Loading…
Reference in new issue