Skip to content

Commit

Permalink
fix(transition): reflow before leave-active class after leave-from (v…
Browse files Browse the repository at this point in the history
…uejs#2593), while fixing (vuejs#10688)
  • Loading branch information
Tadehz committed Oct 28, 2024
1 parent 664d2e5 commit 9fc42cf
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions packages/runtime-dom/src/components/Transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ export function resolveTransitionProps(
onAppearCancelled = onEnterCancelled,
} = baseProps

const finishEnter = (el: Element, isAppear: boolean, done?: () => void) => {
const finishEnter = (
el: Element & { _enterCancelled?: boolean },
isAppear: boolean,
done?: () => void,
isCancelled?: boolean,
) => {
el._enterCancelled = true
removeTransitionClass(el, isAppear ? appearToClass : enterToClass)
removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass)
done && done()
Expand Down Expand Up @@ -240,7 +246,10 @@ export function resolveTransitionProps(
},
onEnter: makeEnterHook(false),
onAppear: makeEnterHook(true),
onLeave(el: Element & { _isLeaving?: boolean }, done) {
onLeave(
el: Element & { _isLeaving?: boolean; _enterCancelled?: boolean },
done,
) {
el._isLeaving = true
const resolve = () => finishLeave(el, done)
addTransitionClass(el, leaveFromClass)
Expand All @@ -249,9 +258,15 @@ export function resolveTransitionProps(
}
// add *-leave-active class before reflow so in the case of a cancelled enter transition
// the css will not get the final state (#10677)
addTransitionClass(el, leaveActiveClass)
// force reflow so *-leave-from classes immediately take effect (#2593)
forceReflow()
if (!el._enterCancelled) {
// force reflow so *-leave-from classes immediately take effect (#2593)
forceReflow()
addTransitionClass(el, leaveActiveClass)
} else {
addTransitionClass(el, leaveActiveClass)
// force reflow so *-leave-from classes immediately take effect (#2593)
forceReflow()
}
nextFrame(() => {
if (!el._isLeaving) {
// cancelled
Expand All @@ -269,11 +284,11 @@ export function resolveTransitionProps(
callHook(onLeave, [el, resolve])
},
onEnterCancelled(el) {
finishEnter(el, false)
finishEnter(el, false, undefined, false)
callHook(onEnterCancelled, [el])
},
onAppearCancelled(el) {
finishEnter(el, true)
finishEnter(el, true, undefined, false)
callHook(onAppearCancelled, [el])
},
onLeaveCancelled(el) {
Expand Down

0 comments on commit 9fc42cf

Please sign in to comment.