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 {
416416 return ( this . #deferred ??= deferred ( ) ) . promise ;
417417 }
418418
419- static ensure ( ) {
419+ static ensure ( autoflush = true ) {
420420 if ( current_batch === null ) {
421421 const batch = ( current_batch = new Batch ( ) ) ;
422422 batches . add ( current_batch ) ;
423423
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+ }
429430
430- batch . flush ( ) ;
431- } ) ;
431+ batch . flush ( ) ;
432+ } ) ;
433+ }
432434 }
433435
434436 return current_batch ;
@@ -449,7 +451,7 @@ export function flushSync(fn) {
449451
450452 var result ;
451453
452- const batch = Batch . ensure ( ) ;
454+ const batch = Batch . ensure ( false ) ;
453455
454456 if ( fn ) {
455457 batch . flush_effects ( ) ;
You can’t perform that action at this time.
0 commit comments