Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node maybe be removed by v-html/v-text (fix #4535) #4548

Merged
merged 1 commit into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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