diff --git a/packages/runtime-dom/src/components/Transition.ts b/packages/runtime-dom/src/components/Transition.ts
index a331c53c235..fb2cbe0ce1c 100644
--- a/packages/runtime-dom/src/components/Transition.ts
+++ b/packages/runtime-dom/src/components/Transition.ts
@@ -195,10 +195,12 @@ export function resolveTransitionProps(
       nextFrame(() => {
         removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass)
         if (__COMPAT__ && legacyClassEnabled) {
-          removeTransitionClass(
-            el,
-            isAppear ? legacyAppearFromClass : legacyEnterFromClass
-          )
+          const legacyClass = isAppear
+            ? legacyAppearFromClass
+            : legacyEnterFromClass
+          if (legacyClass) {
+            removeTransitionClass(el, legacyClass)
+          }
         }
         addTransitionClass(el, isAppear ? appearToClass : enterToClass)
         if (!hasExplicitCallback(hook)) {
@@ -212,7 +214,7 @@ export function resolveTransitionProps(
     onBeforeEnter(el) {
       callHook(onBeforeEnter, [el])
       addTransitionClass(el, enterFromClass)
-      if (__COMPAT__ && legacyClassEnabled) {
+      if (__COMPAT__ && legacyClassEnabled && legacyEnterFromClass) {
         addTransitionClass(el, legacyEnterFromClass)
       }
       addTransitionClass(el, enterActiveClass)
@@ -220,7 +222,7 @@ export function resolveTransitionProps(
     onBeforeAppear(el) {
       callHook(onBeforeAppear, [el])
       addTransitionClass(el, appearFromClass)
-      if (__COMPAT__ && legacyClassEnabled) {
+      if (__COMPAT__ && legacyClassEnabled && legacyAppearFromClass) {
         addTransitionClass(el, legacyAppearFromClass)
       }
       addTransitionClass(el, appearActiveClass)
@@ -231,7 +233,7 @@ export function resolveTransitionProps(
       el._isLeaving = true
       const resolve = () => finishLeave(el, done)
       addTransitionClass(el, leaveFromClass)
-      if (__COMPAT__ && legacyClassEnabled) {
+      if (__COMPAT__ && legacyClassEnabled && legacyLeaveFromClass) {
         addTransitionClass(el, legacyLeaveFromClass)
       }
       // force reflow so *-leave-from classes immediately take effect (#2593)
@@ -243,7 +245,7 @@ export function resolveTransitionProps(
           return
         }
         removeTransitionClass(el, leaveFromClass)
-        if (__COMPAT__ && legacyClassEnabled) {
+        if (__COMPAT__ && legacyClassEnabled && legacyLeaveFromClass) {
           removeTransitionClass(el, legacyLeaveFromClass)
         }
         addTransitionClass(el, leaveToClass)