mirror of https://github.com/vuejs/core.git
fix(reactivity): avoid infinite recursion when mutating ref wrapped in reactive
close #11696
This commit is contained in:
parent
9c4c2e51b0
commit
313e4bf552
|
@ -382,4 +382,13 @@ describe('reactivity/reactive', () => {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #11696
|
||||||
|
test('should use correct receiver on set handler for refs', () => {
|
||||||
|
const a = reactive(ref(1))
|
||||||
|
effect(() => a.value)
|
||||||
|
expect(() => {
|
||||||
|
a.value++
|
||||||
|
}).not.toThrow()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -165,7 +165,12 @@ class MutableReactiveHandler extends BaseReactiveHandler {
|
||||||
isArray(target) && isIntegerKey(key)
|
isArray(target) && isIntegerKey(key)
|
||||||
? Number(key) < target.length
|
? Number(key) < target.length
|
||||||
: hasOwn(target, key)
|
: hasOwn(target, key)
|
||||||
const result = Reflect.set(target, key, value, receiver)
|
const result = Reflect.set(
|
||||||
|
target,
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
isRef(target) ? target : receiver,
|
||||||
|
)
|
||||||
// don't trigger if target is something up in the prototype chain of original
|
// don't trigger if target is something up in the prototype chain of original
|
||||||
if (target === toRaw(receiver)) {
|
if (target === toRaw(receiver)) {
|
||||||
if (!hadKey) {
|
if (!hadKey) {
|
||||||
|
|
Loading…
Reference in New Issue