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(async component): memory leak after synchronous async loading (fix #9229) #9275

Merged
merged 3 commits into from Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/core/vdom/helpers/resolve-async-component.js
Expand Up @@ -78,6 +78,8 @@ export function resolveAsyncComponent (
// (async resolves are shimmed as synchronous during SSR)
if (!sync) {
forceRender(true)
} else {
contexts.length = 0
}
})

Expand Down
26 changes: 26 additions & 0 deletions test/unit/modules/vdom/create-component.spec.js
Expand Up @@ -76,6 +76,32 @@ describe('create-component', () => {
go()
})

it('create a component when resolved with synchronous async loading', done => {
const data = {
props: {},
staticAttrs: { class: 'bar' }
}
spyOn(vm, '$forceUpdate')
function async (resolve, reject) {
resolve({
name: 'child',
props: ['msg']
})
}
const vnode = createComponent(async, data, vm, vm)
expect(vnode.asyncFactory).toBe(async)
expect(vnode.asyncFactory.contexts.length).toEqual(0)
expect(vnode.tag).toMatch(/vue-component-[0-9]+-child/)
expect(vnode.data.staticAttrs).toEqual({ class: 'bar' })
expect(vnode.children).toBeUndefined()
expect(vnode.text).toBeUndefined()
expect(vnode.elm).toBeUndefined()
expect(vnode.ns).toBeUndefined()
expect(vnode.context).toEqual(vm)
expect(vm.$forceUpdate).not.toHaveBeenCalled()
adrienbaron marked this conversation as resolved.
Show resolved Hide resolved
adrienbaron marked this conversation as resolved.
Show resolved Hide resolved
done()
})

it('not create a component when rejected with async loading', done => {
let vnode = null
const data = {
Expand Down