Skip to content

Commit 6116bbf

Browse files
committed
fix svg foreignObject regression (fix #4478)
1 parent 0fe431b commit 6116bbf

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/core/vdom/create-element.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export function _createElement (
7171
// unknown or unlisted namespaced elements
7272
// check at runtime because it may get assigned a namespace when its
7373
// parent normalizes children
74-
ns = tag === 'foreignObject' ? 'xhtml' : ns
7574
vnode = new VNode(
7675
tag, data, children,
7776
undefined, undefined, context
@@ -91,6 +90,10 @@ export function _createElement (
9190

9291
function applyNS (vnode, ns) {
9392
vnode.ns = ns
93+
if (vnode.tag === 'foreignObject') {
94+
// use default namespace inside foreignObject
95+
return
96+
}
9497
if (vnode.children) {
9598
for (let i = 0, l = vnode.children.length; i < l; i++) {
9699
const child = vnode.children[i]

src/platforms/web/util/element.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { makeMap } from 'shared/util'
55

66
export const namespaceMap = {
77
svg: 'http://www.w3.org/2000/svg',
8-
math: 'http://www.w3.org/1998/Math/MathML',
9-
xhtml: 'http://www.w3.org/1999/xhtml'
8+
math: 'http://www.w3.org/1998/Math/MathML'
109
}
1110

1211
export const isHTMLTag = makeMap(

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ describe('create-element', () => {
132132
expect(vnode.children[0].componentOptions).toBeUndefined()
133133
})
134134

135+
it('render svg foreignObject with correct namespace', () => {
136+
const vm = new Vue({})
137+
const h = vm.$createElement
138+
const vnode = h('svg', [h('foreignObject', [h('p')])])
139+
expect(vnode.ns).toBe('svg')
140+
expect(vnode.children[0].ns).toBe('svg')
141+
expect(vnode.children[0].children[0].ns).toBeUndefined()
142+
})
143+
135144
it('warn observed data objects', () => {
136145
new Vue({
137146
data: {

0 commit comments

Comments
 (0)