Skip to content

Commit 808fd28

Browse files
committed
fix: settle batch after DOM updates
1 parent 1b2f7b0 commit 808fd28

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

.changeset/loud-chairs-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: settle batch after DOM updates

packages/svelte/src/internal/client/reactivity/batch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ export class Batch {
196196
flush_queued_effects(target.effects);
197197

198198
previous_batch = null;
199+
200+
this.#deferred?.resolve();
199201
}
200202

201203
batch_values = null;
@@ -432,8 +434,6 @@ export class Batch {
432434

433435
this.committed = true;
434436
batches.delete(this);
435-
436-
this.#deferred?.resolve();
437437
}
438438

439439
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { settled, tick } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
mode: ['client'],
6+
7+
async test({ assert, target }) {
8+
const [shift, update] = target.querySelectorAll('button');
9+
10+
shift.click();
11+
await tick();
12+
13+
assert.htmlEqual(target.innerHTML, '<button>shift</button><button>update</button><p>hello</p>');
14+
15+
update.click();
16+
const promise = settled();
17+
18+
await tick();
19+
shift.click();
20+
await promise;
21+
22+
assert.htmlEqual(
23+
target.innerHTML,
24+
'<button>shift</button><button>update</button><p>goodbye</p>'
25+
);
26+
}
27+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script>
2+
let text = $state('hello');
3+
4+
const resolvers = [];
5+
6+
function push(value) {
7+
const { promise, resolve } = Promise.withResolvers();
8+
resolvers.push(() => resolve(value));
9+
return promise;
10+
}
11+
</script>
12+
13+
<button onclick={() => resolvers.shift()?.()}>shift</button>
14+
<button onclick={() => text = 'goodbye'}>update</button>
15+
16+
<svelte:boundary>
17+
<p>{await push(text)}</p>
18+
19+
{#snippet pending()}{/snippet}
20+
</svelte:boundary>

0 commit comments

Comments
 (0)