Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(transition): v-show false should not call onEnter #4852

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ function baseCreateRenderer(
const needCallTransitionHooks =
(!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
transition &&
!transition.persisted
!transition.persisted &&
!('_vod' in el)
if (needCallTransitionHooks) {
transition!.beforeEnter(el)
}
Expand Down
79 changes: 79 additions & 0 deletions packages/vue/__tests__/Transition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,85 @@ describe('e2e: Transition', () => {
},
E2E_TIMEOUT
)

test(
'transition events should not call onEnter with v-show false',
async () => {
const beforeEnterSpy = jest.fn()
const onEnterSpy = jest.fn()
const afterEnterSpy = jest.fn()

await page().exposeFunction('onEnterSpy', onEnterSpy)
await page().exposeFunction('beforeEnterSpy', beforeEnterSpy)
await page().exposeFunction('afterEnterSpy', afterEnterSpy)

await page().evaluate(() => {
const {
beforeEnterSpy,
onEnterSpy,
afterEnterSpy,
} = window as any
const { createApp, ref } = (window as any).Vue
createApp({
template: `
<div id="container">
<transition
name="test"
appear
@before-enter="beforeEnterSpy"
@enter="onEnterSpy"
@after-enter="afterEnterSpy"
@before-leave="beforeLeaveSpy"
@leave="onLeaveSpy"
@after-leave="afterLeaveSpy">
<div v-show="toggle" class="test">content</div>
</transition>
</div>
<button id="toggleBtn" @click="click">button</button>
`,
setup: () => {
const toggle = ref(false)
const click = () => (toggle.value = !toggle.value)
return {
toggle,
click,
beforeEnterSpy,
onEnterSpy,
afterEnterSpy,
}
}
}).mount('#app')
})
await nextTick()

expect(await isVisible('.test')).toBe(false)

expect(beforeEnterSpy).toBeCalledTimes(0)
expect(onEnterSpy).toBeCalledTimes(0)
// enter
expect(await classWhenTransitionStart()).toStrictEqual([
'test',
'test-enter-from',
'test-enter-active'
])
expect(beforeEnterSpy).toBeCalledTimes(1)
expect(onEnterSpy).toBeCalledTimes(1)
expect(afterEnterSpy).not.toBeCalled()
await nextFrame()
expect(await classList('.test')).toStrictEqual([
'test',
'test-enter-active',
'test-enter-to'
])
expect(afterEnterSpy).not.toBeCalled()
await transitionFinish()
expect(await html('#container')).toBe(
'<div class="test" style="">content</div>'
)
expect(afterEnterSpy).toBeCalled()
},
E2E_TIMEOUT
)
})

describe('explicit durations', () => {
Expand Down