Skip to content

Commit 8b355ad

Browse files
committed
fix(reactivity): handle a ref directly nested in reactive
1 parent fbc0c42 commit 8b355ad

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/reactivity/__tests__/reactive.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ describe('reactivity/reactive', () => {
314314
expect(isReactive(observed)).toBe(false)
315315
})
316316

317+
test('a ref nested in a reactive', () => {
318+
const obj = reactive(ref(1))
319+
const spy1 = vi.fn(() => obj.value)
320+
effect(spy1)
321+
obj.value = 2
322+
expect(isReactive(obj)).toBe(true)
323+
})
324+
317325
test('hasOwnProperty edge case: Symbol values', () => {
318326
const key = Symbol()
319327
const obj = reactive({ [key]: 1 }) as { [key]?: 1 }

packages/reactivity/src/baseHandlers.ts

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class BaseReactiveHandler implements ProxyHandler<Target> {
8282
return
8383
}
8484

85+
// only track its value if target is a ref
86+
if (isRef(target) && key !== 'value') return (target as any)[key]
87+
8588
const targetIsArray = isArray(target)
8689

8790
if (!isReadonly) {

0 commit comments

Comments
 (0)