File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -218,8 +218,17 @@ function doWatch(
218
218
} )
219
219
} else if ( isFunction ( source ) ) {
220
220
if ( cb ) {
221
- // getter with cb
222
- getter = ( ) => call ( source , WATCHER_GETTER )
221
+ const ob = call ( source , WATCHER_GETTER )
222
+ if ( isReactive ( ob ) ) {
223
+ getter = ( ) => {
224
+ ; ( ob as any ) . __ob__ . dep . depend ( )
225
+ return ob
226
+ }
227
+ deep = true
228
+ } else {
229
+ // getter with cb
230
+ getter = ( ) => ob
231
+ }
223
232
} else {
224
233
// no cb -> simple effect
225
234
getter = ( ) => {
Original file line number Diff line number Diff line change @@ -1200,4 +1200,15 @@ describe('api: watch', () => {
1200
1200
expect ( parentSpy ) . toHaveBeenCalledTimes ( 1 )
1201
1201
expect ( childSpy ) . toHaveBeenCalledTimes ( 1 )
1202
1202
} )
1203
+
1204
+ // #12967
1205
+ test ( 'trigger when adding new property with Vue.set' , async ( ) => {
1206
+ const spy = vi . fn ( )
1207
+ const r = reactive ( { exist : 5 } )
1208
+ watch ( ( ) => r , spy , { deep : true } )
1209
+ set ( r , 'add' , 1 )
1210
+
1211
+ await nextTick ( )
1212
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
1213
+ } )
1203
1214
} )
You can’t perform that action at this time.
0 commit comments