fix(ssr): properly init slots during ssr rendering (#12441)

close #12438
This commit is contained in:
edison 2025-05-02 17:48:03 +08:00 committed by GitHub
parent 5e37dd0095
commit 2206cd235a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View File

@ -806,7 +806,7 @@ export function setupComponent(
const { props, children } = instance.vnode
const isStateful = isStatefulComponent(instance)
initProps(instance, props, isStateful, isSSR)
initSlots(instance, children, optimized)
initSlots(instance, children, optimized || isSSR)
const setupResult = isStateful
? setupStatefulComponent(instance, isSSR)

View File

@ -1,4 +1,4 @@
import { createApp } from 'vue'
import { createApp, defineAsyncComponent, h } from 'vue'
import { renderToString } from '../src/renderToString'
const components = {
@ -154,6 +154,38 @@ describe('ssr: slot', () => {
).toBe(`<div><p>1</p><p>2</p></div>`)
})
// #12438
test('async component slot with v-if true', async () => {
const Layout = defineAsyncComponent(() =>
Promise.resolve({
template: `<div><slot name="header">default header</slot></div>`,
}),
)
const LayoutLoader = {
setup(_: any, context: any) {
return () => h(Layout, {}, context.slots)
},
}
expect(
await renderToString(
createApp({
components: {
LayoutLoader,
},
template: `
<Suspense>
<LayoutLoader>
<template v-if="true" #header>
new header
</template>
</LayoutLoader>
</Suspense>
`,
}),
),
).toBe(`<div><!--[--> new header <!--]--></div>`)
})
// #11326
test('dynamic component slot', async () => {
expect(