fix(ssr): hydration for transition wrapper components with empty slot content (#5995)
fix #5991
This commit is contained in:
@@ -113,4 +113,32 @@ describe('ssr: slot', () => {
|
||||
`<div><!--[--><!--[--><div>one</div><div>two</div><!--]--><!--]--></div>`
|
||||
)
|
||||
})
|
||||
|
||||
test('transition slot', async () => {
|
||||
expect(
|
||||
await renderToString(
|
||||
createApp({
|
||||
components: {
|
||||
one: {
|
||||
template: `<transition><slot/></transition>`
|
||||
}
|
||||
},
|
||||
template: `<one><div v-if="false">foo</div></one>`
|
||||
})
|
||||
)
|
||||
).toBe(`<!---->`)
|
||||
|
||||
expect(
|
||||
await renderToString(
|
||||
createApp({
|
||||
components: {
|
||||
one: {
|
||||
template: `<transition><slot/></transition>`
|
||||
}
|
||||
},
|
||||
template: `<one><div v-if="true">foo</div></one>`
|
||||
})
|
||||
)
|
||||
).toBe(`<div>foo</div>`)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -40,7 +40,8 @@ export function ssrRenderSlotInner(
|
||||
fallbackRenderFn: (() => void) | null,
|
||||
push: PushFn,
|
||||
parentComponent: ComponentInternalInstance,
|
||||
slotScopeId?: string
|
||||
slotScopeId?: string,
|
||||
transition?: boolean
|
||||
) {
|
||||
const slotFn = slots[slotName]
|
||||
if (slotFn) {
|
||||
@@ -61,10 +62,14 @@ export function ssrRenderSlotInner(
|
||||
// ssr slot.
|
||||
// check if the slot renders all comments, in which case use the fallback
|
||||
let isEmptySlot = true
|
||||
for (let i = 0; i < slotBuffer.length; i++) {
|
||||
if (!isComment(slotBuffer[i])) {
|
||||
isEmptySlot = false
|
||||
break
|
||||
if (transition) {
|
||||
isEmptySlot = false
|
||||
} else {
|
||||
for (let i = 0; i < slotBuffer.length; i++) {
|
||||
if (!isComment(slotBuffer[i])) {
|
||||
isEmptySlot = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isEmptySlot) {
|
||||
|
||||
Reference in New Issue
Block a user