Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix transitions on v-show cancelled on next frame (fix #7390) #7391

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/platforms/web/runtime/modules/transition.js
Original file line number Diff line number Diff line change
@@ -149,13 +149,15 @@ export function enter (vnode: VNodeWithData, toggleDisplay: ?() => void) {
addTransitionClass(el, startClass)
addTransitionClass(el, activeClass)
nextFrame(() => {
addTransitionClass(el, toClass)
removeTransitionClass(el, startClass)
if (!cb.cancelled && !userWantsControl) {
if (isValidDuration(explicitEnterDuration)) {
setTimeout(cb, explicitEnterDuration)
} else {
whenTransitionEnds(el, type, cb)
if (!cb.cancelled) {
addTransitionClass(el, toClass)
if (!userWantsControl) {
if (isValidDuration(explicitEnterDuration)) {
setTimeout(cb, explicitEnterDuration)
} else {
whenTransitionEnds(el, type, cb)
}
}
}
})
@@ -257,13 +259,15 @@ export function leave (vnode: VNodeWithData, rm: Function) {
addTransitionClass(el, leaveClass)
addTransitionClass(el, leaveActiveClass)
nextFrame(() => {
addTransitionClass(el, leaveToClass)
removeTransitionClass(el, leaveClass)
if (!cb.cancelled && !userWantsControl) {
if (isValidDuration(explicitLeaveDuration)) {
setTimeout(cb, explicitLeaveDuration)
} else {
whenTransitionEnds(el, type, cb)
if (!cb.cancelled) {
addTransitionClass(el, leaveToClass)
if (!userWantsControl) {
if (isValidDuration(explicitLeaveDuration)) {
setTimeout(cb, explicitLeaveDuration)
} else {
whenTransitionEnds(el, type, cb)
}
}
}
})
44 changes: 44 additions & 0 deletions test/unit/features/transition/transition.spec.js
Original file line number Diff line number Diff line change
@@ -612,6 +612,50 @@ if (!isIE9) {
}).then(done)
})

it('leave transition with v-show: cancelled on next frame', done => {
const vm = new Vue({
template: `
<div>
<transition name="test">
<div v-show="ok" class="test">foo</div>
</transition>
</div>
`,
data: { ok: true }
}).$mount(el)

vm.ok = false
waitForUpdate(() => {
vm.ok = true
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.children[0].className).toBe('test test-enter-active test-enter-to')
}).thenWaitFor(duration + buffer).then(() => {
expect(vm.$el.children[0].className).toBe('test')
}).then(done)
})

it('enter transition with v-show: cancelled on next frame', done => {
const vm = new Vue({
template: `
<div>
<transition name="test">
<div v-show="ok" class="test">foo</div>
</transition>
</div>
`,
data: { ok: false }
}).$mount(el)

vm.ok = true
waitForUpdate(() => {
vm.ok = false
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.children[0].className).toBe('test test-leave-active test-leave-to')
}).thenWaitFor(duration + buffer).then(() => {
expect(vm.$el.children[0].className).toBe('test')
}).then(done)
})

it('animations', done => {
const vm = new Vue({
template: `