Răsfoiți Sursa

fix(compiler): properly bail stringfication for nested slot elements

Evan You 5 ani în urmă
părinte
comite
f74b16ccfe

+ 7 - 0
packages/compiler-core/src/transforms/hoistStatic.ts

@@ -111,7 +111,14 @@ function walk(
 
     // walk further
     if (child.type === NodeTypes.ELEMENT) {
+      const isComponent = child.tagType === ElementTypes.COMPONENT
+      if (isComponent) {
+        context.scopes.vSlot++
+      }
       walk(child, context)
+      if (isComponent) {
+        context.scopes.vSlot--
+      }
     } else if (child.type === NodeTypes.FOR) {
       // Do not hoist v-for single child because it has to be a block
       walk(child, context, child.children.length === 1)

+ 2 - 5
packages/compiler-dom/src/transforms/stringifyStatic.ts

@@ -60,11 +60,8 @@ type StringifiableNode = PlainElementNode | TextCallNode
  * This optimization is only performed in Node.js.
  */
 export const stringifyStatic: HoistTransform = (children, context, parent) => {
-  if (
-    parent.type === NodeTypes.ELEMENT &&
-    (parent.tagType === ElementTypes.COMPONENT ||
-      parent.tagType === ElementTypes.TEMPLATE)
-  ) {
+  // bail stringification for slot content
+  if (context.scopes.vSlot > 0) {
     return
   }