File tree Expand file tree Collapse file tree 4 files changed +54
-2
lines changed
src/internal/client/reactivity
tests/runtime-runes/samples/async-settled-after-dom Expand file tree Collapse file tree 4 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' svelte ' : patch
3+ ---
4+
5+ fix: settle batch after DOM updates
Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments