Skip to content

Commit 2206cd2

Browse files
authored
fix(ssr): properly init slots during ssr rendering (#12441)
close #12438
1 parent 5e37dd0 commit 2206cd2

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/runtime-core/src/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ export function setupComponent(
806806
const { props, children } = instance.vnode
807807
const isStateful = isStatefulComponent(instance)
808808
initProps(instance, props, isStateful, isSSR)
809-
initSlots(instance, children, optimized)
809+
initSlots(instance, children, optimized || isSSR)
810810

811811
const setupResult = isStateful
812812
? setupStatefulComponent(instance, isSSR)

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createApp } from 'vue'
1+
import { createApp, defineAsyncComponent, h } from 'vue'
22
import { renderToString } from '../src/renderToString'
33

44
const components = {
@@ -154,6 +154,38 @@ describe('ssr: slot', () => {
154154
).toBe(`<div><p>1</p><p>2</p></div>`)
155155
})
156156

157+
// #12438
158+
test('async component slot with v-if true', async () => {
159+
const Layout = defineAsyncComponent(() =>
160+
Promise.resolve({
161+
template: `<div><slot name="header">default header</slot></div>`,
162+
}),
163+
)
164+
const LayoutLoader = {
165+
setup(_: any, context: any) {
166+
return () => h(Layout, {}, context.slots)
167+
},
168+
}
169+
expect(
170+
await renderToString(
171+
createApp({
172+
components: {
173+
LayoutLoader,
174+
},
175+
template: `
176+
<Suspense>
177+
<LayoutLoader>
178+
<template v-if="true" #header>
179+
new header
180+
</template>
181+
</LayoutLoader>
182+
</Suspense>
183+
`,
184+
}),
185+
),
186+
).toBe(`<div><!--[--> new header <!--]--></div>`)
187+
})
188+
157189
// #11326
158190
test('dynamic component slot', async () => {
159191
expect(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy