Skip to content

Commit af08256

Browse files
committed
handle synchronous transition leave callback (fix #1117)
1 parent 635d6c9 commit af08256

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/transition/transition.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ p.leave = function (op, cb) {
148148
addClass(this.el, this.leaveClass)
149149
this.callHookWithCb('leave')
150150
this.cancel = this.hooks && this.hooks.leaveCancelled
151-
// only need to handle leaveDone if there's no explicit
152-
// js callback
153-
if (!this.pendingJsCb) {
151+
// only need to handle leaveDone if
152+
// 1. the transition is already done (synchronously called
153+
// by the user, which causes this.op set to null)
154+
// 2. there's no explicit js callback
155+
if (this.op && !this.pendingJsCb) {
154156
// if a CSS transition leaves immediately after enter,
155157
// the transitionend event never fires. therefore we
156158
// detect such cases and end the leave immediately.
@@ -188,6 +190,7 @@ p.leaveDone = function () {
188190
removeClass(this.el, this.leaveClass)
189191
this.callHook('afterLeave')
190192
if (this.cb) this.cb()
193+
this.op = null
191194
}
192195

193196
/**

test/unit/specs/transition/transition_spec.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ if (_.inBrowser && !_.isIE9) {
116116
expect(cb).toHaveBeenCalled()
117117
})
118118

119-
it('skip when no css transition is available', function () {
119+
it('skip when css transition is not supported', function () {
120120
var e = _.transitionEndEvent
121121
_.transitionEndEvent = null
122122
el.__v_trans = new Transition(el, 'test', null, vm)
@@ -190,15 +190,18 @@ if (_.inBrowser && !_.isIE9) {
190190
expect(cb).toHaveBeenCalled()
191191
expect(hooks.afterEnter).toHaveBeenCalled()
192192
expect(el.classList.contains('test-no-trans-enter')).toBe(false)
193-
transition.apply(el, -1, op, vm, cb)
194-
expect(hooks.beforeLeave).toHaveBeenCalled()
195-
expect(hooks.leave).toHaveBeenCalled()
193+
// wait until transition.justEntered flag is off
196194
_.nextTick(function () {
197-
expect(op.calls.count()).toBe(2)
198-
expect(cb.calls.count()).toBe(2)
199-
expect(hooks.afterLeave).toHaveBeenCalled()
200-
expect(el.classList.contains('test-no-trans-leave')).toBe(false)
201-
done()
195+
transition.apply(el, -1, op, vm, cb)
196+
expect(hooks.beforeLeave).toHaveBeenCalled()
197+
expect(hooks.leave).toHaveBeenCalled()
198+
_.nextTick(function () {
199+
expect(op.calls.count()).toBe(2)
200+
expect(cb.calls.count()).toBe(2)
201+
expect(hooks.afterLeave).toHaveBeenCalled()
202+
expect(el.classList.contains('test-no-trans-leave')).toBe(false)
203+
done()
204+
})
202205
})
203206
})
204207
})

0 commit comments

Comments
 (0)