import { createApp, 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( `
` + `
` + `
` ) }) })