Skip to content

Commit

Permalink
fix(watch): revert watch behavior when watching shallow reactive objects
Browse files Browse the repository at this point in the history
close #9965
  • Loading branch information
yyx990803 committed Jan 3, 2024
1 parent 0648804 commit a9f781a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9f781a

Please sign in to comment.