Skip to content

Commit 0841b9b

Browse files
mefcorviyyx990803
authored andcommitted
fix(keep-alive): fix keep-alive rendering when placed in vnode branch
fix #4817
1 parent 3705b3b commit 0841b9b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/runtime-core/src/components/KeepAlive.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ const KeepAliveImpl: ComponentOptions = {
9696

9797
// if the internal renderer is not registered, it indicates that this is server-side rendering,
9898
// for KeepAlive, we just need to render its children
99-
if (!sharedContext.renderer) {
100-
return slots.default
99+
if (__SSR__ && !sharedContext.renderer) {
100+
return () => {
101+
const children = slots.default && slots.default()
102+
return children && children.length === 1 ? children[0] : children
103+
}
101104
}
102105

103106
const cache: Cache = new Map()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ function testRender(type: string, render: typeof renderToString) {
676676
render: () => h('p', 'hello')
677677
}
678678
expect(await render(h(KeepAlive, () => h(MyComp)))).toBe(
679-
`<!--[--><p>hello</p><!--]-->`
679+
`<p>hello</p>`
680680
)
681681
})
682682

0 commit comments

Comments
 (0)