Skip to content

Commit 7f429e9

Browse files
committed
discard vnode children if it has innerHTML or textContent as a prop (fix vuejs#3360)
1 parent f31366c commit 7f429e9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/platforms/web/runtime/modules/dom-props.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
2121
}
2222
}
2323
for (key in props) {
24+
// ignore children if the node has textContent or innerHTML,
25+
// as these will throw away existing DOM nodes and cause removal errors
26+
// on subsequent patches (#3360)
27+
if ((key === 'textContent' || key === 'innerHTML') && vnode.children) {
28+
vnode.children.length = 0
29+
}
2430
cur = props[key]
2531
if (key === 'value') {
2632
// store value as _value as well since

test/unit/modules/vdom/modules/props.spec.js renamed to test/unit/modules/vdom/modules/dom-props.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,27 @@ describe('vdom domProps module', () => {
2929
const elm = patch(null, vnode)
3030
expect(elm.value).toBe('0')
3131
})
32+
33+
it('should save raw value on element', () => {
34+
const value = {}
35+
const vnode = new VNode('input', { domProps: { value }})
36+
const elm = patch(null, vnode)
37+
expect(elm._value).toBe(value)
38+
})
39+
40+
it('should discard vnode children if the node has innerHTML or textContent as a prop', () => {
41+
const vnode = new VNode('div', { domProps: { innerHTML: 'hi' }}, [
42+
new VNode('span'), new VNode('span')
43+
])
44+
const elm = patch(null, vnode)
45+
expect(elm.innerHTML).toBe('hi')
46+
expect(vnode.children.length).toBe(0)
47+
48+
const vnode2 = new VNode('div', { domProps: { textContent: 'hi' }}, [
49+
new VNode('span'), new VNode('span')
50+
])
51+
const elm2 = patch(null, vnode2)
52+
expect(elm2.textContent).toBe('hi')
53+
expect(vnode2.children.length).toBe(0)
54+
})
3255
})

0 commit comments

Comments
 (0)