File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
packages/svelte/src/internal/client/reactivity Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: avoid microtask in flushSync
Original file line number Diff line number Diff line change @@ -416,19 +416,21 @@ export class Batch {
416
416
return ( this . #deferred ??= deferred ( ) ) . promise ;
417
417
}
418
418
419
- static ensure ( ) {
419
+ static ensure ( autoflush = true ) {
420
420
if ( current_batch === null ) {
421
421
const batch = ( current_batch = new Batch ( ) ) ;
422
422
batches . add ( current_batch ) ;
423
423
424
- queueMicrotask ( ( ) => {
425
- if ( current_batch !== batch ) {
426
- // a flushSync happened in the meantime
427
- return ;
428
- }
424
+ if ( autoflush ) {
425
+ queueMicrotask ( ( ) => {
426
+ if ( current_batch !== batch ) {
427
+ // a flushSync happened in the meantime
428
+ return ;
429
+ }
429
430
430
- batch . flush ( ) ;
431
- } ) ;
431
+ batch . flush ( ) ;
432
+ } ) ;
433
+ }
432
434
}
433
435
434
436
return current_batch ;
@@ -449,7 +451,7 @@ export function flushSync(fn) {
449
451
450
452
var result ;
451
453
452
- const batch = Batch . ensure ( ) ;
454
+ const batch = Batch . ensure ( false ) ;
453
455
454
456
if ( fn ) {
455
457
batch . flush_effects ( ) ;
You can’t perform that action at this time.
0 commit comments