]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(ssr): don't render v-if comments in TransitionGroup (#6732)
authorJonas <mail@jonaskuske.com>
Mon, 15 Apr 2024 13:26:19 +0000 (15:26 +0200)
committerGitHub <noreply@github.com>
Mon, 15 Apr 2024 13:26:19 +0000 (21:26 +0800)
close #6715

packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts
packages/compiler-ssr/src/ssrCodegenTransform.ts
packages/compiler-ssr/src/transforms/ssrTransformTransitionGroup.ts
packages/compiler-ssr/src/transforms/ssrVIf.ts

index d2a576fd02a1e7f5814b58131a5a298736d0dfd3..905e6a4895d6d2cba020c7fb0009acf3d596f6b8 100644 (file)
@@ -82,8 +82,6 @@ describe('transition-group', () => {
         })
         if (_ctx.ok) {
           _push(\`<div>ok</div>\`)
-        } else {
-          _push(\`<!---->\`)
         }
         _push(\`<!--]-->\`)
       }"
index 1755be3a3b07b2146b8e80233cc8434e2c0c1cdf..53a7a0605104a20ee249a22d4bcf56b67af5e95f 100644 (file)
@@ -141,6 +141,7 @@ export function processChildren(
   context: SSRTransformContext,
   asFragment = false,
   disableNestedFragments = false,
+  disableCommentAsIfAlternate = false,
 ) {
   if (asFragment) {
     context.pushStringPart(`<!--[-->`)
@@ -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)
index 2d434010e2ade5da8c7e02ef80e1eb4debee3f2c..a2e284ae84158fa621ee52eb0439b34a04ad3ce7 100644 (file)
@@ -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!)
@@ -106,6 +113,6 @@ export function ssrProcessTransitionGroup(
     }
   } else {
     // fragment
-    processChildren(node, context, true, true)
+    processChildren(node, context, true, true, true)
   }
 }
index 32a5a7c00f14270c3bbdffeed71cf13ae7ed651b..b30846c1eeb09922851ce4d5e9a3cad30927b97b 100644 (file)
@@ -26,6 +26,7 @@ export function ssrProcessIf(
   node: IfNode,
   context: SSRTransformContext,
   disableNestedFragments = false,
+  disableCommentAsIfAlternate = false,
 ) {
   const [rootBranch] = node.branches
   const ifStatement = createIfStatement(
@@ -54,7 +55,7 @@ export function ssrProcessIf(
     }
   }
 
-  if (!currentIf.alternate) {
+  if (!currentIf.alternate && !disableCommentAsIfAlternate) {
     currentIf.alternate = createBlockStatement([
       createCallExpression(`_push`, ['`<!---->`']),
     ])