fix(reactivity): retain readonly proxies when setting as reactive property
fix #4986
This commit is contained in:
parent
820a143457
commit
d145128ab4
@ -465,4 +465,13 @@ describe('reactivity/readonly', () => {
|
|||||||
'Set operation on key "randomProperty" failed: target is readonly.'
|
'Set operation on key "randomProperty" failed: target is readonly.'
|
||||||
).toHaveBeenWarned()
|
).toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #4986
|
||||||
|
test('setting a readonly object as a property of a reactive object should retain readonly proxy', () => {
|
||||||
|
const r = readonly({})
|
||||||
|
const rr = reactive({}) as any
|
||||||
|
rr.foo = r
|
||||||
|
expect(rr.foo).toBe(r)
|
||||||
|
expect(isReadonly(rr.foo)).toBe(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -7,7 +7,8 @@ import {
|
|||||||
readonlyMap,
|
readonlyMap,
|
||||||
reactiveMap,
|
reactiveMap,
|
||||||
shallowReactiveMap,
|
shallowReactiveMap,
|
||||||
shallowReadonlyMap
|
shallowReadonlyMap,
|
||||||
|
isReadonly
|
||||||
} from './reactive'
|
} from './reactive'
|
||||||
import { TrackOpTypes, TriggerOpTypes } from './operations'
|
import { TrackOpTypes, TriggerOpTypes } from './operations'
|
||||||
import {
|
import {
|
||||||
@ -146,7 +147,7 @@ function createSetter(shallow = false) {
|
|||||||
receiver: object
|
receiver: object
|
||||||
): boolean {
|
): boolean {
|
||||||
let oldValue = (target as any)[key]
|
let oldValue = (target as any)[key]
|
||||||
if (!shallow) {
|
if (!shallow && !isReadonly(value)) {
|
||||||
value = toRaw(value)
|
value = toRaw(value)
|
||||||
oldValue = toRaw(oldValue)
|
oldValue = toRaw(oldValue)
|
||||||
if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
|
if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user