import { createApp, h, mergeProps, withCtx } from 'vue'
import { renderToString } from '../src/renderToString'
import { ssrRenderComponent, ssrRenderAttrs, ssrRenderSlot } from '../src'
describe('ssr: scopedId runtime behavior', () => {
test('id on component root', async () => {
const Child = {
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
push(`
`)
}
}
const Comp = {
__scopeId: 'parent',
ssrRender: (ctx: any, push: any, parent: any) => {
push(ssrRenderComponent(Child), null, null, parent)
}
}
const result = await renderToString(createApp(Comp))
expect(result).toBe(``)
})
test('id and :slotted on component root', async () => {
const Child = {
//
ssrRender: (_: any, push: any, _parent: any, attrs: any) => {
push(``)
}
}
const Wrapper = {
__scopeId: 'wrapper',
ssrRender: (ctx: any, push: any, parent: any) => {
//
ssrRenderSlot(
ctx.$slots,
'default',
{},
null,
push,
parent,
'wrapper-s'
)
}
}
const Comp = {
__scopeId: 'parent',
ssrRender: (_: any, push: any, parent: any) => {
//
push(
ssrRenderComponent(
Wrapper,
null,
{
default: withCtx(
(_: any, push: any, parent: any, scopeId: string) => {
push(ssrRenderComponent(Child, null, null, parent, scopeId))
}
),
_: 1
} as any,
parent
)
)
}
}
const result = await renderToString(createApp(Comp))
expect(result).toBe(``)
})
// #2892
test(':slotted on forwarded slots', async () => {
const Wrapper = {
__scopeId: 'wrapper',
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
//
push(
``
)
ssrRenderSlot(
ctx.$slots,
'default',
{},
null,
push,
parent,
'wrapper-s'
)
push(`
`)
}
}
const Slotted = {
__scopeId: 'slotted',
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
//
push(
ssrRenderComponent(
Wrapper,
attrs,
{
default: withCtx(
(_: any, push: any, parent: any, scopeId: string) => {
ssrRenderSlot(
ctx.$slots,
'default',
{},
null,
push,
parent,
'slotted-s' + scopeId
)
}
),
_: 1
} as any,
parent
)
)
}
}
const Root = {
__scopeId: 'root',
//
ssrRender: (_: any, push: any, parent: any, attrs: any) => {
push(
ssrRenderComponent(
Slotted,
attrs,
{
default: withCtx(
(_: any, push: any, parent: any, scopeId: string) => {
push(``)
}
),
_: 1
} as any,
parent
)
)
}
}
const result = await renderToString(createApp(Root))
expect(result).toBe(
``
)
})
// #3513
test('scopeId inheritance across ssr-compiled andn on-ssr compiled parent chain', async () => {
const Child = {
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
push(``)
}
}
const Middle = {
render() {
return h(Child)
}
}
const Comp = {
__scopeId: 'parent',
ssrRender: (ctx: any, push: any, parent: any) => {
push(ssrRenderComponent(Middle, null, null, parent))
}
}
const result = await renderToString(createApp(Comp)) // output: ``
expect(result).toBe(``)
})
})