Skip to content

Commit

Permalink
fix(keep-alive): fix keep-alive rendering when placed in vnode branch
Browse files Browse the repository at this point in the history
fix #4817
  • Loading branch information
mefcorvi authored and yyx990803 committed May 18, 2022
1 parent 3705b3b commit 0841b9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/runtime-core/src/components/KeepAlive.ts
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion packages/server-renderer/__tests__/render.spec.ts
Expand Up @@ -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>`
)
})

Expand Down

0 comments on commit 0841b9b

Please sign in to comment.