2
0
daiwei 1 жил өмнө
parent
commit
21454ce627

+ 32 - 0
packages/server-renderer/__tests__/ssrDirectives.spec.ts

@@ -66,6 +66,38 @@ describe('ssr: directives', () => {
         ),
       ).toBe(`<div style="color:red;font-size:12;display:none;"></div>`)
     })
+
+    test('with component', async () => {
+      expect(
+        await renderToString(
+          createApp({
+            components: {
+              Foo: {
+                template: `<div><span v-bind="$attrs"></span></div>`,
+              },
+            },
+            data: () => ({ show: false }),
+            template: `<Foo v-show="show"/>`,
+          }),
+        ),
+      ).toBe(`<div style="display:none;"><span></span></div>`)
+    })
+
+    test('with dynamic component', async () => {
+      expect(
+        await renderToString(
+          createApp({
+            components: {
+              Foo: {
+                template: `<div><span v-bind="$attrs"></span></div>`,
+              },
+            },
+            data: () => ({ show: false }),
+            template: `<component is="Foo" v-show="show"/>`,
+          }),
+        ),
+      ).toBe(`<div style="display:none;"><span></span></div>`)
+    })
   })
 
   describe('template v-model', () => {

+ 2 - 0
packages/server-renderer/src/helpers/ssrRenderComponent.ts

@@ -13,10 +13,12 @@ export function ssrRenderComponent(
   children: Slots | SSRSlots | null = null,
   parentComponent: ComponentInternalInstance | null = null,
   slotScopeId?: string,
+  vShowValue?: Props,
 ): SSRBuffer | Promise<SSRBuffer> {
   return renderComponentVNode(
     createVNode(comp, props, children),
     parentComponent,
     slotScopeId,
+    vShowValue,
   )
 }

+ 3 - 3
packages/server-renderer/src/render.ts

@@ -92,7 +92,7 @@ export function renderComponentVNode(
   vnode: VNode,
   parentComponent: ComponentInternalInstance | null = null,
   slotScopeId?: string,
-  vShowValue?: Props | null,
+  vShowValue?: Props,
 ): SSRBuffer | Promise<SSRBuffer> {
   const instance = (vnode.component = createComponentInstance(
     vnode,
@@ -128,7 +128,7 @@ export function renderComponentVNode(
 function renderComponentSubTree(
   instance: ComponentInternalInstance,
   slotScopeId?: string,
-  vShowValue?: Props | null,
+  vShowValue?: Props,
 ): SSRBuffer | Promise<SSRBuffer> {
   if (__DEV__) pushWarningContext(instance.vnode)
   const comp = instance.type as Component
@@ -235,7 +235,7 @@ export function renderVNode(
   vnode: VNode,
   parentComponent: ComponentInternalInstance,
   slotScopeId?: string,
-  vShowValue?: Props | null,
+  vShowValue?: Props,
 ): void {
   const { type, shapeFlag, children, dirs, props } = vnode
   if (dirs) {