Skip to content

Commit 61c1357

Browse files
authored
fix(compiler-ssr): fix missing scopeId on server-rendered TransitionGroup (#7557)
close #7554
1 parent 36c99a9 commit 61c1357

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

packages/compiler-ssr/__tests__/ssrScopeId.spec.ts

+44
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,48 @@ describe('ssr: scopeId', () => {
124124
}"
125125
`)
126126
})
127+
128+
// #7554
129+
test('scopeId is correctly transform to scope attribute of transition-group ', () => {
130+
expect(
131+
compile(
132+
`<transition-group tag="div" class="red"><span>hello</span></transition-group>`,
133+
{
134+
scopeId,
135+
mode: 'module'
136+
}
137+
).code
138+
).toMatchInlineSnapshot(`
139+
"import { mergeProps as _mergeProps } from \\"vue\\"
140+
import { ssrRenderAttrs as _ssrRenderAttrs } from \\"vue/server-renderer\\"
141+
142+
export function ssrRender(_ctx, _push, _parent, _attrs) {
143+
_push(\`<div\${_ssrRenderAttrs(_mergeProps({ class: \\"red\\" }, _attrs))} data-v-xxxxxxx><span data-v-xxxxxxx>hello</span></div>\`)
144+
}"
145+
`)
146+
147+
// with dynamic tag
148+
expect(
149+
compile(
150+
`<transition-group :tag="someTag" class="red"><span>hello</span></transition-group>`,
151+
{
152+
scopeId,
153+
mode: 'module'
154+
}
155+
).code
156+
).toMatchInlineSnapshot(`
157+
"import { mergeProps as _mergeProps } from \\"vue\\"
158+
import { ssrRenderAttrs as _ssrRenderAttrs } from \\"vue/server-renderer\\"
159+
160+
export function ssrRender(_ctx, _push, _parent, _attrs) {
161+
_push(\`<\${
162+
_ctx.someTag
163+
}\${
164+
_ssrRenderAttrs(_mergeProps({ class: \\"red\\" }, _attrs))
165+
} data-v-xxxxxxx><span data-v-xxxxxxx>hello</span></\${
166+
_ctx.someTag
167+
}>\`)
168+
}"
169+
`)
170+
})
127171
})

packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const wipMap = new WeakMap<ComponentNode, WIPEntry>()
1818
interface WIPEntry {
1919
tag: AttributeNode | DirectiveNode
2020
propsExp: string | JSChildNode | null
21+
scopeId: string | null
2122
}
2223

2324
// phase 1: build props
@@ -45,7 +46,8 @@ export function ssrTransformTransitionGroup(
4546
}
4647
wipMap.set(node, {
4748
tag,
48-
propsExp
49+
propsExp,
50+
scopeId: context.scopeId || null
4951
})
5052
}
5153
}
@@ -58,14 +60,17 @@ export function ssrProcessTransitionGroup(
5860
) {
5961
const entry = wipMap.get(node)
6062
if (entry) {
61-
const { tag, propsExp } = entry
63+
const { tag, propsExp, scopeId } = entry
6264
if (tag.type === NodeTypes.DIRECTIVE) {
6365
// dynamic :tag
6466
context.pushStringPart(`<`)
6567
context.pushStringPart(tag.exp!)
6668
if (propsExp) {
6769
context.pushStringPart(propsExp)
6870
}
71+
if (scopeId) {
72+
context.pushStringPart(` ${scopeId}`)
73+
}
6974
context.pushStringPart(`>`)
7075

7176
processChildren(
@@ -89,6 +94,9 @@ export function ssrProcessTransitionGroup(
8994
if (propsExp) {
9095
context.pushStringPart(propsExp)
9196
}
97+
if (scopeId) {
98+
context.pushStringPart(` ${scopeId}`)
99+
}
92100
context.pushStringPart(`>`)
93101
processChildren(node, context, false, true)
94102
context.pushStringPart(`</${tag.value!.content}>`)

0 commit comments

Comments
 (0)