]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): ensure markRaw objects are not reactive (#12824)
authorFatRadish <97723304+FatRadish@users.noreply.github.com>
Wed, 19 Feb 2025 06:25:30 +0000 (14:25 +0800)
committerGitHub <noreply@github.com>
Wed, 19 Feb 2025 06:25:30 +0000 (14:25 +0800)
close #12807

packages/reactivity/__tests__/reactive.spec.ts
packages/reactivity/src/reactive.ts

index aabd954568afcc627fd44ef45cbaee2a0bcdbf10..a23f2066f244b78dc2437de1b1ba664a1d8f2f9d 100644 (file)
@@ -301,6 +301,13 @@ describe('reactivity/reactive', () => {
     expect(() => markRaw(obj)).not.toThrowError()
   })
 
+  test('should not markRaw object as reactive', () => {
+    const a = reactive({ a: 1 })
+    const b = reactive({ b: 2 }) as any
+    b.a = markRaw(toRaw(a))
+    expect(b.a === a).toBe(false)
+  })
+
   test('should not observe non-extensible objects', () => {
     const obj = reactive({
       foo: Object.preventExtensions({ a: 1 }),
index 729c854965e45cc6a0b126cae25e3451adf3dea3..c549d729125ffd1bed6c9df6f861abeb1e873511 100644 (file)
@@ -279,16 +279,16 @@ function createReactiveObject(
   ) {
     return target
   }
-  // target already has corresponding Proxy
-  const existingProxy = proxyMap.get(target)
-  if (existingProxy) {
-    return existingProxy
-  }
   // only specific value types can be observed.
   const targetType = getTargetType(target)
   if (targetType === TargetType.INVALID) {
     return target
   }
+  // target already has corresponding Proxy
+  const existingProxy = proxyMap.get(target)
+  if (existingProxy) {
+    return existingProxy
+  }
   const proxy = new Proxy(
     target,
     targetType === TargetType.COLLECTION ? collectionHandlers : baseHandlers,