From 0ad8e8d94f3a3bf4429f25850c85a6bbb2b81364 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 6 Dec 2023 15:45:15 +0800 Subject: [PATCH] fix(shallowReactive): should track value if already reactive when set in shallowReactive --- src/core/instance/state.ts | 4 ++-- src/core/observer/index.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/instance/state.ts b/src/core/instance/state.ts index 7ac84c6ba..f59dda13d 100644 --- a/src/core/instance/state.ts +++ b/src/core/instance/state.ts @@ -110,10 +110,10 @@ function initProps(vm: Component, propsOptions: Object) { ) } }, - true + true /* shallow */ ) } else { - defineReactive(props, key, value, undefined, true) + defineReactive(props, key, value, undefined, true /* shallow */) } // static props are already proxied on the component's prototype // during Vue.extend(). We only need to proxy props defined at diff --git a/src/core/observer/index.ts b/src/core/observer/index.ts index 9988fb868..dc6efae4d 100644 --- a/src/core/observer/index.ts +++ b/src/core/observer/index.ts @@ -131,7 +131,8 @@ export function defineReactive( val?: any, customSetter?: Function | null, shallow?: boolean, - mock?: boolean + mock?: boolean, + observeEvenIfShallow = false ) { const dep = new Dep() @@ -150,7 +151,7 @@ export function defineReactive( val = obj[key] } - let childOb = !shallow && observe(val, false, mock) + let childOb = shallow ? val && val.__ob__ : observe(val, false, mock) Object.defineProperty(obj, key, { enumerable: true, configurable: true, @@ -194,7 +195,7 @@ export function defineReactive( } else { val = newVal } - childOb = !shallow && observe(newVal, false, mock) + childOb = shallow ? newVal && newVal.__ob__ : observe(newVal, false, mock) if (__DEV__) { dep.notify({ type: TriggerOpTypes.SET,