Skip to content

Commit

Permalink
fix(namespace): apply every namespace in slot when call applyNS (vuej…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhonghe committed Apr 24, 2023
1 parent a9ca2d8 commit 904cd6d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/vdom/create-element.ts
Expand Up @@ -157,6 +157,17 @@ function applyNS(vnode, ns, force?: boolean) {
}
}
}

// #11315
if (isObject(vnode.componentOptions) && isDef(vnode.componentOptions.children)) {
for (var i = 0, l = vnode.componentOptions.children.length; i < l; i++) {
var child = vnode.componentOptions.children[i]
if (isDef(child.tag) && (
isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
applyNS(child, ns, force)
}
}
}
}

// ref #5318
Expand Down
43 changes: 43 additions & 0 deletions test/unit/modules/vdom/create-element.spec.ts
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

0 comments on commit 904cd6d

Please sign in to comment.