From a9f781a92cbc7de7b25c9e3d5b1295ca99eb6d86 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 3 Jan 2024 17:25:24 +0800 Subject: [PATCH] fix(watch): revert watch behavior when watching shallow reactive objects close #9965 --- packages/runtime-core/__tests__/apiWatch.spec.ts | 4 ++-- packages/runtime-core/src/apiWatch.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index c82b06c1a8b..3656b0a64ba 100644 --- a/packages/runtime-core/__tests__/apiWatch.spec.ts +++ b/packages/runtime-core/__tests__/apiWatch.spec.ts @@ -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 = 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() diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index d840864454f..7e1e250bd64 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -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