Skip to content

Commit 5a96267

Browse files
authored
fix(ssr): don't render v-if comments in TransitionGroup (#6732)
close #6715
1 parent 2ec06fd commit 5a96267

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

Diff for: packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ describe('transition-group', () => {
8282
})
8383
if (_ctx.ok) {
8484
_push(\`<div>ok</div>\`)
85-
} else {
86-
_push(\`<!---->\`)
8785
}
8886
_push(\`<!--]-->\`)
8987
}"

Diff for: packages/compiler-ssr/src/ssrCodegenTransform.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export function processChildren(
141141
context: SSRTransformContext,
142142
asFragment = false,
143143
disableNestedFragments = false,
144+
disableCommentAsIfAlternate = false,
144145
) {
145146
if (asFragment) {
146147
context.pushStringPart(`<!--[-->`)
@@ -191,7 +192,12 @@ export function processChildren(
191192
)
192193
break
193194
case NodeTypes.IF:
194-
ssrProcessIf(child, context, disableNestedFragments)
195+
ssrProcessIf(
196+
child,
197+
context,
198+
disableNestedFragments,
199+
disableCommentAsIfAlternate,
200+
)
195201
break
196202
case NodeTypes.FOR:
197203
ssrProcessFor(child, context, disableNestedFragments)

Diff for: packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ export function ssrProcessTransitionGroup(
8787
* by disabling nested fragment wrappers from being generated.
8888
*/
8989
true,
90+
/**
91+
* TransitionGroup filters out comment children at runtime and thus
92+
* doesn't expect comments to be present during hydration. We need to
93+
* account for that by disabling the empty comment that is otherwise
94+
* rendered for a falsy v-if that has no v-else specified. (#6715)
95+
*/
96+
true,
9097
)
9198
context.pushStringPart(`</`)
9299
context.pushStringPart(tag.exp!)
@@ -106,6 +113,6 @@ export function ssrProcessTransitionGroup(
106113
}
107114
} else {
108115
// fragment
109-
processChildren(node, context, true, true)
116+
processChildren(node, context, true, true, true)
110117
}
111118
}

Diff for: packages/compiler-ssr/src/transforms/ssrVIf.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function ssrProcessIf(
2626
node: IfNode,
2727
context: SSRTransformContext,
2828
disableNestedFragments = false,
29+
disableCommentAsIfAlternate = false,
2930
) {
3031
const [rootBranch] = node.branches
3132
const ifStatement = createIfStatement(
@@ -54,7 +55,7 @@ export function ssrProcessIf(
5455
}
5556
}
5657

57-
if (!currentIf.alternate) {
58+
if (!currentIf.alternate && !disableCommentAsIfAlternate) {
5859
currentIf.alternate = createBlockStatement([
5960
createCallExpression(`_push`, ['`<!---->`']),
6061
])

0 commit comments

Comments
 (0)