mirror of https://github.com/sveltejs/svelte
fix: settle batch after DOM updates (#17054)
parent
1b2f7b068e
commit
90a8a03988
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: settle batch after DOM updates
|
||||
@ -0,0 +1,27 @@
|
||||
import { settled, tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client'],
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [shift, update] = target.querySelectorAll('button');
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, '<button>shift</button><button>update</button><p>hello</p>');
|
||||
|
||||
update.click();
|
||||
const promise = settled();
|
||||
|
||||
await tick();
|
||||
shift.click();
|
||||
await promise;
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<button>shift</button><button>update</button><p>goodbye</p>'
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
<script>
|
||||
let text = $state('hello');
|
||||
|
||||
const resolvers = [];
|
||||
|
||||
function push(value) {
|
||||
const { promise, resolve } = Promise.withResolvers();
|
||||
resolvers.push(() => resolve(value));
|
||||
return promise;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={() => resolvers.shift()?.()}>shift</button>
|
||||
<button onclick={() => text = 'goodbye'}>update</button>
|
||||
|
||||
<svelte:boundary>
|
||||
<p>{await push(text)}</p>
|
||||
|
||||
{#snippet pending()}{/snippet}
|
||||
</svelte:boundary>
|
||||
Loading…
Reference in new issue