Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/corePublic

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
edison1105 merged 1 commit intovuejs:mainfromhuangxiuqi:fix-14210
Dec 18, 2025

Conversation

@huangxiuqi
Copy link
Contributor

@huangxiuqihuangxiuqi commentedDec 17, 2025
edited by coderabbitaibot
Loading

Fix:#14210

Summary by CodeRabbit

  • Bug Fixes

    • Improved KeepAlive to correctly identify async components when applying include/exclude filter rules, ensuring proper cache behavior with dynamic prop updates.
  • Tests

    • Added test coverage for async components with dynamic include prop changes, verifying state preservation across visibility toggles.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitaibot commentedDec 17, 2025
edited
Loading

Walkthrough

Fixed cache pruning in KeepAlive for async components by extracting the component name from the inner resolved component (__asyncResolved) instead of the wrapper vnode when determining which cache entries to prune during include/exclude prop updates. Adds test coverage for this scenario.

Changes

Cohort / File(s)Summary
KeepAlive async component caching fix
packages/runtime-core/src/components/KeepAlive.ts
ModifiedpruneCache method to check if vnode is an async wrapper and use the inner loaded component for name extraction; otherwise uses the original vnode.type for include/exclude filter matching
KeepAlive test coverage
packages/runtime-core/__tests__/components/KeepAlive.spec.ts
Added test case "should work with async component when updateinclude props" to verify state preservation when toggling async component visibility while dynamically updating include prop

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify the conditional logic correctly identifies async wrapper vnodes and extracts the resolved component name
  • Ensure the fix doesn't affect non-async component caching behavior
  • Confirm test case properly exercises the fixed async component + dynamic include scenario

Suggested labels

ready to merge,:hammer: p3-minor-bug

Poem

🐰 A cache kept losing async friends so dear,
When include props changed, they'd just disappear!
Now resolved components stay, state intact,
KeepAlive remembers—the fix is exact! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.You can run@coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check✅ PassedThe PR fixes the identified issue by modifying KeepAlive's pruneCache to correctly extract component names from async wrappers, ensuring async components are properly cached when include list updates occur.
Out of Scope Changes check✅ PassedAll changes are scoped to fixing the async component caching issue: test coverage for async components with dynamic include props and the pruneCache logic fix for async component name resolution.
Title check✅ PassedThe title clearly and specifically describes the main change: fixing KeepAlive to use the resolved component name for async components during cache pruning, which directly addresses the linked issue#14210.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

❤️ Share

Comment@coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitaicoderabbitaibot left a 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:

functiongetComponentForNameCheck(vnode:VNode):ConcreteComponent{returnisAsyncWrapper(vnode)    ?(vnode.typeasComponentOptions).__asyncResolved||{}    :(vnode.typeasConcreteComponent)}

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

📥 Commits

Reviewing files that changed from the base of the PR and betweend8a2de4 and75519f8.

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

  1. Creating and resolving an async component
  2. Modifying component state (incrementing count)
  3. Updating theinclude prop (triggering pruneCache)
  4. 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.

@edison1105edison1105 changed the titlefix(KeepAlive): should work with async component when update include …fix(KeepAlive): should work with async component when update include propDec 17, 2025
@github-actions
Copy link

Size Report

Bundles

FileSizeGzipBrotli
runtime-dom.global.prod.js103 kB (+33 B)39 kB (+4 B)35.2 kB (+71 B)
vue.global.prod.js161 kB (+33 B)58.9 kB (+4 B)52.5 kB (+17 B)

Usages

NameSizeGzipBrotli
createApp (CAPI only)46.9 kB18.3 kB16.8 kB
createApp55 kB21.4 kB19.6 kB
createSSRApp59.3 kB23.1 kB21.1 kB
defineCustomElement60.6 kB23.1 kB21.1 kB
overall69.4 kB (+33 B)26.6 kB (+7 B)24.3 kB (+4 B)

@pkg-pr-new
Copy link

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit:75519f8

@edison1105edison1105 changed the titlefix(KeepAlive): should work with async component when update include propfix(KeepAlive): use resolved component name for async components in cache pruningDec 17, 2025
@edison1105edison1105 added ready to mergeThe PR is ready to be merged. 🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage. labelsDec 17, 2025
@edison1105edison1105 merged commitdfe667c intovuejs:mainDec 18, 2025
14 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

Assignees

No one assigned

Labels

🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.ready to mergeThe PR is ready to be merged.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

updating keepalive include will cause asyn loaded components to not be cached.

2 participants

@huangxiuqi@edison1105

[8]ページ先頭

©2009-2025 Movatter.jp