]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(keep-alive): fix keep-alive rendering when placed in vnode branch
authorBulat Aykaev <mefcorvi@gmail.com>
Mon, 28 Mar 2022 13:05:38 +0000 (17:05 +0400)
committerEvan You <yyx990803@gmail.com>
Wed, 18 May 2022 02:48:58 +0000 (10:48 +0800)
fix #4817

packages/runtime-core/src/components/KeepAlive.ts
packages/server-renderer/__tests__/render.spec.ts

index 4b2c7288581ef43b4ce58297cc4c7a0bf60c4f4e..3fec48140fc441467ce9a1637f51791c64d2bcdb 100644 (file)
@@ -96,8 +96,11 @@ const KeepAliveImpl: ComponentOptions = {
 
     // if the internal renderer is not registered, it indicates that this is server-side rendering,
     // for KeepAlive, we just need to render its children
-    if (!sharedContext.renderer) {
-      return slots.default
+    if (__SSR__ && !sharedContext.renderer) {
+      return () => {
+        const children = slots.default && slots.default()
+        return children && children.length === 1 ? children[0] : children
+      }
     }
 
     const cache: Cache = new Map()
index 96e16750917586e7c63d4b09012d00e99feff068..4fd781fcae255b2c9829a28a2b041ed1959b6d35 100644 (file)
@@ -676,7 +676,7 @@ function testRender(type: string, render: typeof renderToString) {
           render: () => h('p', 'hello')
         }
         expect(await render(h(KeepAlive, () => h(MyComp)))).toBe(
-          `<!--[--><p>hello</p><!--]-->`
+          `<p>hello</p>`
         )
       })