Skip to content

Commit 3f8f9b6

Browse files
authored
fix(transition): ensure styles from *-leave-active trigger transition (#2716)
fix #2712
1 parent d067fb2 commit 3f8f9b6

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

packages/runtime-dom/src/components/Transition.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ export function resolveTransitionProps(
157157
const resolve = () => finishLeave(el, done)
158158
addTransitionClass(el, leaveActiveClass)
159159
addTransitionClass(el, leaveFromClass)
160-
// ref #2531, #2593
161-
// disabling the transition before nextFrame ensures styles from
162-
// *-leave-from and *-enter-from classes are applied instantly before
163-
// the transition starts. This is applied for enter transition as well
164-
// so that it accounts for `visibility: hidden` cases.
160+
165161
const cachedTransition = (el as HTMLElement).style.transitionProperty
166-
;(el as HTMLElement).style.transitionProperty = 'none'
162+
requestAnimationFrame(() => {
163+
// ref #2531, #2593
164+
// disabling the transition before nextFrame ensures styles from
165+
// *-leave-from classes are applied instantly before the transition starts.
166+
// ref #2712
167+
// do this in an rAF to ensure styles from *-leave-active can trigger
168+
// transition on the first frame when el has `transition` property itself.
169+
;(el as HTMLElement).style.transitionProperty = 'none'
170+
})
167171
nextFrame(() => {
168172
;(el as HTMLElement).style.transitionProperty = cachedTransition
169173
removeTransitionClass(el, leaveFromClass)

packages/vue/__tests__/TransitionGroup.spec.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ describe('e2e: TransitionGroup', () => {
88

99
const duration = 50
1010
const buffer = 5
11-
const transitionDisableProp = `style="transition-property: none;"`
1211

1312
const htmlWhenTransitionStart = () =>
1413
page().evaluate(() => {
@@ -107,9 +106,9 @@ describe('e2e: TransitionGroup', () => {
107106
)
108107

109108
expect(await htmlWhenTransitionStart()).toBe(
110-
`<div class="test test-leave-active test-leave-from" ${transitionDisableProp}>a</div>` +
109+
`<div class="test test-leave-active test-leave-from">a</div>` +
111110
`<div class="test">b</div>` +
112-
`<div class="test test-leave-active test-leave-from" ${transitionDisableProp}>c</div>`
111+
`<div class="test test-leave-active test-leave-from">c</div>`
113112
)
114113
await nextFrame()
115114
expect(await html('#container')).toBe(
@@ -151,7 +150,7 @@ describe('e2e: TransitionGroup', () => {
151150
)
152151

153152
expect(await htmlWhenTransitionStart()).toBe(
154-
`<div class="test test-leave-active test-leave-from" ${transitionDisableProp}>a</div>` +
153+
`<div class="test test-leave-active test-leave-from">a</div>` +
155154
`<div class="test">b</div>` +
156155
`<div class="test">c</div>` +
157156
`<div class="test test-enter-active test-enter-from">d</div>`
@@ -279,7 +278,7 @@ describe('e2e: TransitionGroup', () => {
279278
`<div class="test group-enter-active group-enter-from">d</div>` +
280279
`<div class="test">b</div>` +
281280
`<div class="test group-move" style="">a</div>` +
282-
`<div class="test group-leave-active group-leave-from group-move" ${transitionDisableProp}>c</div>`
281+
`<div class="test group-leave-active group-leave-from group-move" style="">c</div>`
283282
)
284283
await nextFrame()
285284
expect(await html('#container')).toBe(
@@ -462,7 +461,7 @@ describe('e2e: TransitionGroup', () => {
462461

463462
// enter + leave
464463
expect(await htmlWhenTransitionStart()).toBe(
465-
`<div class="test test-leave-active test-leave-from" ${transitionDisableProp}>a</div>` +
464+
`<div class="test test-leave-active test-leave-from">a</div>` +
466465
`<div class="test">b</div>` +
467466
`<div class="test">c</div>` +
468467
`<div class="test test-enter-active test-enter-from">d</div>`

0 commit comments

Comments
 (0)