-import { createVaporApp } from '../src'
+import { createVaporApp, vaporInteropPlugin } from '../src'
import type { App } from '@vue/runtime-dom'
import type { VaporComponent, VaporComponentInstance } from '../src/component'
import type { RawProps } from '../src/componentProps'
+import { type Component, createApp } from 'vue'
export interface RenderContext {
component: VaporComponent
return define
}
+
+export interface InteropRenderContext {
+ mount: (container?: string | ParentNode) => InteropRenderContext
+ render: (
+ props?: RawProps,
+ container?: string | ParentNode,
+ ) => InteropRenderContext
+ html: () => string
+}
+
+export function makeInteropRender(): (comp: Component) => InteropRenderContext {
+ let host: HTMLElement
+ beforeEach(() => {
+ host = document.createElement('div')
+ })
+ afterEach(() => {
+ host.remove()
+ })
+
+ function define(comp: Component) {
+ let app: App
+ function render(
+ props: RawProps | undefined = undefined,
+ container: string | ParentNode = host,
+ ) {
+ app?.unmount()
+ app = createApp(comp, props)
+ app.use(vaporInteropPlugin)
+ return mount(container)
+ }
+
+ function mount(container: string | ParentNode = host) {
+ app.mount(container)
+ return res()
+ }
+
+ function html() {
+ return host.innerHTML
+ }
+
+ const res = () => ({
+ mount,
+ render,
+ html,
+ })
+
+ return res()
+ }
+
+ return define
+}
--- /dev/null
+import { h } from 'vue'
+import { createSlot, defineVaporComponent, template } from '../src'
+import { makeInteropRender } from './_utils'
+
+const define = makeInteropRender()
+
+describe('vdomInterop', () => {
+ describe('slots', () => {
+ test('should render slot fallback if no slot content is provided', () => {
+ const VaporChild = defineVaporComponent({
+ setup() {
+ const n0 = createSlot('default', null, () => {
+ const n2 = template('<div>hi</div>')()
+ return n2
+ })
+ return n0
+ },
+ })
+
+ const { html } = define({
+ setup() {
+ return () => h(VaporChild as any)
+ },
+ }).render()
+
+ expect(html()).toBe('<div>hi</div>')
+ })
+ })
+})
frag.insert = (parentNode, anchor) => {
if (!isMounted) {
renderEffect(() => {
- const vnode = renderSlot(
- slotsRef.value,
- isFunction(name) ? name() : name,
- props,
- )
- if ((vnode.children as any[]).length) {
- if (fallbackNodes) {
- remove(fallbackNodes, parentNode)
- fallbackNodes = undefined
- }
- internals.p(
- oldVNode,
- vnode,
- parentNode,
- anchor,
- parentComponent as any,
+ if (slotsRef.value) {
+ const vnode = renderSlot(
+ slotsRef.value,
+ isFunction(name) ? name() : name,
+ props,
)
- oldVNode = vnode
+ if ((vnode.children as any[]).length) {
+ if (fallbackNodes) {
+ remove(fallbackNodes, parentNode)
+ fallbackNodes = undefined
+ }
+ internals.p(
+ oldVNode,
+ vnode,
+ parentNode,
+ anchor,
+ parentComponent as any,
+ )
+ oldVNode = vnode
+ }
} else {
if (fallback && !fallbackNodes) {
// mount fallback