File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -610,4 +610,25 @@ describe('scheduler', () => {
610
610
expect ( await p ) . toBe ( 1 )
611
611
expect ( fn ) . toHaveBeenCalledTimes ( 1 )
612
612
} )
613
+
614
+ // #10003
615
+ test ( 'nested flushPostFlushCbs' , async ( ) => {
616
+ const calls : string [ ] = [ ]
617
+ const cb1 = ( ) => calls . push ( 'cb1' )
618
+ // cb1 has no id
619
+ const cb2 = ( ) => calls . push ( 'cb2' )
620
+ cb2 . id = - 1
621
+ const queueAndFlush = ( hook : Function ) => {
622
+ queuePostFlushCb ( hook )
623
+ flushPostFlushCbs ( )
624
+ }
625
+
626
+ queueAndFlush ( ( ) => {
627
+ queuePostFlushCb ( [ cb1 , cb2 ] )
628
+ flushPostFlushCbs ( )
629
+ } )
630
+
631
+ await nextTick ( )
632
+ expect ( calls ) . toEqual ( [ 'cb2' , 'cb1' ] )
633
+ } )
613
634
} )
Original file line number Diff line number Diff line change @@ -164,7 +164,9 @@ export function flushPreFlushCbs(
164
164
165
165
export function flushPostFlushCbs ( seen ?: CountMap ) {
166
166
if ( pendingPostFlushCbs . length ) {
167
- const deduped = [ ...new Set ( pendingPostFlushCbs ) ]
167
+ const deduped = [ ...new Set ( pendingPostFlushCbs ) ] . sort (
168
+ ( a , b ) => getId ( a ) - getId ( b ) ,
169
+ )
168
170
pendingPostFlushCbs . length = 0
169
171
170
172
// #1947 already has active queue, nested flushPostFlushCbs call
@@ -178,8 +180,6 @@ export function flushPostFlushCbs(seen?: CountMap) {
178
180
seen = seen || new Map ( )
179
181
}
180
182
181
- activePostFlushCbs . sort ( ( a , b ) => getId ( a ) - getId ( b ) )
182
-
183
183
for (
184
184
postFlushIndex = 0 ;
185
185
postFlushIndex < activePostFlushCbs . length ;
You can’t perform that action at this time.
0 commit comments