Skip to content

Commit 0160264

Browse files
authored
fix(ssr): avoid rendering transition-group slot content as a fragment (#9961)
close #9933
1 parent 25f212d commit 0160264

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,20 @@ describe('ssr: slot', () => {
137137
),
138138
).toBe(`<div>foo</div>`)
139139
})
140+
141+
// #9933
142+
test('transition-group slot', async () => {
143+
expect(
144+
await renderToString(
145+
createApp({
146+
components: {
147+
one: {
148+
template: `<TransitionGroup tag="div"><slot/></TransitionGroup>`,
149+
},
150+
},
151+
template: `<one><p v-for="i in 2">{{i}}</p></one>`,
152+
}),
153+
),
154+
).toBe(`<div><p>1</p><p>2</p></div>`)
155+
})
140156
})

packages/server-renderer/src/helpers/ssrRenderSlot.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,23 @@ export function ssrRenderSlotInner(
8282
fallbackRenderFn()
8383
}
8484
} else {
85-
for (let i = 0; i < slotBuffer.length; i++) {
85+
// #9933
86+
// Although we handle Transition/TransitionGroup in the transform stage
87+
// without rendering it as a fragment, the content passed into the slot
88+
// may still be a fragment.
89+
// Therefore, here we need to avoid rendering it as a fragment again.
90+
let start = 0
91+
let end = slotBuffer.length
92+
if (
93+
transition &&
94+
slotBuffer[0] === '<!--[-->' &&
95+
slotBuffer[end - 1] === '<!--]-->'
96+
) {
97+
start++
98+
end--
99+
}
100+
101+
for (let i = start; i < end; i++) {
86102
push(slotBuffer[i])
87103
}
88104
}

0 commit comments

Comments
 (0)