expect(spy).toHaveBeenCalled()
})
+ test('SVG as a mount container', () => {
+ const svgContainer = document.createElement('svg')
+ svgContainer.innerHTML = '<g></g>'
+ const app = createSSRApp({
+ render: () => h('g')
+ })
+
+ expect(
+ (app.mount(svgContainer).$.subTree as VNode<Node, Element> & {
+ el: Element
+ }).el instanceof SVGElement
+ )
+ })
+
describe('mismatch handling', () => {
test('text node', () => {
const { container } = mountWithHydration(`foo`, () => 'bar')
directive(name: string, directive: Directive): this
mount(
rootContainer: HostElement | string,
- isHydrate?: boolean
+ isHydrate?: boolean,
+ isSVG?: boolean
): ComponentPublicInstance
unmount(): void
provide<T>(key: InjectionKey<T> | string, value: T): this
return app
},
- mount(rootContainer: HostElement, isHydrate?: boolean): any {
+ mount(
+ rootContainer: HostElement,
+ isHydrate?: boolean,
+ isSVG?: boolean
+ ): any {
if (!isMounted) {
const vnode = createVNode(
rootComponent as ConcreteComponent,
// HMR root reload
if (__DEV__) {
context.reload = () => {
- render(cloneVNode(vnode), rootContainer)
+ render(cloneVNode(vnode), rootContainer, isSVG)
}
}
if (isHydrate && hydrate) {
hydrate(vnode as VNode<Node, Element>, rootContainer as any)
} else {
- render(vnode, rootContainer)
+ render(vnode, rootContainer, isSVG)
}
isMounted = true
app._container = rootContainer
export type RootRenderFunction<HostElement = RendererElement> = (
vnode: VNode | null,
- container: HostElement
+ container: HostElement,
+ isSVG?: boolean
) => void
export interface RendererOptions<
return hostNextSibling((vnode.anchor || vnode.el)!)
}
- const render: RootRenderFunction = (vnode, container) => {
+ const render: RootRenderFunction = (vnode, container, isSVG) => {
if (vnode == null) {
if (container._vnode) {
unmount(container._vnode, null, null, true)
}
} else {
- patch(container._vnode || null, vnode, container)
+ patch(container._vnode || null, vnode, container, null, null, null, isSVG)
}
flushPostFlushCbs()
container._vnode = vnode
--- /dev/null
+import { createApp, h } from '../src'
+
+describe('createApp for dom', () => {
+ // #2926
+ test('mount to SVG container', () => {
+ const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
+ createApp({
+ render() {
+ return h('g')
+ }
+ }).mount(root)
+ expect(root.children.length).toBe(1)
+ expect(root.children[0] instanceof SVGElement).toBe(true)
+ })
+})
}
// clear content before mounting
container.innerHTML = ''
- const proxy = mount(container)
+ const proxy = mount(container, false, container instanceof SVGElement)
if (container instanceof Element) {
container.removeAttribute('v-cloak')
container.setAttribute('data-v-app', '')
app.mount = (containerOrSelector: Element | ShadowRoot | string): any => {
const container = normalizeContainer(containerOrSelector)
if (container) {
- return mount(container, true)
+ return mount(container, true, container instanceof SVGElement)
}
}