Skip to content

Commit a9f781a

Browse files
committed
fix(watch): revert watch behavior when watching shallow reactive objects
close #9965
1 parent 0648804 commit a9f781a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

packages/runtime-core/__tests__/apiWatch.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('api: watch', () => {
187187
})
188188

189189
// #9916
190-
it('directly watching shallow reactive array', async () => {
190+
it('watching shallow reactive array with deep: false', async () => {
191191
class foo {
192192
prop1: ShallowRef<string> = shallowRef('')
193193
prop2: string = ''
@@ -198,7 +198,7 @@ describe('api: watch', () => {
198198

199199
const collection = shallowReactive([obj1, obj2])
200200
const cb = vi.fn()
201-
watch(collection, cb)
201+
watch(collection, cb, { deep: false })
202202

203203
collection[0].prop1.value = 'foo'
204204
await nextTick()

packages/runtime-core/src/apiWatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ function doWatch(
225225
const reactiveGetter = (source: object) =>
226226
deep === true
227227
? source // traverse will happen in wrapped getter below
228-
: // for shallow or deep: false, only traverse root-level properties
229-
traverse(source, isShallow(source) || deep === false ? 1 : undefined)
228+
: // for deep: false, only traverse root-level properties
229+
traverse(source, deep === false ? 1 : undefined)
230230

231231
let getter: () => any
232232
let forceTrigger = false

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy