From cf1ff5b0dc3d15c1e16821cb5e4fc984c74f07c1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 2 Oct 2017 17:35:47 -0400 Subject: [PATCH] fix: use correct ns inside as root node fix #6642 --- src/core/vdom/create-element.js | 9 ++++--- test/unit/modules/vdom/create-element.spec.js | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/core/vdom/create-element.js b/src/core/vdom/create-element.js index c9f30d2287e..fd8f853f0bc 100644 --- a/src/core/vdom/create-element.js +++ b/src/core/vdom/create-element.js @@ -122,17 +122,18 @@ export function _createElement ( } } -function applyNS (vnode, ns) { +function applyNS (vnode, ns, force) { vnode.ns = ns if (vnode.tag === 'foreignObject') { // use default namespace inside foreignObject - return + ns = undefined + force = true } if (isDef(vnode.children)) { for (let i = 0, l = vnode.children.length; i < l; i++) { const child = vnode.children[i] - if (isDef(child.tag) && isUndef(child.ns)) { - applyNS(child, ns) + if (isDef(child.tag) && (isUndef(child.ns) || force)) { + applyNS(child, ns, force) } } } diff --git a/test/unit/modules/vdom/create-element.spec.js b/test/unit/modules/vdom/create-element.spec.js index c060343df19..3bec065f312 100644 --- a/test/unit/modules/vdom/create-element.spec.js +++ b/test/unit/modules/vdom/create-element.spec.js @@ -141,6 +141,32 @@ describe('create-element', () => { expect(vnode.children[0].children[0].ns).toBeUndefined() }) + // #6642 + it('render svg foreignObject component with correct namespace', () => { + const vm = new Vue({ + template: ` + + + + `, + components: { + test: { + template: ` + +

+
+ ` + } + } + }).$mount() + const testComp = vm.$children[0] + expect(testComp.$vnode.ns).toBe('svg') + expect(testComp._vnode.tag).toBe('foreignObject') + expect(testComp._vnode.ns).toBe('svg') + expect(testComp._vnode.children[0].tag).toBe('p') + expect(testComp._vnode.children[0].ns).toBeUndefined() + }) + // #6506 it('render SVGAElement in a component correctly', () => { const vm = new Vue({