Skip to content

Commit 9f6f8b3

Browse files
committed
fix(compiler-ssr): fix attr fallthrough for transition/keep-alive as template root
fix #3981
1 parent 9b607fe commit 9f6f8b3

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ describe('ssr: components', () => {
269269
test('built-in fallthroughs', () => {
270270
expect(compile(`<transition><div/></transition>`).code)
271271
.toMatchInlineSnapshot(`
272-
"
272+
"const { ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
273+
273274
return function ssrRender(_ctx, _push, _parent, _attrs) {
274-
_push(\`<div></div>\`)
275+
_push(\`<div\${_ssrRenderAttrs(_attrs)}></div>\`)
275276
}"
276277
`)
277278

@@ -283,7 +284,7 @@ describe('ssr: components', () => {
283284
return function ssrRender(_ctx, _push, _parent, _attrs) {
284285
const _component_foo = _resolveComponent(\\"foo\\")
285286
286-
_push(_ssrRenderComponent(_component_foo, null, null, _parent))
287+
_push(_ssrRenderComponent(_component_foo, _attrs, null, _parent))
287288
}"
288289
`)
289290
})

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
RootNode,
88
TemplateChildNode,
99
ParentNode,
10-
findDir
10+
findDir,
11+
isBuiltInType
1112
} from '@vue/compiler-dom'
1213

1314
const hasSingleChild = (node: ParentNode): boolean =>
@@ -21,6 +22,18 @@ export const ssrInjectFallthroughAttrs: NodeTransform = (node, context) => {
2122
context.identifiers._attrs = 1
2223
}
2324

25+
if (
26+
node.type === NodeTypes.ELEMENT &&
27+
node.tagType === ElementTypes.COMPONENT &&
28+
(isBuiltInType(node.tag, 'Transition') ||
29+
isBuiltInType(node.tag, 'KeepAlive'))
30+
) {
31+
if (hasSingleChild(node)) {
32+
injectFallthroughAttrs(node.children[0])
33+
}
34+
return
35+
}
36+
2437
const parent = context.parent
2538
if (!parent || parent.type !== NodeTypes.ROOT) {
2639
return

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ export function ssrProcessComponent(
180180
} else if (component === TRANSITION_GROUP) {
181181
return ssrProcessTransitionGroup(node, context)
182182
} else {
183-
// real fall-through (e.g. KeepAlive): just render its children.
183+
// real fall-through: Transition / KeepAlive
184+
// just render its children.
184185
processChildren(node.children, context)
185186
}
186187
} else {

0 commit comments

Comments
 (0)