Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion packages/server-renderer/__tests__/ssrSlot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createApp } from 'vue'
import { createApp, defineAsyncComponent, h } from 'vue'
import { renderToString } from '../src/renderToString'

const components = {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/server-renderer/src/helpers/ssrRenderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function ssrRenderSlotInner(
parentComponent,
slotScopeId ? ' ' + slotScopeId : '',
)
if (isArray(ret)) {
if (isArray(ret) && slotBuffer.length === 0) {
const validSlotContent = ensureValidVNode(ret)
if (validSlotContent) {
// normal slot
Expand Down