]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(BaseTransition): collect correct children with slot passthrough in `Transition...
authorunderfin <2218301630@qq.com>
Mon, 29 Jun 2020 16:04:28 +0000 (00:04 +0800)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2020 16:04:28 +0000 (12:04 -0400)
fix #1455

packages/runtime-core/src/components/BaseTransition.ts
packages/runtime-core/src/index.ts
packages/runtime-dom/src/components/TransitionGroup.ts

index e68b4749738b1d481646c52730c40ad5b1eac439..a3ab079bc606bd86cbb5dc441f97bc04eeeae564 100644 (file)
@@ -8,7 +8,8 @@ import {
   Comment,
   isSameVNodeType,
   VNode,
-  VNodeArrayChildren
+  VNodeArrayChildren,
+  Fragment
 } from '../vnode'
 import { warn } from '../warning'
 import { isKeepAlive } from './KeepAlive'
@@ -135,7 +136,10 @@ const BaseTransitionImpl = {
     const state = useTransitionState()
 
     return () => {
-      const children = slots.default && slots.default()
+      const children = getTransitionRawChildren(
+        slots.default ? slots.default() : [],
+        true
+      )
       if (!children || !children.length) {
         return
       }
@@ -417,3 +421,27 @@ export function setTransitionHooks(vnode: VNode, hooks: TransitionHooks) {
     vnode.transition = hooks
   }
 }
+
+export function getTransitionRawChildren(
+  children: VNode[],
+  keepComment: boolean = false
+): VNode[] {
+  let ret: VNode[] = []
+  for (let i = 0; i < children.length; i++) {
+    const child = children[i]
+    // handle fragment children case, e.g. v-for
+    if (child.type === Fragment) {
+      ret = ret.concat(
+        getTransitionRawChildren(child.children as VNode[], keepComment)
+      )
+    }
+    // comment placeholders should be skipped, e.g. v-if
+    else if (
+      child.type !== Comment ||
+      (child.type === Comment && keepComment)
+    ) {
+      ret.push(child)
+    }
+  }
+  return ret
+}
index 86c1986941f5afd2f32b63bc110d807e10107e4c..8ce8d44b2d702ce387f0f3684f87b82aeba06240 100644 (file)
@@ -91,7 +91,8 @@ export { registerRuntimeCompiler } from './component'
 export {
   useTransitionState,
   resolveTransitionHooks,
-  setTransitionHooks
+  setTransitionHooks,
+  getTransitionRawChildren
 } from './components/BaseTransition'
 
 // Types -----------------------------------------------------------------------
index 34d8466e0fde2e4907ac609992ebcba31d4861bc..bd48b4a3cd6d30d666d91bd577ec8df379e9b8b3 100644 (file)
@@ -9,11 +9,11 @@ import {
 } from './Transition'
 import {
   Fragment,
-  Comment,
   VNode,
   warn,
   resolveTransitionHooks,
   useTransitionState,
+  getTransitionRawChildren,
   getCurrentInstance,
   setTransitionHooks,
   createVNode,
@@ -129,22 +129,6 @@ const TransitionGroupImpl = {
   }
 }
 
-function getTransitionRawChildren(children: VNode[]): VNode[] {
-  let ret: VNode[] = []
-  for (let i = 0; i < children.length; i++) {
-    const child = children[i]
-    // handle fragment children case, e.g. v-for
-    if (child.type === Fragment) {
-      ret = ret.concat(getTransitionRawChildren(child.children as VNode[]))
-    }
-    // comment placeholders should be skipped, e.g. v-if
-    else if (child.type !== Comment) {
-      ret.push(child)
-    }
-  }
-  return ret
-}
-
 // remove mode props as TransitionGroup doesn't support it
 delete TransitionGroupImpl.props.mode