From: mmis1000 <2993977+mmis1000@users.noreply.github.com>
Date: Thu, 30 May 2024 09:43:34 +0000 (+0800)
Subject: fix(ssr): fix the bug that multi slot scope id does not work on component (#6100)
X-Git-Tag: v3.4.28~59
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c74302aae64c118752db7fc2a2c229a11ebaead;p=thirdparty%2Fvuejs%2Fcore.git
fix(ssr): fix the bug that multi slot scope id does not work on component (#6100)
close #6093
---
diff --git a/packages/server-renderer/__tests__/ssrScopeId.spec.ts b/packages/server-renderer/__tests__/ssrScopeId.spec.ts
index f9d356065d..4ceb865fb5 100644
--- a/packages/server-renderer/__tests__/ssrScopeId.spec.ts
+++ b/packages/server-renderer/__tests__/ssrScopeId.spec.ts
@@ -179,4 +179,94 @@ describe('ssr: scopedId runtime behavior', () => {
const result = await renderToString(createApp(Comp)) // output: `
`
expect(result).toBe(``)
})
+
+ // #6093
+ test(':slotted on forwarded slots on component', async () => {
+ const Wrapper = {
+ __scopeId: 'wrapper',
+ ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
+ //
+ push(
+ ``,
+ )
+ ssrRenderSlot(
+ ctx.$slots,
+ 'default',
+ {},
+ null,
+ push,
+ parent,
+ 'wrapper-s',
+ )
+ push(`
`)
+ },
+ }
+
+ const Slotted = {
+ __scopeId: 'slotted',
+ ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
+ //
+ push(
+ ssrRenderComponent(
+ Wrapper,
+ attrs,
+ {
+ default: withCtx(
+ (_: any, push: any, parent: any, scopeId: string) => {
+ ssrRenderSlot(
+ ctx.$slots,
+ 'default',
+ {},
+ null,
+ push,
+ parent,
+ 'slotted-s' + scopeId,
+ )
+ },
+ ),
+ _: 1,
+ } as any,
+ parent,
+ ),
+ )
+ },
+ }
+
+ const Child = {
+ ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
+ push(``)
+ },
+ }
+
+ const Root = {
+ __scopeId: 'root',
+ //
+ ssrRender: (_: any, push: any, parent: any, attrs: any) => {
+ push(
+ ssrRenderComponent(
+ Slotted,
+ attrs,
+ {
+ default: withCtx(
+ (_: any, push: any, parent: any, scopeId: string) => {
+ push(ssrRenderComponent(Child, null, null, parent, scopeId))
+ },
+ ),
+ _: 1,
+ } as any,
+ parent,
+ ),
+ )
+ },
+ }
+
+ const result = await renderToString(createApp(Root))
+ expect(result).toBe(
+ ``,
+ )
+ })
})
diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts
index 28a78c6684..7e274c3b98 100644
--- a/packages/server-renderer/src/render.ts
+++ b/packages/server-renderer/src/render.ts
@@ -181,7 +181,10 @@ function renderComponentSubTree(
if (slotScopeId) {
if (!hasCloned) attrs = { ...attrs }
- attrs![slotScopeId.trim()] = ''
+ const slotScopeIdList = slotScopeId.trim().split(' ')
+ for (let i = 0; i < slotScopeIdList.length; i++) {
+ attrs![slotScopeIdList[i]] = ''
+ }
}
// set current rendering instance for asset resolution