From d21e93139697be2c0a6fdc4ee74d30d2834a729f Mon Sep 17 00:00:00 2001 From: Adrien Baron Date: Fri, 11 Jan 2019 21:46:25 +0100 Subject: [PATCH] fix(async component): memory leak after synchronous async loading (#9275) fix #9229 --- .../vdom/helpers/resolve-async-component.js | 2 ++ .../modules/vdom/create-component.spec.js | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/core/vdom/helpers/resolve-async-component.js b/src/core/vdom/helpers/resolve-async-component.js index 44ca238854..4dbefd91fb 100644 --- a/src/core/vdom/helpers/resolve-async-component.js +++ b/src/core/vdom/helpers/resolve-async-component.js @@ -78,6 +78,8 @@ export function resolveAsyncComponent ( // (async resolves are shimmed as synchronous during SSR) if (!sync) { forceRender(true) + } else { + contexts.length = 0 } }) diff --git a/test/unit/modules/vdom/create-component.spec.js b/test/unit/modules/vdom/create-component.spec.js index e69fca0eff..c5a1f717c9 100644 --- a/test/unit/modules/vdom/create-component.spec.js +++ b/test/unit/modules/vdom/create-component.spec.js @@ -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 = {