Skip to content

fix(transition): drop the from class when the enter ends - #16434

Open
zhoubiao188 wants to merge 1 commit into
vuejs:mainfrom
zhoubiao188:fix/transition-enter-from-class
Open

zhoubiao188 wants to merge 1 commit into
vuejs:mainfrom
zhoubiao188:fix/transition-enter-from-class

Conversation

@zhoubiao188

@zhoubiao188 zhoubiao188 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The defect

finishEnter clears the to and active classes but not the from class:

const finishEnter = (el, isAppear, done, isCancelled) => {
  el._enterResolve = undefined
  el._enterCancelled = isCancelled
  removeTransitionClass(el, isAppear ? appearToClass : enterToClass)
  removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass)
  done && done()
}

So the nextFrame callback of makeEnterHook removes 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):

nextFrame(() => {
  removeTransitionClass(el, /* from class */)
  ...
  if (el._enterResolve !== resolve) return   // too late, the class is already gone
  addTransitionClass(el, /* to class */)
})

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 finishLeave clears leaveFromClass and onLeave's frame therefore checks _leaveResolve first 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:

<Transition name="test">
  <div v-show="visible" />
</Transition>

visible is set true, then false, then true again before the frame of the first enter runs. .test-enter-from is 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:

<Transition
  enter-from-class="opacity-0"
  leave-from-class="opacity-0"
  enter-active-class="transition-opacity duration-300"
  leave-active-class="transition-opacity duration-300"
>
  <div v-show="visible" />
</Transition>

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):

frame before after
leave starts test-enter-from test-leave-from test-leave-active test-leave-from test-leave-active
stale enter frame test-enter-active test-enter-from test-enter-active
new enter frame test-enter-active test-enter-to test-enter-active test-enter-to

The 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 order onLeave already uses.

  • finishEnter also removes enterFromClass / 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: finishEnter runs synchronously from resolve and from onEnterCancelled / onAppearCancelled. A normal enter is unaffected — the frame removes the class and adds the to class exactly as before, and the later finishEnter removal is a no-op.

Verification

Two tests in the existing stale callbacks (with Transition) block, next to the #16355 / #16357 ones:

  • fails on 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;
  • full unit + unit-jsdom: 4170 passed | 6 skipped (183 files);
  • e2e-browser (the browser Transition / TransitionGroup suites): 88 passed;
  • e2e (jsdom): the 36 test bodies pass; the run reports teardown errors from browser.close() because this machine has no Puppeteer browser, so treat that suite as not evaluated here;
  • tsc --noEmit, eslint, prettier --check clean.

Duplicate check

This is the enter side of the asymmetry that #16134 fixes for leave (_leaveId); that PR does not touch finishEnter or the enter frame. It also does not overlap with #16357 / #16358, which added the _enterResolve / _leaveResolve identity 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 touches finishEnter.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where interrupted show and enter transitions could leave elements with incorrect transition styling. Elements now retain the appropriate appearance during subsequent transitions and reach the expected final visibility and styling.

`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.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The transition code now removes the enter-from class when an enter finishes or is cancelled, and stops stale animation-frame callbacks before they change transition classes. Two regression tests cover cancelled enters followed by another enter or a leave.

Changes: v-show transition class handling

Layer / File(s) Summary
Enter class cleanup and stale callback guard
packages/runtime-dom/src/components/Transition.ts, packages/runtime-dom/__tests__/directives/vShow.spec.ts
finishEnter removes the active enter/appear from-class and, when compatibility mode is enabled, its legacy counterpart. The animation-frame callback checks whether its resolver is current before changing classes. Tests cover a cancelled enter followed by another enter or a leave. They verify transition classes and the final display state.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • vuejs/core#16357: Guards stale enter callbacks on reused elements in the same transition code path.
  • vuejs/core#16355: Prevents stale enter-frame callbacks from adding the enter-to class after cancellation or completion.

Suggested reviewers: edison1105

Merge Risk: Minimal · up to 5ab71

This fixes stale animation-frame callbacks removing a newer enter's or a leave's from class during rapid v-show toggling. The change is localized and has regression tests. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change accurately. The PR makes finishEnter remove the enter/appear from-class (and its compat legacy class) when an enter ends or is cancelled. The summary and objectives describe…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change accurately. The PR makes finishEnter remove the enter/appear from-class (and its compat legacy class) when an enter ends or is cancelled. The summary and objectives describe the same fix, so the title matches the main change. It follows the conventional-commit style, is short, and avoids vague terms.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7658778a-c87c-450f-9b66-ee8c1c0d6306
Commits

Reviewing files that changed from the base of the PR and between 44234e8 and 5ab7164.

Files selected for processing: 2

  • packages/runtime-dom/__tests__/directives/vShow.spec.ts
  • packages/runtime-dom/src/components/Transition.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@16434
npm i https://pkg.pr.new/@vue/compiler-core@16434
yarn add https://pkg.pr.new/@vue/compiler-core@16434.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@16434
npm i https://pkg.pr.new/@vue/compiler-dom@16434
yarn add https://pkg.pr.new/@vue/compiler-dom@16434.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@16434
npm i https://pkg.pr.new/@vue/compiler-sfc@16434
yarn add https://pkg.pr.new/@vue/compiler-sfc@16434.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@16434
npm i https://pkg.pr.new/@vue/compiler-ssr@16434
yarn add https://pkg.pr.new/@vue/compiler-ssr@16434.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@16434
npm i https://pkg.pr.new/@vue/reactivity@16434
yarn add https://pkg.pr.new/@vue/reactivity@16434.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@16434
npm i https://pkg.pr.new/@vue/runtime-core@16434
yarn add https://pkg.pr.new/@vue/runtime-core@16434.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@16434
npm i https://pkg.pr.new/@vue/runtime-dom@16434
yarn add https://pkg.pr.new/@vue/runtime-dom@16434.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@16434
npm i https://pkg.pr.new/@vue/server-renderer@16434
yarn add https://pkg.pr.new/@vue/server-renderer@16434.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@16434
npm i https://pkg.pr.new/@vue/shared@16434
yarn add https://pkg.pr.new/@vue/shared@16434.tgz

vue

pnpm add https://pkg.pr.new/vue@16434
npm i https://pkg.pr.new/vue@16434
yarn add https://pkg.pr.new/vue@16434.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@16434
npm i https://pkg.pr.new/@vue/compat@16434
yarn add https://pkg.pr.new/@vue/compat@16434.tgz

commit: 5ab7164

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 115 kB (+12 B) 43.1 kB (-3 B) 38.6 kB (-36 B)
vue.global.prod.js 174 kB (+12 B) 63.5 kB (+1 B) 56.4 kB (+24 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 52.9 kB 20.4 kB 18.7 kB
createApp 61.1 kB 23.5 kB 21.5 kB
createSSRApp 65.9 kB 25.5 kB 23.2 kB
defineCustomElement 67.4 kB 25.4 kB 23.2 kB
overall 77.2 kB (+12 B) 29.3 kB (-2 B) 26.6 kB

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant