-
-
Notifications
You must be signed in to change notification settings - Fork 9k
fix(KeepAlive): use resolved component name for async components in cache pruning #14212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughFixed cache pruning in KeepAlive for async components by extracting the component name from the inner resolved component ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/runtime-core/src/components/KeepAlive.ts (1)
310-316: LGTM! Consistent name resolution for async components in render logic.The logic correctly mirrors the pruneCache implementation, ensuring that both cache pruning and include/exclude filtering use the resolved inner component for name extraction.
Consider extracting the component resolution logic into a helper function to reduce duplication:
function getComponentForNameCheck(vnode: VNode): ConcreteComponent { return isAsyncWrapper(vnode) ? (vnode.type as ComponentOptions).__asyncResolved || {} : (vnode.type as ConcreteComponent) }Then use it in both locations:
-const name = getComponentName( - isAsyncWrapper(vnode) - ? (vnode.type as ComponentOptions).__asyncResolved || {} - : comp, -) +const name = getComponentName(getComponentForNameCheck(vnode))This would improve maintainability if the logic needs to change in the future.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/runtime-core/__tests__/components/KeepAlive.spec.ts(1 hunks)packages/runtime-core/src/components/KeepAlive.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/runtime-core/__tests__/components/KeepAlive.spec.ts (3)
packages/runtime-core/src/components/KeepAlive.ts (1)
KeepAlive(383-393)packages/runtime-test/src/serialize.ts (1)
serializeInner(22-33)packages/vue/__tests__/e2e/e2eUtils.ts (1)
timeout(16-17)
packages/runtime-core/src/components/KeepAlive.ts (2)
packages/runtime-core/src/component.ts (3)
getComponentName(1210-1217)ComponentOptions(276-276)ConcreteComponent(248-258)packages/runtime-core/src/apiAsyncComponent.ts (1)
isAsyncWrapper(43-44)
🔇 Additional comments (2)
packages/runtime-core/src/components/KeepAlive.ts (1)
203-216: LGTM! Correct fix for async component name resolution in cache pruning.The logic correctly extracts the component name from the resolved inner component (
__asyncResolved) for async wrappers, ensuring that async components are properly matched against include/exclude patterns during cache pruning. The|| {}fallback safely handles cases where the async component hasn't resolved yet.packages/runtime-core/__tests__/components/KeepAlive.spec.ts (1)
1177-1224: LGTM! Comprehensive test coverage for async component caching with include updates.The test effectively validates the fix for issue #14210 by:
- Creating and resolving an async component
- Modifying component state (incrementing count)
- Updating the
includeprop (triggering pruneCache)- Verifying state preservation after re-activation
The test correctly creates a new array reference on line 1216 (
['Foo']), which triggers the watcher and exercises the cache pruning logic with the fixed async component name resolution.
Size ReportBundles
Usages
|
@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: |
Fix: #14210
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.