@@ -10,14 +10,36 @@ import {
10
10
animationEndEvent ,
11
11
transitionProp ,
12
12
animationProp ,
13
- warn
13
+ warn ,
14
+ inBrowser
14
15
} from '../util/index'
15
16
16
17
const TYPE_TRANSITION = 'transition'
17
18
const TYPE_ANIMATION = 'animation'
18
19
const transDurationProp = transitionProp + 'Duration'
19
20
const animDurationProp = animationProp + 'Duration'
20
21
22
+ /**
23
+ * If a just-entered element is applied the
24
+ * leave class while its enter transition hasn't started yet,
25
+ * and the transitioned property has the same value for both
26
+ * enter/leave, then the leave transition will be skipped and
27
+ * the transitionend event never fires. This function ensures
28
+ * its callback to be called after a transition has started
29
+ * by waiting for double raf.
30
+ *
31
+ * It falls back to setTimeout on devices that support CSS
32
+ * transitions but not raf (e.g. Android 4.2 browser) - since
33
+ * these environments are usually slow, we are giving it a
34
+ * relatively large timeout.
35
+ */
36
+
37
+ const raf = inBrowser && window . requestAnimationFrame
38
+ const waitForTransitionStart = raf
39
+ /* istanbul ignore next */
40
+ ? function ( fn ) { raf ( function ( ) { raf ( fn ) } ) }
41
+ : function ( fn ) { setTimeout ( fn , 50 ) }
42
+
21
43
/**
22
44
* A Transition object that encapsulates the state and logic
23
45
* of the transition.
@@ -117,19 +139,11 @@ p.enter = function (op, cb) {
117
139
*/
118
140
119
141
p . enterNextTick = function ( ) {
120
- // Important hack:
121
- // in Chrome, if a just-entered element is applied the
122
- // leave class while its interpolated property still has
123
- // a very small value (within one frame), Chrome will
124
- // skip the leave transition entirely and not firing the
125
- // transtionend event. Therefore we need to protected
126
- // against such cases using a one-frame timeout.
142
+ // prevent transition skipping
127
143
this . justEntered = true
128
- var self = this
129
- setTimeout ( function ( ) {
130
- self . justEntered = false
131
- } , 17 )
132
-
144
+ waitForTransitionStart ( ( ) => {
145
+ this . justEntered = false
146
+ } )
133
147
var enterDone = this . enterDone
134
148
var type = this . getCssTransitionType ( this . enterClass )
135
149
if ( ! this . pendingJsCb ) {
0 commit comments