Skip to content

Commit

Permalink
fix(async component): memory leak after synchronous async loading (vu…
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbaron authored and hefeng committed Jan 25, 2019
1 parent 39d3242 commit 5e32ed3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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()
done()
})

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

0 comments on commit 5e32ed3

Please sign in to comment.