Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commitcf1ff5b

Browse files
committed
fix: use correct ns inside <foreignObject> as root node
fixvuejs#6642
1 parent894d380 commitcf1ff5b

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

‎src/core/vdom/create-element.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,18 @@ export function _createElement (
122122
}
123123
}
124124

125-
functionapplyNS(vnode,ns){
125+
functionapplyNS(vnode,ns,force){
126126
vnode.ns=ns
127127
if(vnode.tag==='foreignObject'){
128128
// use default namespace inside foreignObject
129-
return
129+
ns=undefined
130+
force=true
130131
}
131132
if(isDef(vnode.children)){
132133
for(leti=0,l=vnode.children.length;i<l;i++){
133134
constchild=vnode.children[i]
134-
if(isDef(child.tag)&&isUndef(child.ns)){
135-
applyNS(child,ns)
135+
if(isDef(child.tag)&&(isUndef(child.ns)||force)){
136+
applyNS(child,ns,force)
136137
}
137138
}
138139
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,32 @@ describe('create-element', () => {
141141
expect(vnode.children[0].children[0].ns).toBeUndefined()
142142
})
143143

144+
// #6642
145+
it('render svg foreignObject component with correct namespace',()=>{
146+
constvm=newVue({
147+
template:`
148+
<svg>
149+
<test></test>
150+
</svg>
151+
`,
152+
components:{
153+
test:{
154+
template:`
155+
<foreignObject>
156+
<p xmlns="http://www.w3.org/1999/xhtml"></p>
157+
</foreignObject>
158+
`
159+
}
160+
}
161+
}).$mount()
162+
consttestComp=vm.$children[0]
163+
expect(testComp.$vnode.ns).toBe('svg')
164+
expect(testComp._vnode.tag).toBe('foreignObject')
165+
expect(testComp._vnode.ns).toBe('svg')
166+
expect(testComp._vnode.children[0].tag).toBe('p')
167+
expect(testComp._vnode.children[0].ns).toBeUndefined()
168+
})
169+
144170
// #6506
145171
it('render SVGAElement in a component correctly',()=>{
146172
constvm=newVue({

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp