Skip to content

fix(Transition): handle leave immediately done in out-in mode #11824

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions packages/runtime-core/src/components/BaseTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { PatchFlags, ShapeFlags, isArray, isFunction } from '@vue/shared'
import { onBeforeUnmount, onMounted } from '../apiLifecycle'
import { isTeleport } from './Teleport'
import type { RendererElement } from '../renderer'
import { SchedulerJobFlags } from '../scheduler'
import { SchedulerJobFlags, queueJob } from '../scheduler'

type Hook<T = () => void> = T | T[]

Expand Down Expand Up @@ -225,7 +225,7 @@ const BaseTransitionImpl: ComponentOptions = {
// #6835
// it also needs to be updated when active is undefined
if (!(instance.job.flags! & SchedulerJobFlags.DISPOSED)) {
instance.update()
queueJob(instance.update)
}
delete leavingHooks.afterLeave
}
Expand Down
46 changes: 46 additions & 0 deletions packages/vue/__tests__/e2e/Transition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,52 @@ describe('e2e: Transition', () => {
E2E_TIMEOUT,
)

test(
'onLeave event immediately done (out-in mode)',
async () => {
const onLeaveSpy = vi.fn()
await page().exposeFunction('onLeaveSpy', onLeaveSpy)

await page().evaluate(async () => {
const { onLeaveSpy } = window as any
const { createApp, ref } = (window as any).Vue
createApp({
template: `
<div id="container">
<transition mode="out-in" @leave="onLeave">
<div v-if="toggle">True</div>
<div v-else>False</div>
</transition>
</div>
<button id="toggleBtn" @click="click">button</button>
`,
setup: () => {
const toggle = ref(true)
function onLeave(el: Element, done: Function) {
onLeaveSpy()
// immediately done
done()
}
const click = () => (toggle.value = !toggle.value)
return {
toggle,
click,
onLeave,
}
},
}).mount('#app')
})

expect(await html('#container')).toBe('<div>True</div>')

await click('#toggleBtn')
await transitionFinish()
expect(onLeaveSpy).toBeCalled()
expect(await html('#container')).toBe('<div class="">False</div>')
},
E2E_TIMEOUT,
)

test(
'css: false',
async () => {
Expand Down