]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: add test case
authordaiwei <daiwei521@126.com>
Tue, 10 Dec 2024 01:02:28 +0000 (09:02 +0800)
committerdaiwei <daiwei521@126.com>
Tue, 10 Dec 2024 01:02:28 +0000 (09:02 +0800)
packages/server-renderer/__tests__/ssrDirectives.spec.ts
packages/server-renderer/src/helpers/ssrRenderComponent.ts
packages/server-renderer/src/render.ts

index dfdebe971f55888229ccf155148a17863ab93799..f0a947f49bd68fafe4a1d0b794774855c0533a8a 100644 (file)
@@ -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', () => {
index 4277bb1747e5eabe1f220f82bd7af183d7d597cd..94ec2d50f77c7c0cdbd025ae2579dbca17ca1e33 100644 (file)
@@ -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,
   )
 }
index e34072e24221a4e6b4270c9b14de99b6d28f5cef..af95a2fbc6e2654ba00fac8d25081ebab8e50888 100644 (file)
@@ -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) {