Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/v3/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,17 @@ function doWatch(
})
} else if (isFunction(source)) {
if (cb) {
// getter with cb
getter = () => call(source, WATCHER_GETTER)
const ob = call(source, WATCHER_GETTER)
if (isReactive(ob)){
getter = () => {
;(ob as any).__ob__.dep.depend()
return ob
}
deep = true
} else {
// getter with cb
getter = () => call(source, WATCHER_GETTER)
}
} else {
// no cb -> simple effect
getter = () => {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/features/v3/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1200,4 +1200,15 @@ describe('api: watch', () => {
expect(parentSpy).toHaveBeenCalledTimes(1)
expect(childSpy).toHaveBeenCalledTimes(1)
})

// #12967
test('trigger when adding new property with Vue.set', async () => {
const spy = vi.fn()
const r = reactive({ exist: 5 })
watch(() => r, spy, { deep: true })
set(r, 'add', 1)

await nextTick()
expect(spy).toHaveBeenCalledTimes(1)
})
})