Skip to content

Commit

Permalink
fix(ssr): don't render v-if comments in TransitionGroup (#6732)
Browse files Browse the repository at this point in the history
close #6715
  • Loading branch information
jonaskuske committed Apr 15, 2024
1 parent 2ec06fd commit 5a96267
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 0 additions & 2 deletions packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts
Expand Up @@ -82,8 +82,6 @@ describe('transition-group', () => {
})
if (_ctx.ok) {
_push(\`<div>ok</div>\`)
} else {
_push(\`<!---->\`)
}
_push(\`<!--]-->\`)
}"
Expand Down
8 changes: 7 additions & 1 deletion packages/compiler-ssr/src/ssrCodegenTransform.ts
Expand Up @@ -141,6 +141,7 @@ export function processChildren(
context: SSRTransformContext,
asFragment = false,
disableNestedFragments = false,
disableCommentAsIfAlternate = false,
) {
if (asFragment) {
context.pushStringPart(`<!--[-->`)
Expand Down Expand Up @@ -191,7 +192,12 @@ export function processChildren(
)
break
case NodeTypes.IF:
ssrProcessIf(child, context, disableNestedFragments)
ssrProcessIf(
child,
context,
disableNestedFragments,
disableCommentAsIfAlternate,
)
break
case NodeTypes.FOR:
ssrProcessFor(child, context, disableNestedFragments)
Expand Down
Expand Up @@ -87,6 +87,13 @@ export function ssrProcessTransitionGroup(
* by disabling nested fragment wrappers from being generated.
*/
true,
/**
* TransitionGroup filters out comment children at runtime and thus
* doesn't expect comments to be present during hydration. We need to
* account for that by disabling the empty comment that is otherwise
* rendered for a falsy v-if that has no v-else specified. (#6715)
*/
true,
)
context.pushStringPart(`</`)
context.pushStringPart(tag.exp!)
Expand All @@ -106,6 +113,6 @@ export function ssrProcessTransitionGroup(
}
} else {
// fragment
processChildren(node, context, true, true)
processChildren(node, context, true, true, true)
}
}
3 changes: 2 additions & 1 deletion packages/compiler-ssr/src/transforms/ssrVIf.ts
Expand Up @@ -26,6 +26,7 @@ export function ssrProcessIf(
node: IfNode,
context: SSRTransformContext,
disableNestedFragments = false,
disableCommentAsIfAlternate = false,
) {
const [rootBranch] = node.branches
const ifStatement = createIfStatement(
Expand Down Expand Up @@ -54,7 +55,7 @@ export function ssrProcessIf(
}
}

if (!currentIf.alternate) {
if (!currentIf.alternate && !disableCommentAsIfAlternate) {
currentIf.alternate = createBlockStatement([
createCallExpression(`_push`, ['`<!---->`']),
])
Expand Down

0 comments on commit 5a96267

Please sign in to comment.