Skip to content

Commit 71cc0a5

Browse files
defccyyx990803
authored andcommitted
Node maybe be removed v-html/v-text (#4548)
1 parent 2009de3 commit 71cc0a5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Diff for: src/core/vdom/patch.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ export function createPatchFunction (backend) {
6969
function createRmCb (childElm, listeners) {
7070
function remove () {
7171
if (--remove.listeners === 0) {
72-
removeElement(childElm)
72+
removeNode(childElm)
7373
}
7474
}
7575
remove.listeners = listeners
7676
return remove
7777
}
7878

79-
function removeElement (el) {
79+
function removeNode (el) {
8080
const parent = nodeOps.parentNode(el)
81-
// element may have already been removed due to v-html
81+
// element may have already been removed due to v-html / v-text
8282
if (parent) {
8383
nodeOps.removeChild(parent, el)
8484
}
@@ -298,7 +298,7 @@ export function createPatchFunction (backend) {
298298
removeAndInvokeRemoveHook(ch)
299299
invokeDestroyHook(ch)
300300
} else { // Text node
301-
nodeOps.removeChild(parentElm, ch.elm)
301+
removeNode(ch.elm)
302302
}
303303
}
304304
}
@@ -328,7 +328,7 @@ export function createPatchFunction (backend) {
328328
rm()
329329
}
330330
} else {
331-
removeElement(vnode.elm)
331+
removeNode(vnode.elm)
332332
}
333333
}
334334

Diff for: test/unit/modules/vdom/modules/dom-props.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ describe('vdom domProps module', () => {
5252
const elm2 = patch(null, vnode2)
5353
expect(elm2.textContent).toBe('hi')
5454
expect(vnode2.children.length).toBe(0)
55+
56+
const vnode3 = new VNode('div', undefined, undefined, '123')
57+
patch(null, vnode3)
58+
const elm3 = patch(vnode3, vnode2)
59+
expect(elm3.textContent).toBe('hi')
60+
61+
const vnode4 = new VNode('div', undefined, undefined, new VNode('span'))
62+
patch(null, vnode4)
63+
const elm4 = patch(vnode4, vnode)
64+
expect(elm4.textContent).toBe('hi')
5565
})
5666

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

0 commit comments

Comments
 (0)