Skip to content

Commit 210a3a2

Browse files
committed
test in-out early cancel with keep-alive
1 parent ccf3a61 commit 210a3a2

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

src/platforms/web/runtime/components/transition.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// supports transition mode (out-in / in-out)
33

44
import { warn } from 'core/util/index'
5-
import { noop, camelize } from 'shared/util'
5+
import { camelize } from 'shared/util'
66
import { getRealChild, mergeVNodeHook } from 'core/vdom/helpers'
77

88
export const transitionProps = {
@@ -110,16 +110,11 @@ export default {
110110
} else if (mode === 'in-out') {
111111
let delayedLeave
112112
const performLeave = () => { delayedLeave() }
113-
114113
mergeVNodeHook(data, 'afterEnter', performLeave)
115114
mergeVNodeHook(data, 'enterCancelled', performLeave)
116-
117115
mergeVNodeHook(oldData, 'delayLeave', leave => {
118116
delayedLeave = leave
119117
})
120-
mergeVNodeHook(oldData, 'leaveCancelled', () => {
121-
delayedLeave = noop
122-
})
123118
}
124119
}
125120

src/platforms/web/runtime/modules/transition.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ export function leave (vnode: VNodeWithData, rm: Function) {
160160
}
161161

162162
function performLeave () {
163+
// the delayed leave may have already been cancelled
164+
if (cb.cancelled) {
165+
return
166+
}
163167
// record leaving element
164168
if (!vnode.data.show) {
165169
(el.parentNode._pending || (el.parentNode._pending = {}))[vnode.key] = vnode

test/unit/features/component/component-keep-alive.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,71 @@ describe('Component keep-alive', () => {
260260
assertHookCalls(two, [1, 1, 1, 1, 0])
261261
}).then(done)
262262
})
263+
264+
it('dynamic components, in-out with early cancel', done => {
265+
let next
266+
const vm = new Vue({
267+
template: `<div>
268+
<transition name="test" mode="in-out" @after-enter="afterEnter">
269+
<component :is="view" class="test" keep-alive></component>
270+
</transition>
271+
</div>`,
272+
data: { view: 'one' },
273+
components,
274+
methods: {
275+
afterEnter () {
276+
next()
277+
}
278+
}
279+
}).$mount(el)
280+
expect(vm.$el.textContent).toBe('one')
281+
vm.view = 'two'
282+
waitForUpdate(() => {
283+
expect(vm.$el.innerHTML).toBe(
284+
'<div class="test">one</div>' +
285+
'<div class="test test-enter test-enter-active">two</div>'
286+
)
287+
}).thenWaitFor(nextFrame).then(() => {
288+
expect(vm.$el.innerHTML).toBe(
289+
'<div class="test">one</div>' +
290+
'<div class="test test-enter-active">two</div>'
291+
)
292+
// switch again before enter finishes,
293+
// this cancels both enter and leave.
294+
vm.view = 'one'
295+
}).then(() => {
296+
// 1. the pending leaving "one" should be removed instantly.
297+
// 2. the entering "two" should be placed into its final state instantly.
298+
// 3. a new "one" is created and entering
299+
expect(vm.$el.innerHTML).toBe(
300+
'<div class="test">two</div>' +
301+
'<div class="test test-enter test-enter-active">one</div>'
302+
)
303+
}).thenWaitFor(nextFrame).then(() => {
304+
expect(vm.$el.innerHTML).toBe(
305+
'<div class="test">two</div>' +
306+
'<div class="test test-enter-active">one</div>'
307+
)
308+
}).thenWaitFor(_next => { next = _next }).then(() => {
309+
expect(vm.$el.innerHTML).toBe(
310+
'<div class="test">two</div>' +
311+
'<div class="test">one</div>'
312+
)
313+
}).then(() => {
314+
expect(vm.$el.innerHTML).toBe(
315+
'<div class="test test-leave test-leave-active">two</div>' +
316+
'<div class="test">one</div>'
317+
)
318+
}).thenWaitFor(nextFrame).then(() => {
319+
expect(vm.$el.innerHTML).toBe(
320+
'<div class="test test-leave-active">two</div>' +
321+
'<div class="test">one</div>'
322+
)
323+
}).thenWaitFor(duration + 10).then(() => {
324+
expect(vm.$el.innerHTML).toBe(
325+
'<div class="test">one</div>'
326+
)
327+
}).then(done).then(done)
328+
})
263329
}
264330
})

test/unit/features/transition/transition-mode.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ if (!isIE9) {
142142
}).then(done)
143143
})
144144

145-
it('dynamic components, in-out with leaveCancell', done => {
145+
it('dynamic components, in-out with early cancel', done => {
146146
let next
147147
const vm = new Vue({
148148
template: `<div>

0 commit comments

Comments
 (0)