fix(runtime-core): skip persisted transition hooks when moving kept-alive nodes (fix #14031)#14865
fix(runtime-core): skip persisted transition hooks when moving kept-alive nodes (fix #14031)#14865LeSingh1 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes issue ChangesPersisted Transition Behavior Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Fixes #14031.
When a
<keep-alive>activates or deactivates a cached child, the renderer'smovefunction callstransition.beforeEnter/transition.enter(orleave) on every element vnode that carries a transition. For a normal transition this is correct, but for a persisted transition (the flag the template compiler injects when<Transition>has a singlev-showchild) the lifecycle is owned by the directive, not by mount/move. The element is being moved in or out of a detached storage container; the visibility is already controlled byv-show.As a result, every cache hit was firing
onBeforeEnter/onEnterand (because no async hook keeps it pending)onAfterEnter, even when thev-showtarget was never displayed. The reproduction in the issue uses av-show="false"element inside a<keep-alive>and observesafter-enterlogged on each toggle.The fix extends the same
!transition.persistedguard thatmountElementalready uses (via the module-levelneedTransitionhelper) to the per-element branch insidemove. Persisted transitions still get theirhostInsertso the element is correctly relocated between the live tree and the keep-alive storage container, but the directive-owned enter / leave hooks are no longer called behind the directive's back. The existing#13153interaction with_isLeavinglives outside the persisted path and is unaffected.Added a regression test in
BaseTransition.spec.tsthat wraps aKeepAliveswitching between two components inside aBaseTransitionwithpersisted: trueand asserts that none of the enter or leave hooks fire on activate or deactivate. The test fails onmain(the deactivate path callsonBeforeLeave/onLeaveand the activate path calls all three enter hooks via the immediatedone()inBaseTransition) and passes with the change.Summary by CodeRabbit
KeepAlivecomponents. Switching between cached components now works smoothly without unintended animation hooks firing.