Skip to content

Commit feadb33

Browse files
committed
fix(ssr): support resolve tag name from _attrs in transition group rendering
1 parent 119f18c commit feadb33

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ describe('transition-group', () => {
1111
"const { ssrRenderList: _ssrRenderList } = require("vue/server-renderer")
1212
1313
return function ssrRender(_ctx, _push, _parent, _attrs) {
14+
if (_attrs.tag) {
15+
_push(\`<\${_attrs.tag}>\`)
16+
}
1417
_push(\`<!--[-->\`)
1518
_ssrRenderList(_ctx.list, (i) => {
1619
_push(\`<div></div>\`)
1720
})
1821
_push(\`<!--]-->\`)
22+
if (_attrs.tag) {
23+
_push(\`</\${_attrs.tag}>\`)
24+
}
1925
}"
2026
`)
2127
})
@@ -114,6 +120,9 @@ describe('transition-group', () => {
114120
"const { ssrRenderList: _ssrRenderList } = require("vue/server-renderer")
115121
116122
return function ssrRender(_ctx, _push, _parent, _attrs) {
123+
if (_attrs.tag) {
124+
_push(\`<\${_attrs.tag}>\`)
125+
}
117126
_push(\`<!--[-->\`)
118127
_ssrRenderList(10, (i) => {
119128
_push(\`<div></div>\`)
@@ -125,6 +134,9 @@ describe('transition-group', () => {
125134
_push(\`<div>ok</div>\`)
126135
}
127136
_push(\`<!--]-->\`)
137+
if (_attrs.tag) {
138+
_push(\`</\${_attrs.tag}>\`)
139+
}
128140
}"
129141
`)
130142
})

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
NodeTypes,
77
type TransformContext,
88
buildProps,
9+
createBlockStatement,
910
createCallExpression,
11+
createIfStatement,
12+
createSimpleExpression,
1013
findProp,
1114
} from '@vue/compiler-dom'
1215
import { SSR_RENDER_ATTRS } from '../runtimeHelpers'
@@ -112,7 +115,37 @@ export function ssrProcessTransitionGroup(
112115
context.pushStringPart(`</${tag.value!.content}>`)
113116
}
114117
} else {
118+
// #12827 _attrs fallthrough may contain tag property
119+
const hasFallthroughAttrs = node.props.some(
120+
p =>
121+
p.type === NodeTypes.DIRECTIVE &&
122+
p.name === 'bind' &&
123+
p.exp &&
124+
p.exp.type === NodeTypes.SIMPLE_EXPRESSION &&
125+
p.exp.content === '_attrs',
126+
)
127+
if (hasFallthroughAttrs) {
128+
context.pushStatement(
129+
createIfStatement(
130+
createSimpleExpression('_attrs.tag'),
131+
createBlockStatement([
132+
createSimpleExpression('_push(`<${_attrs.tag}>`)'),
133+
]),
134+
),
135+
)
136+
}
115137
// fragment
116138
processChildren(node, context, true, true, true)
139+
140+
if (hasFallthroughAttrs) {
141+
context.pushStatement(
142+
createIfStatement(
143+
createSimpleExpression('_attrs.tag'),
144+
createBlockStatement([
145+
createSimpleExpression('_push(`</${_attrs.tag}>`)'),
146+
]),
147+
),
148+
)
149+
}
117150
}
118151
}

0 commit comments

Comments
 (0)