Skip to content

Commit

Permalink
fix(transition): fix css:false with hooks with no explicit done callback
Browse files Browse the repository at this point in the history
close #1149
  • Loading branch information
yyx990803 committed Jun 25, 2020
1 parent 2ff8dca commit 9edbc27
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
12 changes: 9 additions & 3 deletions packages/runtime-core/src/components/BaseTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ export function resolveTransitionHooks(
})
if (hook) {
hook(el, done)
if (hook.length <= 1) {
done()
}
} else {
done()
}
Expand All @@ -358,7 +361,7 @@ export function resolveTransitionHooks(
}
callHook(onBeforeLeave, [el])
let called = false
const afterLeave = (el._leaveCb = (cancelled?) => {
const done = (el._leaveCb = (cancelled?) => {
if (called) return
called = true
remove()
Expand All @@ -374,9 +377,12 @@ export function resolveTransitionHooks(
})
leavingVNodesCache[key] = vnode
if (onLeave) {
onLeave(el, afterLeave)
onLeave(el, done)
if (onLeave.length <= 1) {
done()
}
} else {
afterLeave()
done()
}
}
}
Expand Down
52 changes: 41 additions & 11 deletions packages/vue/__tests__/Transition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('e2e: Transition', () => {
classList,
isVisible,
timeout,
nextFrame
nextFrame,
click
} = setupPuppeteer()
const baseUrl = `file://${path.resolve(__dirname, './transition.html')}`

Expand Down Expand Up @@ -665,27 +666,45 @@ describe('e2e: Transition', () => {
E2E_TIMEOUT
)

// fixme
test(
'css: false',
async () => {
const onLeaveSpy = jest.fn()
const onBeforeEnterSpy = jest.fn()
const onEnterSpy = jest.fn()
const onAfterEnterSpy = jest.fn()
const onBeforeLeaveSpy = jest.fn()
const onLeaveSpy = jest.fn()
const onAfterLeaveSpy = jest.fn()

await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onBeforeEnterSpy', onBeforeEnterSpy)
await page().exposeFunction('onEnterSpy', onEnterSpy)
await page().exposeFunction('onAfterEnterSpy', onAfterEnterSpy)
await page().exposeFunction('onBeforeLeaveSpy', onBeforeLeaveSpy)
await page().exposeFunction('onLeaveSpy', onLeaveSpy)
await page().exposeFunction('onAfterLeaveSpy', onAfterLeaveSpy)

await page().evaluate(() => {
const { onLeaveSpy, onEnterSpy } = window as any
const {
onBeforeEnterSpy,
onEnterSpy,
onAfterEnterSpy,
onBeforeLeaveSpy,
onLeaveSpy,
onAfterLeaveSpy
} = window as any
const { createApp, ref } = (window as any).Vue
createApp({
template: `
<div id="container">
<transition
:css="false"
name="test"
@before-enter="onBeforeEnterSpy"
@enter="onEnterSpy"
@leave="onLeaveSpy">
@after-enter="onAfterEnterSpy"
@before-leave="onBeforeLeaveSpy"
@leave="onLeaveSpy"
@after-leave="onAfterLeaveSpy">
<div v-if="toggle" class="test">content</div>
</transition>
</div>
Expand All @@ -694,21 +713,32 @@ describe('e2e: Transition', () => {
setup: () => {
const toggle = ref(true)
const click = () => (toggle.value = !toggle.value)
return { toggle, click, onLeaveSpy, onEnterSpy }
return {
toggle,
click,
onBeforeEnterSpy,
onEnterSpy,
onAfterEnterSpy,
onBeforeLeaveSpy,
onLeaveSpy,
onAfterLeaveSpy
}
}
}).mount('#app')
})
expect(await html('#container')).toBe('<div class="test">content</div>')

// leave
await classWhenTransitionStart()
await click('#toggleBtn')
expect(onBeforeLeaveSpy).toBeCalled()
expect(onLeaveSpy).toBeCalled()
expect(await html('#container')).toBe(
'<div class="test">content</div><!--v-if-->'
)
expect(onAfterLeaveSpy).toBeCalled()
expect(await html('#container')).toBe('<!--v-if-->')
// enter
await classWhenTransitionStart()
expect(onBeforeEnterSpy).toBeCalled()
expect(onEnterSpy).toBeCalled()
expect(onAfterEnterSpy).toBeCalled()
expect(await html('#container')).toBe('<div class="test">content</div>')
},
E2E_TIMEOUT
Expand Down

0 comments on commit 9edbc27

Please sign in to comment.