From caa2b46172ee10ce9a59f9cd137c8f408d1e1e79 Mon Sep 17 00:00:00 2001 From: OnlyWick Date: Wed, 13 Mar 2024 11:07:11 +0800 Subject: [PATCH 1/3] fix(reactivity): computed should not be detected as true by isProxy --- packages/reactivity/src/reactive.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 1e0f9365daa..996a6e8828d 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -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 } /** From eae332f77c81c1647f9b70a8ae48ca672fb35240 Mon Sep 17 00:00:00 2001 From: OnlyWick Date: Wed, 13 Mar 2024 11:10:10 +0800 Subject: [PATCH 2/3] test(reactivity): add test --- .../reactivity/__tests__/reactive.spec.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/__tests__/reactive.spec.ts b/packages/reactivity/__tests__/reactive.spec.ts index ab953ff891a..a36d6ed495f 100644 --- a/packages/reactivity/__tests__/reactive.spec.ts +++ b/packages/reactivity/__tests__/reactive.spec.ts @@ -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' @@ -302,4 +311,24 @@ describe('reactivity/reactive', () => { const observed = reactive(original) expect(isReactive(observed)).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) + }) }) From 825a3e0ef0b8378fc10d022d2a9f08c17262ef0d Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:53:48 +0000 Subject: [PATCH 3/3] [autofix.ci] apply automated fixes --- packages/reactivity/__tests__/reactive.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/reactivity/__tests__/reactive.spec.ts b/packages/reactivity/__tests__/reactive.spec.ts index c174fbc84e3..bd4ec402bb2 100644 --- a/packages/reactivity/__tests__/reactive.spec.ts +++ b/packages/reactivity/__tests__/reactive.spec.ts @@ -312,7 +312,6 @@ describe('reactivity/reactive', () => { expect(isReactive(observed)).toBe(false) }) - test('hasOwnProperty edge case: Symbol values', () => { const key = Symbol() const obj = reactive({ [key]: 1 }) as { [key]?: 1 } @@ -340,7 +339,7 @@ describe('reactivity/reactive', () => { delete obj[key] expect(dummy).toBe(false) }) - + test('isProxy', () => { const foo = {} expect(isProxy(foo)).toBe(false)