diff --git a/src/mixin.ts b/src/mixin.ts index 88e4b0c9..ed9fc19a 100644 --- a/src/mixin.ts +++ b/src/mixin.ts @@ -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) => diff --git a/test/setup.spec.js b/test/setup.spec.js index ae29ec77..64f457d5 100644 --- a/test/setup.spec.js +++ b/test/setup.spec.js @@ -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) + }) }) diff --git a/test/setupContext.spec.ts b/test/setupContext.spec.ts index 6ec978f7..701bc95d 100644 --- a/test/setupContext.spec.ts +++ b/test/setupContext.spec.ts @@ -3,6 +3,7 @@ import { defineComponent, createApp, ref, + computed, nextTick, SetupContext, getCurrentInstance, @@ -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: `
`, + setup() { + const person = { + name: computed(() => { + spy() + return 1 + }), + } + return { + person, + } + }, + }) + ).mount() + expect(spy).toHaveBeenCalledTimes(0) + }) })