Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(setup): should not trigger getter w/ object computed nested (#799)
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz committed Aug 21, 2021
1 parent 8beffc3 commit 72a878d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mixin.ts
Expand Up @@ -190,7 +190,7 @@ export function mixin(Vue: VueConstructor) {
return true
}

if (!isPlainObject(target) || isRaw(target)) {
if (!isPlainObject(target) || isRaw(target) || isRef(target)) {
return false
}
return Object.keys(target).some((x) =>
Expand Down
23 changes: 23 additions & 0 deletions test/setup.spec.js
Expand Up @@ -1219,4 +1219,27 @@ describe('setup', () => {
},
}).$mount()
})

// #794
it('should not trigger getter w/ object computed nested', () => {
const spy = jest.fn()
new Vue({
setup() {
new Vue({
setup() {
const person = {
name: computed(() => {
spy()
return 1
}),
}
return {
person,
}
},
})
},
})
expect(spy).toHaveBeenCalledTimes(0)
})
})
23 changes: 23 additions & 0 deletions test/setupContext.spec.ts
Expand Up @@ -3,6 +3,7 @@ import {
defineComponent,
createApp,
ref,
computed,
nextTick,
SetupContext,
getCurrentInstance,
Expand Down Expand Up @@ -225,4 +226,26 @@ describe('setupContext', () => {
`"RangeError: Maximum call stack size exceeded"`
).not.toHaveBeenWarned()
})

// #794
it('should not trigger getter w/ object computed nested', async () => {
const spy = jest.fn()
createApp(
defineComponent({
template: `<div/>`,
setup() {
const person = {
name: computed<number>(() => {
spy()
return 1
}),
}
return {
person,
}
},
})
).mount()
expect(spy).toHaveBeenCalledTimes(0)
})
})

0 comments on commit 72a878d

Please sign in to comment.