]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): computed should not be detected as true by isProxy (#10401)
authorWick <wick.linxunjie@gmail.com>
Mon, 15 Apr 2024 14:55:37 +0000 (22:55 +0800)
committerGitHub <noreply@github.com>
Mon, 15 Apr 2024 14:55:37 +0000 (22:55 +0800)
packages/reactivity/__tests__/reactive.spec.ts
packages/reactivity/src/reactive.ts

index cdcd032580563daaa93a3e6daccd749b2f659285..bd4ec402bb2a1e0e9fd9c3768df31ead88d032da 100644 (file)
@@ -1,5 +1,14 @@
 import { isRef, ref } from '../src/ref'
-import { isReactive, markRaw, reactive, toRaw } from '../src/reactive'
+import {
+  isProxy,
+  isReactive,
+  markRaw,
+  reactive,
+  readonly,
+  shallowReactive,
+  shallowReadonly,
+  toRaw,
+} from '../src/reactive'
 import { computed } from '../src/computed'
 import { effect } from '../src/effect'
 
@@ -330,4 +339,24 @@ describe('reactivity/reactive', () => {
     delete obj[key]
     expect(dummy).toBe(false)
   })
+
+  test('isProxy', () => {
+    const foo = {}
+    expect(isProxy(foo)).toBe(false)
+
+    const fooRe = reactive(foo)
+    expect(isProxy(fooRe)).toBe(true)
+
+    const fooSRe = shallowReactive(foo)
+    expect(isProxy(fooSRe)).toBe(true)
+
+    const barRl = readonly(foo)
+    expect(isProxy(barRl)).toBe(true)
+
+    const barSRl = shallowReadonly(foo)
+    expect(isProxy(barSRl)).toBe(true)
+
+    const c = computed(() => {})
+    expect(isProxy(c)).toBe(false)
+  })
 })
index 7e80737fbcc2bc6de97d27468fdb13cc4647cbfa..f6fcbbdb98f7aa9b4d68679a6e03cab89774df1a 100644 (file)
@@ -329,8 +329,8 @@ export function isShallow(value: unknown): boolean {
  * @param value - The value to check.
  * @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
  */
-export function isProxy(value: unknown): boolean {
-  return isReactive(value) || isReadonly(value)
+export function isProxy(value: any): boolean {
+  return value ? !!value[ReactiveFlags.RAW] : false
 }
 
 /**