From: Evan You Date: Wed, 3 Jan 2024 09:25:24 +0000 (+0800) Subject: fix(watch): revert watch behavior when watching shallow reactive objects X-Git-Tag: v3.4.4~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9f781a92cbc7de7b25c9e3d5b1295ca99eb6d86;p=thirdparty%2Fvuejs%2Fcore.git fix(watch): revert watch behavior when watching shallow reactive objects close #9965 --- diff --git a/packages/runtime-core/__tests__/apiWatch.spec.ts b/packages/runtime-core/__tests__/apiWatch.spec.ts index c82b06c1a8..3656b0a64b 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 d840864454..7e1e250bd6 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