File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed
packages/svelte/src/internal/client Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: prevent batches from getting intertwined
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ export class Boundary {
148
148
// need to use hydration boundary comments to report whether
149
149
// the pending or main block was rendered for a given
150
150
// boundary, and hydrate accordingly
151
- queueMicrotask ( ( ) => {
151
+ Batch . enqueue ( ( ) => {
152
152
this . #main_effect = this . #run( ( ) => {
153
153
Batch . ensure ( ) ;
154
154
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;
49
49
/** @type {Set<() => void> } */
50
50
export let effect_pending_updates = new Set ( ) ;
51
51
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
+
52
65
/** @type {Effect[] } */
53
66
let queued_root_effects = [ ] ;
54
67
@@ -438,7 +451,7 @@ export class Batch {
438
451
batches . add ( current_batch ) ;
439
452
440
453
if ( autoflush ) {
441
- queueMicrotask ( ( ) => {
454
+ Batch . enqueue ( ( ) => {
442
455
if ( current_batch !== batch ) {
443
456
// a flushSync happened in the meantime
444
457
return ;
@@ -451,6 +464,15 @@ export class Batch {
451
464
452
465
return current_batch ;
453
466
}
467
+
468
+ /** @param {() => void } task */
469
+ static enqueue ( task ) {
470
+ if ( tasks . length === 0 ) {
471
+ queueMicrotask ( dequeue ) ;
472
+ }
473
+
474
+ tasks . unshift ( task ) ;
475
+ }
454
476
}
455
477
456
478
/**
@@ -593,7 +615,11 @@ export function suspend() {
593
615
594
616
return function unsuspend ( ) {
595
617
boundary . update_pending_count ( - 1 ) ;
596
- if ( ! pending ) batch . decrement ( ) ;
618
+
619
+ if ( ! pending ) {
620
+ batch . activate ( ) ;
621
+ batch . decrement ( ) ;
622
+ }
597
623
598
624
unset_context ( ) ;
599
625
} ;
You can’t perform that action at this time.
0 commit comments