Skip to content

Commit 0ad8e8d

Browse files
committed
fix(shallowReactive): should track value if already reactive when set in shallowReactive
1 parent d30f6fd commit 0ad8e8d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/core/instance/state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ function initProps(vm: Component, propsOptions: Object) {
110110
)
111111
}
112112
},
113-
true
113+
true /* shallow */
114114
)
115115
} else {
116-
defineReactive(props, key, value, undefined, true)
116+
defineReactive(props, key, value, undefined, true /* shallow */)
117117
}
118118
// static props are already proxied on the component's prototype
119119
// during Vue.extend(). We only need to proxy props defined at

src/core/observer/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ export function defineReactive(
131131
val?: any,
132132
customSetter?: Function | null,
133133
shallow?: boolean,
134-
mock?: boolean
134+
mock?: boolean,
135+
observeEvenIfShallow = false
135136
) {
136137
const dep = new Dep()
137138

@@ -150,7 +151,7 @@ export function defineReactive(
150151
val = obj[key]
151152
}
152153

153-
let childOb = !shallow && observe(val, false, mock)
154+
let childOb = shallow ? val && val.__ob__ : observe(val, false, mock)
154155
Object.defineProperty(obj, key, {
155156
enumerable: true,
156157
configurable: true,
@@ -194,7 +195,7 @@ export function defineReactive(
194195
} else {
195196
val = newVal
196197
}
197-
childOb = !shallow && observe(newVal, false, mock)
198+
childOb = shallow ? newVal && newVal.__ob__ : observe(newVal, false, mock)
198199
if (__DEV__) {
199200
dep.notify({
200201
type: TriggerOpTypes.SET,

0 commit comments

Comments
 (0)