Skip to content

Commit

Permalink
fix(reactivity): handle a ref directly nested in reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Aug 23, 2024
1 parent fbc0c42 commit 8b355ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/reactivity/__tests__/reactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ describe('reactivity/reactive', () => {
expect(isReactive(observed)).toBe(false)
})

test('a ref nested in a reactive', () => {
const obj = reactive(ref(1))
const spy1 = vi.fn(() => obj.value)
effect(spy1)
obj.value = 2
expect(isReactive(obj)).toBe(true)
})

test('hasOwnProperty edge case: Symbol values', () => {
const key = Symbol()
const obj = reactive({ [key]: 1 }) as { [key]?: 1 }
Expand Down
3 changes: 3 additions & 0 deletions packages/reactivity/src/baseHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class BaseReactiveHandler implements ProxyHandler<Target> {
return
}

// only track its value if target is a ref
if (isRef(target) && key !== 'value') return (target as any)[key]

const targetIsArray = isArray(target)

if (!isReadonly) {
Expand Down

0 comments on commit 8b355ad

Please sign in to comment.