Repository navigation
fix(transition): drop the from class when the enter ends - #16434
zhoubiao188 wants to merge 1 commit into
Conversation
`finishEnter` clears the to and active classes but not the from class, so the `nextFrame` callback of `makeEnterHook` has to remove it. That callback cannot know whether the class is still its own: it removes the class before checking `_enterResolve`, which is the only way a cancelled enter gets cleaned up. When another enter has started on the element in the meantime, the stale frame strips the from class of that enter instead. The leave side does not have this problem: `finishLeave` clears `leaveFromClass`, so `onLeave`'s frame checks `_leaveResolve` first and touches nothing when it is stale. Move the from class removal into `finishEnter` and check the enter identity before touching any class, which makes the enter path match the leave one. This shows up as two glitches with `v-show` + `<Transition>`: - entering again before the frame of a cancelled enter removes the from class of the new enter, so it jumps to the to state instead of animating from it; - when `enter-from-class` is shared with `leave-from-class` (e.g. a Tailwind `transition-opacity` utility), the same frame removes the leave's from class and the element disappears without a leave transition.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Size ReportBundles
Usages
|
The defect
finishEnterclears thetoandactiveclasses but not thefromclass:So the
nextFramecallback ofmakeEnterHookremoves it instead — and to still clean up a cancelled enter, it has to remove it before checking whether the enter is still the current one (#16357):Once another enter has started on the element, that stale frame strips the from class of the new enter.
The leave path does not have this problem, because
finishLeaveclearsleaveFromClassandonLeave's frame therefore checks_leaveResolvefirst and touches nothing when it is stale. Enter and leave disagree on who owns the class.Two consequences with
v-show+<Transition>:1. A re-enter loses its from class, so it jumps to the to state instead of animating from it:
visibleis settrue, thenfalse, thentrueagain before the frame of the first enter runs..test-enter-fromis removed by the stale frame, and the second enter animates from nothing.2. A leave loses a from class shared with
enter-from-class— e.g. a Tailwind utility class on both sides:Entering and hiding before the enter frame runs leaves the element with no
opacity-0, so it disappears without a leave transition.Measured class list, stepping frames with fake timers, on the same template (
:duration="100",visible: true → false → true):test-enter-from test-leave-from test-leave-activetest-leave-from test-leave-activetest-enter-activetest-enter-from test-enter-activetest-enter-active test-enter-totest-enter-active test-enter-toThe fix
Give the from class to
finishEnter, where the enter that owns it ends, and let the frame check the enter identity before touching any class — the same orderonLeavealready uses.finishEnteralso removesenterFromClass/appearFromClass(and the compat legacy class);makeEnterHook's frame returns early when_enterResolve !== resolve, before removing anything.A finished or cancelled enter is still fully cleaned up:
finishEnterruns synchronously fromresolveand fromonEnterCancelled/onAppearCancelled. A normal enter is unaffected — the frame removes the class and adds the to class exactly as before, and the laterfinishEnterremoval is a no-op.Verification
Two tests in the existing
stale callbacks (with Transition)block, next to the#16355/#16357ones:44234e82(expected 'test-enter-active' to be 'test-enter-from test-enter-active'— the new enter's from class;expected 'fade-out' to be 'fade fade-out'— the leave's shared from class), passes with the patch;unit+unit-jsdom:4170 passed | 6 skipped(183 files);e2e-browser(the browserTransition/TransitionGroupsuites):88 passed;e2e(jsdom): the 36 test bodies pass; the run reports teardown errors frombrowser.close()because this machine has no Puppeteer browser, so treat that suite as not evaluated here;tsc --noEmit,eslint,prettier --checkclean.Duplicate check
This is the enter side of the asymmetry that #16134 fixes for leave (
_leaveId); that PR does not touchfinishEnteror the enter frame. It also does not overlap with #16357 / #16358, which added the_enterResolve/_leaveResolveidentity checks: this patch keeps those checks and only moves the from class removal below them, so it is a follow-up rather than a replacement. No open PR touchesfinishEnter.Summary by CodeRabbit