Skip to content

Commit 0529961

Browse files
javoskiyyx990803
authored andcommitted
fix(vdom): svg inside foreignObject should be rendered with correct namespace (fix #7330) (#7350)
* add failed test case * fix failed test case * fix(vdom): svg inside foreignObject should be rendered with correct namespace * adjust comments
1 parent 6ee6849 commit 0529961

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/core/vdom/create-element.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ function applyNS (vnode, ns, force) {
139139
if (isDef(vnode.children)) {
140140
for (let i = 0, l = vnode.children.length; i < l; i++) {
141141
const child = vnode.children[i]
142-
if (isDef(child.tag) && (isUndef(child.ns) || isTrue(force))) {
142+
if (isDef(child.tag) && (
143+
isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
143144
applyNS(child, ns, force)
144145
}
145146
}

test/unit/modules/vdom/create-element.spec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ describe('create-element', () => {
135135
it('render svg foreignObject with correct namespace', () => {
136136
const vm = new Vue({})
137137
const h = vm.$createElement
138-
const vnode = h('svg', [h('foreignObject', [h('p')])])
138+
const vnode = h('svg', [h('foreignObject', [h('p'), h('svg')])])
139139
expect(vnode.ns).toBe('svg')
140140
expect(vnode.children[0].ns).toBe('svg')
141141
expect(vnode.children[0].children[0].ns).toBeUndefined()
142+
// #7330
143+
expect(vnode.children[0].children[1].ns).toBe('svg')
142144
})
143145

144146
// #6642

0 commit comments

Comments
 (0)