)
}
-async function testHydrationInterop(
+async function testWithVaporApp(
code: string,
components?: Record<string, string | { code: string; vapor: boolean }>,
data?: any,
) {
- return testHydration(code, components, data, { interop: true, vapor: false })
+ return testHydration(code, components, data, {
+ isVaporApp: true,
+ interop: true,
+ })
+}
+
+async function testWithVDOMApp(
+ code: string,
+ components?: Record<string, string | { code: string; vapor: boolean }>,
+ data?: any,
+) {
+ return testHydration(code, components, data, {
+ isVaporApp: false,
+ interop: true,
+ })
}
async function testHydration(
code: string,
components: Record<string, string | { code: string; vapor: boolean }> = {},
data: any = ref('foo'),
- { interop = false, vapor = true } = {},
+ { isVaporApp = true, interop = false } = {},
) {
const ssrComponents: any = {}
const clientComponents: any = {}
})
}
- const serverComp = compile(code, data, ssrComponents, { vapor, ssr: true })
+ const serverComp = compile(code, data, ssrComponents, {
+ vapor: isVaporApp,
+ ssr: true,
+ })
const html = await VueServerRenderer.renderToString(
runtimeDom.createSSRApp(serverComp),
)
container.innerHTML = html
const clientComp = compile(code, data, clientComponents, {
- vapor,
+ vapor: isVaporApp,
ssr: false,
})
let app
- if (interop) {
+ if (isVaporApp) {
+ app = createVaporSSRApp(clientComp)
+ } else {
app = runtimeDom.createSSRApp(clientComp)
+ }
+
+ if (interop) {
app.use(runtimeVapor.vaporInteropPlugin)
- } else {
- app = createVaporSSRApp(clientComp)
}
+
app.mount(container)
return { data, container }
}
})
describe('VDOM interop', () => {
- test('basic vapor component', async () => {
+ test('basic render vapor component', async () => {
const data = ref(true)
- const { container } = await testHydrationInterop(
+ const { container } = await testWithVDOMApp(
`<script setup>const data = _data; const components = _components;</script>
<template>
<components.VaporChild/>
test('nested components (VDOM -> Vapor -> VDOM)', async () => {
const data = ref(true)
- const { container } = await testHydrationInterop(
+ const { container } = await testWithVDOMApp(
`<script setup>const data = _data; const components = _components;</script>
<template>
<components.VaporChild/>
test('nested components (VDOM -> Vapor -> VDOM (with slot fallback))', async () => {
const data = ref(true)
- const { container } = await testHydrationInterop(
+ const { container } = await testWithVDOMApp(
`<script setup>const data = _data; const components = _components;</script>
<template>
<components.VaporChild/>
)
})
- test('nested components (VDOM -> Vapor(with slot fallback) -> VDOM)', async () => {
+ test('nested components (VDOM -> Vapor(with slot content) -> VDOM)', async () => {
const data = ref(true)
- const { container } = await testHydrationInterop(
+ const { container } = await testWithVDOMApp(
`<script setup>const data = _data; const components = _components;</script>
<template>
<components.VaporChild/>
)
})
- test('nested components (VDOM -> Vapor(with slot fallback) -> Vapor)', async () => {
+ test('nested components (VDOM -> Vapor(with slot content) -> Vapor)', async () => {
const data = ref(true)
- const { container } = await testHydrationInterop(
+ const { container } = await testWithVDOMApp(
`<script setup>const data = _data; const components = _components;</script>
<template>
<components.VaporChild/>
test('vapor slot render vdom component', async () => {
const data = ref(true)
- const { container } = await testHydrationInterop(
+ const { container } = await testWithVDOMApp(
`<script setup>const data = _data; const components = _components;</script>
<template>
<components.VaporChild>
`,
)
})
+
+ test('vapor slot render vdom component (render function)', async () => {
+ const data = ref(true)
+ const { container } = await testWithVaporApp(
+ `<script setup>
+ import { h } from 'vue'
+ const data = _data; const components = _components;
+ const VdomChild = {
+ setup() {
+ return () => h('div', null, [h('div', [String(data.value)])])
+ }
+ }
+ </script>
+ <template>
+ <components.VaporChild>
+ <VdomChild/>
+ </components.VaporChild>
+ </template>`,
+ {
+ VaporChild: {
+ code: `<template><div><slot/></div></template>`,
+ vapor: true,
+ },
+ },
+ data,
+ )
+
+ expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
+ `
+ "<div>
+ <!--[--><div><div>true</div></div><!--]-->
+ <!--slot--></div>"
+ `,
+ )
+
+ expect(`Hydration node mismatch`).not.toHaveBeenWarned()
+
+ data.value = false
+ await nextTick()
+ expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
+ `
+ "<div>
+ <!--[--><div><div>false</div></div><!--]-->
+ <!--slot--></div>"
+ `,
+ )
+ })
})