Skip to content

Commit 8f82270

Browse files
committed
fix(ssr): handle transition slots rendering by adding comment nodes
1 parent c4e3d00 commit 8f82270

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

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

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,38 @@ describe('ssr: slot', () => {
111111
})
112112

113113
test('transition slot', async () => {
114+
const ReusableTransition = {
115+
template: `<transition><slot/></transition>`,
116+
}
117+
118+
const ReusableTransitionWithAppear = {
119+
template: `<transition appear><slot/></transition>`,
120+
}
121+
114122
expect(
115123
await renderToString(
116124
createApp({
117125
components: {
118-
one: {
119-
template: `<transition><slot/></transition>`,
120-
},
126+
one: ReusableTransition,
121127
},
122128
template: `<one><div v-if="false">foo</div></one>`,
123129
}),
124130
),
125131
).toBe(`<!---->`)
126132

133+
expect(await renderToString(createApp(ReusableTransition))).toBe(`<!---->`)
134+
135+
expect(await renderToString(createApp(ReusableTransitionWithAppear))).toBe(
136+
`<template><!----></template>`,
137+
)
138+
127139
expect(
128140
await renderToString(
129141
createApp({
130-
template: `<transition><slot/></transition>`,
142+
components: {
143+
one: ReusableTransition,
144+
},
145+
template: `<one><slot/></one>`,
131146
}),
132147
),
133148
).toBe(`<!---->`)
@@ -136,43 +151,66 @@ describe('ssr: slot', () => {
136151
await renderToString(
137152
createApp({
138153
components: {
139-
one: {
140-
template: `<transition><slot/></transition>`,
141-
},
154+
one: ReusableTransitionWithAppear,
142155
},
143156
template: `<one><slot/></one>`,
144157
}),
145158
),
159+
).toBe(`<template><!----></template>`)
160+
161+
expect(
162+
await renderToString(
163+
createApp({
164+
render() {
165+
return h(ReusableTransition, null, {
166+
default: () => null,
167+
})
168+
},
169+
}),
170+
),
146171
).toBe(`<!---->`)
147172

148173
expect(
149174
await renderToString(
150175
createApp({
151-
template: `<transition appear><slot/></transition>`,
176+
render() {
177+
return h(ReusableTransitionWithAppear, null, {
178+
default: () => null,
179+
})
180+
},
152181
}),
153182
),
154183
).toBe(`<template><!----></template>`)
155184

156185
expect(
157186
await renderToString(
158187
createApp({
159-
components: {
160-
one: {
161-
template: `<transition appear><slot/></transition>`,
162-
},
188+
render() {
189+
return h(ReusableTransitionWithAppear, null, {
190+
default: () => [],
191+
})
163192
},
164-
template: `<one><slot/></one>`,
165193
}),
166194
),
167195
).toBe(`<template><!----></template>`)
168196

197+
expect(
198+
await renderToString(
199+
createApp({
200+
render() {
201+
return h(ReusableTransition, null, {
202+
default: () => [],
203+
})
204+
},
205+
}),
206+
),
207+
).toBe(`<!---->`)
208+
169209
expect(
170210
await renderToString(
171211
createApp({
172212
components: {
173-
one: {
174-
template: `<transition><slot/></transition>`,
175-
},
213+
one: ReusableTransition,
176214
},
177215
template: `<one><div v-if="true">foo</div></one>`,
178216
}),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export function ssrRenderSlotInner(
7474
)
7575
} else if (fallbackRenderFn) {
7676
fallbackRenderFn()
77+
} else if (transition) {
78+
push(`<!---->`)
7779
}
7880
} else {
7981
// ssr slot.

0 commit comments

Comments
 (0)