Skip to content

Commit 9da34d7

Browse files
authored
fix(reactivity): computed should not be detected as true by isProxy (#10401)
1 parent 37ba93c commit 9da34d7

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/reactivity/__tests__/reactive.spec.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { isRef, ref } from '../src/ref'
2-
import { isReactive, markRaw, reactive, toRaw } from '../src/reactive'
2+
import {
3+
isProxy,
4+
isReactive,
5+
markRaw,
6+
reactive,
7+
readonly,
8+
shallowReactive,
9+
shallowReadonly,
10+
toRaw,
11+
} from '../src/reactive'
312
import { computed } from '../src/computed'
413
import { effect } from '../src/effect'
514

@@ -330,4 +339,24 @@ describe('reactivity/reactive', () => {
330339
delete obj[key]
331340
expect(dummy).toBe(false)
332341
})
342+
343+
test('isProxy', () => {
344+
const foo = {}
345+
expect(isProxy(foo)).toBe(false)
346+
347+
const fooRe = reactive(foo)
348+
expect(isProxy(fooRe)).toBe(true)
349+
350+
const fooSRe = shallowReactive(foo)
351+
expect(isProxy(fooSRe)).toBe(true)
352+
353+
const barRl = readonly(foo)
354+
expect(isProxy(barRl)).toBe(true)
355+
356+
const barSRl = shallowReadonly(foo)
357+
expect(isProxy(barSRl)).toBe(true)
358+
359+
const c = computed(() => {})
360+
expect(isProxy(c)).toBe(false)
361+
})
333362
})

packages/reactivity/src/reactive.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ export function isShallow(value: unknown): boolean {
329329
* @param value - The value to check.
330330
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
331331
*/
332-
export function isProxy(value: unknown): boolean {
333-
return isReactive(value) || isReadonly(value)
332+
export function isProxy(value: any): boolean {
333+
return value ? !!value[ReactiveFlags.RAW] : false
334334
}
335335

336336
/**

0 commit comments

Comments
 (0)