Skip to content

Commit

Permalink
Node maybe be removed v-html/v-text (#4548)
Browse files Browse the repository at this point in the history
  • Loading branch information
defcc authored and yyx990803 committed Dec 23, 2016
1 parent 2009de3 commit 71cc0a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/vdom/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ export function createPatchFunction (backend) {
function createRmCb (childElm, listeners) {
function remove () {
if (--remove.listeners === 0) {
removeElement(childElm)
removeNode(childElm)
}
}
remove.listeners = listeners
return remove
}

function removeElement (el) {
function removeNode (el) {
const parent = nodeOps.parentNode(el)
// element may have already been removed due to v-html
// element may have already been removed due to v-html / v-text
if (parent) {
nodeOps.removeChild(parent, el)
}
Expand Down Expand Up @@ -298,7 +298,7 @@ export function createPatchFunction (backend) {
removeAndInvokeRemoveHook(ch)
invokeDestroyHook(ch)
} else { // Text node
nodeOps.removeChild(parentElm, ch.elm)
removeNode(ch.elm)
}
}
}
Expand Down Expand Up @@ -328,7 +328,7 @@ export function createPatchFunction (backend) {
rm()
}
} else {
removeElement(vnode.elm)
removeNode(vnode.elm)
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/unit/modules/vdom/modules/dom-props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ describe('vdom domProps module', () => {
const elm2 = patch(null, vnode2)
expect(elm2.textContent).toBe('hi')
expect(vnode2.children.length).toBe(0)

const vnode3 = new VNode('div', undefined, undefined, '123')
patch(null, vnode3)
const elm3 = patch(vnode3, vnode2)
expect(elm3.textContent).toBe('hi')

const vnode4 = new VNode('div', undefined, undefined, new VNode('span'))
patch(null, vnode4)
const elm4 = patch(vnode4, vnode)
expect(elm4.textContent).toBe('hi')
})

it('should handle mutating observed props object', done => {
Expand Down

0 comments on commit 71cc0a5

Please sign in to comment.