fix(watch): revert watch behavior when watching shallow reactive objects

close #9965
This commit is contained in:
Evan You 2024-01-03 17:25:24 +08:00
parent 06488047c1
commit a9f781a92c
2 changed files with 4 additions and 4 deletions

View File

@ -187,7 +187,7 @@ describe('api: watch', () => {
})
// #9916
it('directly watching shallow reactive array', async () => {
it('watching shallow reactive array with deep: false', async () => {
class foo {
prop1: ShallowRef<string> = shallowRef('')
prop2: string = ''
@ -198,7 +198,7 @@ describe('api: watch', () => {
const collection = shallowReactive([obj1, obj2])
const cb = vi.fn()
watch(collection, cb)
watch(collection, cb, { deep: false })
collection[0].prop1.value = 'foo'
await nextTick()

View File

@ -225,8 +225,8 @@ function doWatch(
const reactiveGetter = (source: object) =>
deep === true
? source // traverse will happen in wrapped getter below
: // for shallow or deep: false, only traverse root-level properties
traverse(source, isShallow(source) || deep === false ? 1 : undefined)
: // for deep: false, only traverse root-level properties
traverse(source, deep === false ? 1 : undefined)
let getter: () => any
let forceTrigger = false