From 99a96d3c37d70c0fad842f45bcdf9147c10350aa Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 28 May 2016 21:05:53 -0400 Subject: [PATCH] should invoke destroy hook for replaced root nodes too --- src/core/vdom/patch.js | 2 ++ test/unit/modules/vdom/patch/hooks.spec.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index 5d97c442..379c7ab3 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -383,6 +383,8 @@ export function createPatchFunction (backend) { if (parent !== null) { nodeOps.insertBefore(parent, vnode.elm, nodeOps.nextSibling(elm)) removeVnodes(parent, [oldVnode], 0, 0) + } else if (isDef(oldVnode.tag)) { + invokeDestroyHook(oldVnode) } } } diff --git a/test/unit/modules/vdom/patch/hooks.spec.js b/test/unit/modules/vdom/patch/hooks.spec.js index 8d940c6a..adac0cd2 100644 --- a/test/unit/modules/vdom/patch/hooks.spec.js +++ b/test/unit/modules/vdom/patch/hooks.spec.js @@ -244,9 +244,10 @@ describe('hooks', () => { ]) const vnode2 = new VNode('div') patch1(vnode0, vnode1) + expect(destroyed).toBe(1) // should invoke for replaced root nodes too patch1(vnode1, vnode2) expect(created).toBe(5) - expect(destroyed).toBe(4) + expect(destroyed).toBe(5) }) it('should not invoke `create` and `remove` module hook for text nodes', () => { @@ -293,9 +294,10 @@ describe('hooks', () => { ]) const vnode2 = new VNode('div') patch1(vnode0, vnode1) + expect(destroyed).toBe(1) // should invoke for replaced root nodes too patch1(vnode1, vnode2) expect(created).toBe(5) - expect(destroyed).toBe(4) + expect(destroyed).toBe(5) }) it('should call `create` listener before inserted into parent but after children', () => {