Skip to content

Commit 904cd6d

Browse files
committed
fix(namespace): apply every namespace in slot when call applyNS (#11315)
1 parent a9ca2d8 commit 904cd6d

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/core/vdom/create-element.ts

+11
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ function applyNS(vnode, ns, force?: boolean) {
157157
}
158158
}
159159
}
160+
161+
// #11315
162+
if (isObject(vnode.componentOptions) && isDef(vnode.componentOptions.children)) {
163+
for (var i = 0, l = vnode.componentOptions.children.length; i < l; i++) {
164+
var child = vnode.componentOptions.children[i]
165+
if (isDef(child.tag) && (
166+
isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
167+
applyNS(child, ns, force)
168+
}
169+
}
170+
}
160171
}
161172

162173
// ref #5318

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

+43
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,49 @@ describe('create-element', () => {
147147
expect(vnode.children[0].children[1].ns).toBe('svg')
148148
})
149149

150+
// #11315
151+
it('render svg foreignObject nested component slot with correct namespace', () => {
152+
const vm = new Vue({
153+
template: `
154+
<svg>
155+
<box></box>
156+
</svg>
157+
`,
158+
components: {
159+
'box': {
160+
template: `
161+
<foreignObject>
162+
<comp-with-slot>
163+
<p></p><svg></svg>
164+
</comp-with-slot>
165+
</foreignObject>
166+
`,
167+
components: {
168+
'comp-with-slot': {
169+
template: `
170+
<div>
171+
<slot />
172+
</div>
173+
`
174+
}
175+
}
176+
}
177+
}
178+
}).$mount()
179+
const box = vm.$children[0]
180+
const compWithSlot = box.$children[0]
181+
expect(box.$vnode.ns).toBe('svg')
182+
expect(box._vnode.tag).toBe('foreignObject')
183+
expect(box._vnode.ns).toBe('svg')
184+
expect(compWithSlot.$vnode.ns).toBeUndefined()
185+
expect(compWithSlot._vnode.tag).toBe('div')
186+
expect(compWithSlot._vnode.ns).toBeUndefined()
187+
expect(compWithSlot._vnode.children[0].tag).toBe('p')
188+
expect(compWithSlot._vnode.children[0].ns).toBeUndefined()
189+
expect(compWithSlot._vnode.children[1].tag).toBe('svg')
190+
expect(compWithSlot._vnode.children[1].ns).toBe('svg')
191+
})
192+
150193
// #6642
151194
it('render svg foreignObject component with correct namespace', () => {
152195
const vm = new Vue({

0 commit comments

Comments
 (0)