]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): respect readonly during ref unwrapping (#13905)
authoredison <daiwei521@126.com>
Wed, 24 Sep 2025 09:10:49 +0000 (17:10 +0800)
committerGitHub <noreply@github.com>
Wed, 24 Sep 2025 09:10:49 +0000 (17:10 +0800)
close #13903

packages/reactivity/__tests__/readonly.spec.ts
packages/reactivity/src/baseHandlers.ts

index b8dbdc3f6cca7092f3f06557c65d22133abae85d..a6f7542ce12f9760faf8399e5de6d5e3900d9f9f 100644 (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', () => {
index 6368018192769ab51780cf28af75fc60cb346c81..68ad10f3a1a47730277a20ca645c32c8f94ccc55 100644 (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)) {