mirror of https://github.com/sveltejs/svelte
parent
e6110d31c5
commit
871e590c59
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: settle discarded batch
|
||||
@ -0,0 +1,37 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, logs }) {
|
||||
await tick();
|
||||
const [increment, pop] = target.querySelectorAll('button');
|
||||
|
||||
increment.click();
|
||||
await tick();
|
||||
increment.click();
|
||||
await tick();
|
||||
pop.click();
|
||||
await tick();
|
||||
assert.deepEqual(logs, ['settled 2', 'settled 2']);
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
2
|
||||
<button>increment</button>
|
||||
<button>pop</button>
|
||||
`
|
||||
);
|
||||
|
||||
pop.click();
|
||||
await tick();
|
||||
assert.deepEqual(logs, ['settled 2', 'settled 2']);
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
2
|
||||
<button>increment</button>
|
||||
<button>pop</button>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
import { settled } from "svelte";
|
||||
|
||||
let count = $state(0);
|
||||
let queued = [];
|
||||
|
||||
function push(v) {
|
||||
if (!v) return v;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
queued.push(() => resolve(v));
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
{await push(count)}
|
||||
<button onclick={async () => {
|
||||
count++;
|
||||
await settled();
|
||||
console.log('settled ' + count);
|
||||
}}>increment</button>
|
||||
<button onclick={() => queued.pop()?.()}>pop</button>
|
||||
Loading…
Reference in new issue