]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(watch): revert watch behavior when watching shallow reactive objects
authorEvan You <yyx990803@gmail.com>
Wed, 3 Jan 2024 09:25:24 +0000 (17:25 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 3 Jan 2024 09:25:24 +0000 (17:25 +0800)
close #9965

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

index c82b06c1a8b02715cb0b49e781e8124f5a5064c7..3656b0a64bac2ac5698ffe468180767a1bc5758e 100644 (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()
index d840864454ffa87e76227a881d8de6c038670a68..7e1e250bd64f4f04f8a9e4f34df5a605659220d3 100644 (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