Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reactivity): ref directly wrapped in proxy, should not track internal _value access. (fix: #6358) #6376

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/reactivity/__tests__/ref.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ describe('reactivity/ref', () => {
expect(fn).toHaveBeenCalledTimes(2)
})

it('ref wrapped in reactive should not track internal _value access', () => {
const a = ref(1)
const b = reactive(a)
let calls = 0
let dummy

effect(() => {
calls++
dummy = b.value // this will observe both b.value and a.value access
})
expect(calls).toBe(1)
expect(dummy).toBe(1)

// mutating a.value should only trigger effect once
calls = 0
a.value = 3
expect(calls).toBe(1)
expect(dummy).toBe(3)

// mutating b.value should trigger the effect twice. (once for a.value change and once for b.value change)
calls = 0
b.value = 5
expect(calls).toBe(2)
expect(dummy).toBe(5)
})

it('should make nested properties reactive', () => {
const a = ref({
count: 1,
Expand Down