File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
packages/svelte/src/internal/client/reactivity Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ let queued_root_effects = [];
5959let last_scheduled_effect = null ;
6060
6161let is_flushing = false ;
62+ let in_flush_sync = false ;
6263
6364export class Batch {
6465 /**
@@ -421,14 +422,16 @@ export class Batch {
421422 const batch = ( current_batch = new Batch ( ) ) ;
422423 batches . add ( current_batch ) ;
423424
424- queueMicrotask ( ( ) => {
425- if ( current_batch !== batch ) {
426- // a flushSync happened in the meantime
427- return ;
428- }
425+ if ( ! in_flush_sync ) {
426+ queueMicrotask ( ( ) => {
427+ if ( current_batch !== batch ) {
428+ // a flushSync happened in the meantime
429+ return ;
430+ }
429431
430- batch . flush ( ) ;
431- } ) ;
432+ batch . flush ( ) ;
433+ } ) ;
434+ }
432435 }
433436
434437 return current_batch ;
@@ -443,6 +446,8 @@ export class Batch {
443446 * @returns {T }
444447 */
445448export function flushSync ( fn ) {
449+ in_flush_sync = true ;
450+
446451 if ( async_mode_flag && active_effect !== null ) {
447452 e . flush_sync_in_effect ( ) ;
448453 }
@@ -473,6 +478,8 @@ export function flushSync(fn) {
473478 dev_effect_stack = [ ] ;
474479 }
475480
481+ in_flush_sync = false ;
482+
476483 return /** @type {T } */ ( result ) ;
477484 }
478485
You can’t perform that action at this time.
0 commit comments