Skip to content

Commit 21454ce

Browse files
committed
test: add test case
1 parent 637409a commit 21454ce

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

packages/server-renderer/__tests__/ssrDirectives.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,38 @@ describe('ssr: directives', () => {
6666
),
6767
).toBe(`<div style="color:red;font-size:12;display:none;"></div>`)
6868
})
69+
70+
test('with component', async () => {
71+
expect(
72+
await renderToString(
73+
createApp({
74+
components: {
75+
Foo: {
76+
template: `<div><span v-bind="$attrs"></span></div>`,
77+
},
78+
},
79+
data: () => ({ show: false }),
80+
template: `<Foo v-show="show"/>`,
81+
}),
82+
),
83+
).toBe(`<div style="display:none;"><span></span></div>`)
84+
})
85+
86+
test('with dynamic component', async () => {
87+
expect(
88+
await renderToString(
89+
createApp({
90+
components: {
91+
Foo: {
92+
template: `<div><span v-bind="$attrs"></span></div>`,
93+
},
94+
},
95+
data: () => ({ show: false }),
96+
template: `<component is="Foo" v-show="show"/>`,
97+
}),
98+
),
99+
).toBe(`<div style="display:none;"><span></span></div>`)
100+
})
69101
})
70102

71103
describe('template v-model', () => {

packages/server-renderer/src/helpers/ssrRenderComponent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export function ssrRenderComponent(
1313
children: Slots | SSRSlots | null = null,
1414
parentComponent: ComponentInternalInstance | null = null,
1515
slotScopeId?: string,
16+
vShowValue?: Props,
1617
): SSRBuffer | Promise<SSRBuffer> {
1718
return renderComponentVNode(
1819
createVNode(comp, props, children),
1920
parentComponent,
2021
slotScopeId,
22+
vShowValue,
2123
)
2224
}

packages/server-renderer/src/render.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function renderComponentVNode(
9292
vnode: VNode,
9393
parentComponent: ComponentInternalInstance | null = null,
9494
slotScopeId?: string,
95-
vShowValue?: Props | null,
95+
vShowValue?: Props,
9696
): SSRBuffer | Promise<SSRBuffer> {
9797
const instance = (vnode.component = createComponentInstance(
9898
vnode,
@@ -128,7 +128,7 @@ export function renderComponentVNode(
128128
function renderComponentSubTree(
129129
instance: ComponentInternalInstance,
130130
slotScopeId?: string,
131-
vShowValue?: Props | null,
131+
vShowValue?: Props,
132132
): SSRBuffer | Promise<SSRBuffer> {
133133
if (__DEV__) pushWarningContext(instance.vnode)
134134
const comp = instance.type as Component
@@ -235,7 +235,7 @@ export function renderVNode(
235235
vnode: VNode,
236236
parentComponent: ComponentInternalInstance,
237237
slotScopeId?: string,
238-
vShowValue?: Props | null,
238+
vShowValue?: Props,
239239
): void {
240240
const { type, shapeFlag, children, dirs, props } = vnode
241241
if (dirs) {

0 commit comments

Comments
 (0)