瀏覽代碼

fix transition insert hook duplicate invocation on slot nodes (fix #3474)

Evan You 9 年之前
父節點
當前提交
ba5fb31188
共有 2 個文件被更改,包括 11 次插入3 次删除
  1. 1 0
      flow/vnode.js
  2. 10 3
      src/platforms/web/runtime/modules/transition.js

+ 1 - 0
flow/vnode.js

@@ -46,6 +46,7 @@ declare interface VNodeData {
   on?: ?{ [key: string]: Function | Array<Function> };
   nativeOn?: { [key: string]: Function | Array<Function> };
   transition?: Object;
+  transitionInjected?: boolean;
   inlineTemplate?: {
     render: Function;
     staticRenderFns: Array<Function>;

+ 10 - 3
src/platforms/web/runtime/modules/transition.js

@@ -94,14 +94,21 @@ export function enter (vnode: VNodeWithData) {
 
   if (!vnode.data.show) {
     // remove pending leave element on enter by injecting an insert hook
-    mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', () => {
+    const hooks = vnode.data.hook || (vnode.data.hook = {})
+    hooks._transitionInsert = () => {
       const parent = el.parentNode
-      const pendingNode = parent._pending && parent._pending[vnode.key]
+      const pendingNode = parent && parent._pending && parent._pending[vnode.key]
       if (pendingNode && pendingNode.tag === vnode.tag && pendingNode.elm._leaveCb) {
         pendingNode.elm._leaveCb()
       }
       enterHook && enterHook(el, cb)
-    })
+    }
+    if (!vnode.data.transitionInjected) {
+      vnode.data.transitionInjected = true
+      mergeVNodeHook(hooks, 'insert', () => {
+        hooks._transitionInsert()
+      })
+    }
   }
 
   // start enter transition