Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(svg): apply every namespace in slot when call applyNS #13008

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/core/vdom/create-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ function applyNS(vnode, ns, force?: boolean) {
ns = undefined
force = true
}
if (isDef(vnode.children)) {
for (let i = 0, l = vnode.children.length; i < l; i++) {
const child = vnode.children[i]
const children =
vnode.children ||
// #11315
(vnode.componentOptions && vnode.componentOptions.children)

if (isDef(children)) {
for (let i = 0, l = children.length; i < l; i++) {
const child = children[i]
if (
isDef(child.tag) &&
(isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))
Expand Down
43 changes: 43 additions & 0 deletions test/unit/modules/vdom/create-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,49 @@ describe('create-element', () => {
expect(vnode.children[0].children[1].ns).toBe('svg')
})

// #11315
it('render svg foreignObject nested component slot with correct namespace', () => {
const vm = new Vue({
template: `
<svg>
<box></box>
</svg>
`,
components: {
'box': {
template: `
<foreignObject>
<comp-with-slot>
<p></p><svg></svg>
</comp-with-slot>
</foreignObject>
`,
components: {
'comp-with-slot': {
template: `
<div>
<slot />
</div>
`
}
}
}
}
}).$mount()
const box = vm.$children[0]
const compWithSlot = box.$children[0]
expect(box.$vnode.ns).toBe('svg')
expect(box._vnode.tag).toBe('foreignObject')
expect(box._vnode.ns).toBe('svg')
expect(compWithSlot.$vnode.ns).toBeUndefined()
expect(compWithSlot._vnode.tag).toBe('div')
expect(compWithSlot._vnode.ns).toBeUndefined()
expect(compWithSlot._vnode.children[0].tag).toBe('p')
expect(compWithSlot._vnode.children[0].ns).toBeUndefined()
expect(compWithSlot._vnode.children[1].tag).toBe('svg')
expect(compWithSlot._vnode.children[1].ns).toBe('svg')
})

// #6642
it('render svg foreignObject component with correct namespace', () => {
const vm = new Vue({
Expand Down