From d0afcd3cf9ad572621676ef02005d226cb4ac7c4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 4 Nov 2016 16:22:49 -0400 Subject: [PATCH] fix domProps unset for v-html (fix #4107) --- src/core/vdom/patch.js | 5 ++++- src/platforms/web/runtime/modules/dom-props.js | 2 +- test/unit/modules/vdom/modules/dom-props.spec.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index eebc0ec1..13e53de5 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -78,7 +78,10 @@ export function createPatchFunction (backend) { function removeElement (el) { const parent = nodeOps.parentNode(el) - nodeOps.removeChild(parent, el) + // element may have already been removed due to v-html + if (parent) { + nodeOps.removeChild(parent, el) + } } function createElm (vnode, insertedVnodeQueue, nested) { diff --git a/src/platforms/web/runtime/modules/dom-props.js b/src/platforms/web/runtime/modules/dom-props.js index e58fbf4b..5c8c293c 100644 --- a/src/platforms/web/runtime/modules/dom-props.js +++ b/src/platforms/web/runtime/modules/dom-props.js @@ -17,7 +17,7 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) { for (key in oldProps) { if (props[key] == null) { - elm[key] = undefined + elm[key] = '' } } for (key in props) { diff --git a/test/unit/modules/vdom/modules/dom-props.spec.js b/test/unit/modules/vdom/modules/dom-props.spec.js index d442c4df..cd0a64fd 100644 --- a/test/unit/modules/vdom/modules/dom-props.spec.js +++ b/test/unit/modules/vdom/modules/dom-props.spec.js @@ -22,7 +22,7 @@ describe('vdom domProps module', () => { const vnode2 = new VNode('a', { domProps: {}}) patch(null, vnode1) const elm = patch(vnode1, vnode2) - expect(elm.src).toBeUndefined() + expect(elm.src).toBe('') }) it('should initialize the elements value to zero', () => {