File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
packages/svelte/src/internal/client Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ export class Boundary {
148148 // need to use hydration boundary comments to report whether
149149 // the pending or main block was rendered for a given
150150 // boundary, and hydrate accordingly
151- queueMicrotask ( ( ) => {
151+ Batch . enqueue ( ( ) => {
152152 this . #main_effect = this . #run( ( ) => {
153153 Batch . ensure ( ) ;
154154 return branch ( ( ) => this . #children( this . #anchor) ) ;
Original file line number Diff line number Diff line change @@ -49,6 +49,19 @@ export let batch_deriveds = null;
4949/** @type {Set<() => void> } */
5050export let effect_pending_updates = new Set ( ) ;
5151
52+ /** @type {Array<() => void> } */
53+ let tasks = [ ] ;
54+
55+ function dequeue ( ) {
56+ const task = /** @type {() => void } */ ( tasks . shift ( ) ) ;
57+
58+ if ( tasks . length > 0 ) {
59+ queueMicrotask ( dequeue ) ;
60+ }
61+
62+ task ( ) ;
63+ }
64+
5265/** @type {Effect[] } */
5366let queued_root_effects = [ ] ;
5467
@@ -438,7 +451,7 @@ export class Batch {
438451 batches . add ( current_batch ) ;
439452
440453 if ( autoflush ) {
441- queueMicrotask ( ( ) => {
454+ Batch . enqueue ( ( ) => {
442455 if ( current_batch !== batch ) {
443456 // a flushSync happened in the meantime
444457 return ;
@@ -451,6 +464,15 @@ export class Batch {
451464
452465 return current_batch ;
453466 }
467+
468+ /** @param {() => void } task */
469+ static enqueue ( task ) {
470+ if ( tasks . length === 0 ) {
471+ queueMicrotask ( dequeue ) ;
472+ }
473+
474+ tasks . unshift ( task ) ;
475+ }
454476}
455477
456478/**
You can’t perform that action at this time.
0 commit comments