Skip to content

Commit

Permalink
fix(async component): memory leak after synchronous async loading (#9275
Browse files Browse the repository at this point in the history
)

fix #9229
  • Loading branch information
adrienbaron authored and yyx990803 committed Jan 11, 2019
1 parent cf42f8e commit d21e931
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d21e931

Please sign in to comment.