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(customReactive): avoid circular reference. #758

Merged
merged 2 commits into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})
})