File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -218,15 +218,17 @@ export function mountComponent(
218218 )
219219 hydrating = false
220220
221+ // flush buffer for flush: "pre" watchers queued in setup()
222+ const preWatchers = vm . _preWatchers
223+ if ( preWatchers ) {
224+ for ( let i = 0 ; i < preWatchers . length ; i ++ ) {
225+ preWatchers [ i ] . run ( )
226+ }
227+ }
228+
221229 // manually mounted instance, call mounted on self
222230 // mounted is called for render-created child components in its inserted hook
223231 if ( vm . $vnode == null ) {
224- const preWatchers = vm . _preWatchers
225- if ( preWatchers ) {
226- for ( let i = 0 ; i < preWatchers . length ; i ++ ) {
227- preWatchers [ i ] . run ( )
228- }
229- }
230232 vm . _isMounted = true
231233 callHook ( vm , 'mounted' )
232234 }
Original file line number Diff line number Diff line change @@ -336,6 +336,23 @@ describe('api: watch', () => {
336336 expect ( result2 ) . toBe ( true )
337337 } )
338338
339+ // #12569
340+ it ( 'flush:pre watcher triggered before component mount (in child components)' , ( ) => {
341+ const count = ref ( 0 )
342+ const spy = vi . fn ( )
343+ const Comp = {
344+ setup ( ) {
345+ watch ( count , spy )
346+ count . value ++
347+ return h => h ( 'div' )
348+ }
349+ }
350+ new Vue ( {
351+ render : h => h ( Comp )
352+ } ) . $mount ( )
353+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
354+ } )
355+
339356 it ( 'flush timing: post' , async ( ) => {
340357 const count = ref ( 0 )
341358 let result
You can’t perform that action at this time.
0 commit comments