Skip to content

Commit 4c74302

Browse files
authoredMay 30, 2024··
fix(ssr): fix the bug that multi slot scope id does not work on component (#6100)
close #6093
1 parent b9ca202 commit 4c74302

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed
 

‎packages/server-renderer/__tests__/ssrScopeId.spec.ts

+90
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,94 @@ describe('ssr: scopedId runtime behavior', () => {
179179
const result = await renderToString(createApp(Comp)) // output: `<div></div>`
180180
expect(result).toBe(`<div parent></div>`)
181181
})
182+
183+
// #6093
184+
test(':slotted on forwarded slots on component', async () => {
185+
const Wrapper = {
186+
__scopeId: 'wrapper',
187+
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
188+
// <div class="wrapper"><slot/></div>
189+
push(
190+
`<div${ssrRenderAttrs(
191+
mergeProps({ class: 'wrapper' }, attrs),
192+
)} wrapper>`,
193+
)
194+
ssrRenderSlot(
195+
ctx.$slots,
196+
'default',
197+
{},
198+
null,
199+
push,
200+
parent,
201+
'wrapper-s',
202+
)
203+
push(`</div>`)
204+
},
205+
}
206+
207+
const Slotted = {
208+
__scopeId: 'slotted',
209+
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
210+
// <Wrapper><slot/></Wrapper>
211+
push(
212+
ssrRenderComponent(
213+
Wrapper,
214+
attrs,
215+
{
216+
default: withCtx(
217+
(_: any, push: any, parent: any, scopeId: string) => {
218+
ssrRenderSlot(
219+
ctx.$slots,
220+
'default',
221+
{},
222+
null,
223+
push,
224+
parent,
225+
'slotted-s' + scopeId,
226+
)
227+
},
228+
),
229+
_: 1,
230+
} as any,
231+
parent,
232+
),
233+
)
234+
},
235+
}
236+
237+
const Child = {
238+
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
239+
push(`<div${ssrRenderAttrs(attrs)}></div>`)
240+
},
241+
}
242+
243+
const Root = {
244+
__scopeId: 'root',
245+
// <Slotted><Child></Child></Slotted>
246+
ssrRender: (_: any, push: any, parent: any, attrs: any) => {
247+
push(
248+
ssrRenderComponent(
249+
Slotted,
250+
attrs,
251+
{
252+
default: withCtx(
253+
(_: any, push: any, parent: any, scopeId: string) => {
254+
push(ssrRenderComponent(Child, null, null, parent, scopeId))
255+
},
256+
),
257+
_: 1,
258+
} as any,
259+
parent,
260+
),
261+
)
262+
},
263+
}
264+
265+
const result = await renderToString(createApp(Root))
266+
expect(result).toBe(
267+
`<div class="wrapper" root slotted wrapper>` +
268+
`<!--[--><!--[--><div root slotted-s wrapper-s></div><!--]--><!--]-->` +
269+
`</div>`,
270+
)
271+
})
182272
})

‎packages/server-renderer/src/render.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ function renderComponentSubTree(
181181

182182
if (slotScopeId) {
183183
if (!hasCloned) attrs = { ...attrs }
184-
attrs![slotScopeId.trim()] = ''
184+
const slotScopeIdList = slotScopeId.trim().split(' ')
185+
for (let i = 0; i < slotScopeIdList.length; i++) {
186+
attrs![slotScopeIdList[i]] = ''
187+
}
185188
}
186189

187190
// set current rendering instance for asset resolution

0 commit comments

Comments
 (0)
Please sign in to comment.