File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -610,4 +610,25 @@ describe('scheduler', () => {
610610 expect ( await p ) . toBe ( 1 )
611611 expect ( fn ) . toHaveBeenCalledTimes ( 1 )
612612 } )
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+ } )
613634} )
Original file line number Diff line number Diff line change @@ -164,7 +164,9 @@ export function flushPreFlushCbs(
164164
165165export function flushPostFlushCbs ( seen ?: CountMap ) {
166166 if ( pendingPostFlushCbs . length ) {
167- const deduped = [ ...new Set ( pendingPostFlushCbs ) ]
167+ const deduped = [ ...new Set ( pendingPostFlushCbs ) ] . sort (
168+ ( a , b ) => getId ( a ) - getId ( b ) ,
169+ )
168170 pendingPostFlushCbs . length = 0
169171
170172 // #1947 already has active queue, nested flushPostFlushCbs call
@@ -178,8 +180,6 @@ export function flushPostFlushCbs(seen?: CountMap) {
178180 seen = seen || new Map ( )
179181 }
180182
181- activePostFlushCbs . sort ( ( a , b ) => getId ( a ) - getId ( b ) )
182-
183183 for (
184184 postFlushIndex = 0 ;
185185 postFlushIndex < activePostFlushCbs . length ;
You can’t perform that action at this time.
0 commit comments