Skip to content

Commit

Permalink
fix(reactivity): computed should not be detected as true by isProxy (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyWick committed Apr 15, 2024
1 parent 37ba93c commit 9da34d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion 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'

Expand Down Expand Up @@ -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)
})
})
4 changes: 2 additions & 2 deletions packages/reactivity/src/reactive.ts
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit 9da34d7

Please sign in to comment.