Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(customReactive): avoid circular reference. (#758)
  • Loading branch information
ygj6 committed Jul 12, 2021
1 parent 55a0a20 commit 2bd6ea5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mixin.ts
Expand Up @@ -149,7 +149,8 @@ export function mixin(Vue: VueConstructor) {
}
}

function customReactive(target: object) {
function customReactive(target: object, visited = new Set()) {
if (visited.has(target)) return
if (
!isPlainObject(target) ||
isRef(target) ||
Expand All @@ -165,7 +166,8 @@ export function mixin(Vue: VueConstructor) {
const val = target[k]
defineReactive(target, k, val)
if (val) {
customReactive(val)
visited.add(val)
customReactive(val, visited)
}
return
})
Expand Down
30 changes: 30 additions & 0 deletions test/setupContext.spec.ts
Expand Up @@ -5,9 +5,12 @@ import {
ref,
nextTick,
SetupContext,
getCurrentInstance,
} from '../src'
import { mockWarn } from './helpers'

describe('setupContext', () => {
mockWarn(true)
it('should have proper properties', () => {
let context: SetupContext = undefined!

Expand Down Expand Up @@ -195,4 +198,31 @@ describe('setupContext', () => {

expect(_attrs.foo).toBe('bar2')
})

// #563
it('should not RangeError: Maximum call stack size exceeded', async () => {
createApp(
defineComponent({
template: `<div/>`,
setup() {
// @ts-expect-error
const app = getCurrentInstance().proxy
let mockNT: any = []
mockNT.__ob__ = {}
const test = {
app,
mockNT,
}
return {
test,
}
},
})
).mount()

await nextTick()
expect(
`"RangeError: Maximum call stack size exceeded"`
).not.toHaveBeenWarned()
})
})

0 comments on commit 2bd6ea5

Please sign in to comment.