File tree 2 files changed +29
-5
lines changed
2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -320,11 +320,12 @@ function doWatch(
320
320
} else {
321
321
// pre
322
322
watcher . update = ( ) => {
323
- if ( ! instance || instance . _isMounted ) {
324
- queueWatcher ( watcher )
325
- } else {
323
+ if ( instance && instance === currentInstance ) {
324
+ // pre-watcher triggered inside setup()
326
325
const buffer = instance . _preWatchers || ( instance . _preWatchers = [ ] )
327
326
if ( buffer . indexOf ( watcher ) < 0 ) buffer . push ( watcher )
327
+ } else {
328
+ queueWatcher ( watcher )
328
329
}
329
330
}
330
331
}
Original file line number Diff line number Diff line change @@ -628,9 +628,8 @@ describe('api: watch', () => {
628
628
expect ( calls ) . toMatchObject ( [ 'watch 3' , 'mounted' ] )
629
629
} )
630
630
631
- // TODO
632
631
// vuejs/core#1852
633
- it . skip ( 'flush: post watcher should fire after template refs updated' , async ( ) => {
632
+ it ( 'flush: post watcher should fire after template refs updated' , async ( ) => {
634
633
const toggle = ref ( false )
635
634
let dom : HTMLElement | null = null
636
635
@@ -1093,4 +1092,28 @@ describe('api: watch', () => {
1093
1092
// own update effect
1094
1093
expect ( instance ! . _scope . effects . length ) . toBe ( 1 )
1095
1094
} )
1095
+
1096
+ // #12578
1097
+ test ( 'template ref triggered watcher should fire after component mount' , async ( ) => {
1098
+ const order : string [ ] = [ ]
1099
+ const Child = { template : '<div/>' }
1100
+ const App = {
1101
+ setup ( ) {
1102
+ const child = ref < any > ( null )
1103
+ onMounted ( ( ) => {
1104
+ order . push ( 'mounted' )
1105
+ } )
1106
+ watch ( child , ( ) => {
1107
+ order . push ( 'watcher' )
1108
+ } )
1109
+ return { child }
1110
+ } ,
1111
+ components : { Child } ,
1112
+ template : `<Child ref="child"/>`
1113
+ }
1114
+ new Vue ( App ) . $mount ( )
1115
+
1116
+ await nextTick ( )
1117
+ expect ( order ) . toMatchObject ( [ `mounted` , `watcher` ] )
1118
+ } )
1096
1119
} )
You can’t perform that action at this time.
0 commit comments