@@ -126,11 +126,7 @@ export function resolveTransitionProps(
126
126
removeTransitionClass ( el , isAppear ? appearFromClass : enterFromClass )
127
127
addTransitionClass ( el , isAppear ? appearToClass : enterToClass )
128
128
if ( ! ( hook && hook . length > 1 ) ) {
129
- if ( enterDuration ) {
130
- setTimeout ( resolve , enterDuration )
131
- } else {
132
- whenTransitionEnds ( el , type , resolve )
133
- }
129
+ whenTransitionEnds ( el , type , enterDuration , resolve )
134
130
}
135
131
} )
136
132
}
@@ -157,11 +153,7 @@ export function resolveTransitionProps(
157
153
removeTransitionClass ( el , leaveFromClass )
158
154
addTransitionClass ( el , leaveToClass )
159
155
if ( ! ( onLeave && onLeave . length > 1 ) ) {
160
- if ( leaveDuration ) {
161
- setTimeout ( resolve , leaveDuration )
162
- } else {
163
- whenTransitionEnds ( el , type , resolve )
164
- }
156
+ whenTransitionEnds ( el , type , leaveDuration , resolve )
165
157
}
166
158
} )
167
159
onLeave && onLeave ( el , resolve )
@@ -247,27 +239,39 @@ function nextFrame(cb: () => void) {
247
239
} )
248
240
}
249
241
242
+ let endId = 0
243
+
250
244
function whenTransitionEnds (
251
- el : Element ,
245
+ el : Element & { _endId ?: number } ,
252
246
expectedType : TransitionProps [ 'type' ] | undefined ,
253
- cb : ( ) => void
247
+ explicitTimeout : number | null ,
248
+ resolve : ( ) => void
254
249
) {
250
+ const id = ( el . _endId = ++ endId )
251
+ const resolveIfNotStale = ( ) => {
252
+ if ( id === el . _endId ) {
253
+ resolve ( )
254
+ }
255
+ }
256
+
257
+ if ( explicitTimeout ) {
258
+ return setTimeout ( resolveIfNotStale , explicitTimeout )
259
+ }
260
+
255
261
const { type, timeout, propCount } = getTransitionInfo ( el , expectedType )
256
262
if ( ! type ) {
257
- return cb ( )
263
+ return resolve ( )
258
264
}
259
265
260
266
const endEvent = type + 'end'
261
267
let ended = 0
262
268
const end = ( ) => {
263
269
el . removeEventListener ( endEvent , onEnd )
264
- cb ( )
270
+ resolveIfNotStale ( )
265
271
}
266
272
const onEnd = ( e : Event ) => {
267
- if ( e . target === el ) {
268
- if ( ++ ended >= propCount ) {
269
- end ( )
270
- }
273
+ if ( e . target === el && ++ ended >= propCount ) {
274
+ end ( )
271
275
}
272
276
}
273
277
setTimeout ( ( ) => {
0 commit comments