fix(reactivity): respect readonly during ref unwrapping (#13905)

close #13903
This commit is contained in:
edison 2025-09-24 17:10:49 +08:00 committed by GitHub
parent ba7f7f90f6
commit aba7feda17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -522,6 +522,16 @@ describe('reactivity/readonly', () => {
expect(obj.r).toBe(ro)
expect(r.value).toBe(ro)
})
test('should keep nested ref readonly', () => {
const items = ref(['one', 'two', 'three'])
const obj = {
o: readonly({
items,
}),
}
expect(isReadonly(obj.o.items)).toBe(true)
})
})
test('should be able to trigger with triggerRef', () => {

View File

@ -119,7 +119,8 @@ class BaseReactiveHandler implements ProxyHandler<Target> {
if (isRef(res)) {
// ref unwrapping - skip unwrap for Array + integer key.
return targetIsArray && isIntegerKey(key) ? res : res.value
const value = targetIsArray && isIntegerKey(key) ? res : res.value
return isReadonly && isObject(value) ? readonly(value) : value
}
if (isObject(res)) {