Skip to content

feat(vue2): 优化组件安装逻辑,避免重复安装#369

Merged
YufJi merged 2 commits into
testfrom
task/3409715697838336
Jun 22, 2026
Merged

feat(vue2): 优化组件安装逻辑,避免重复安装#369
YufJi merged 2 commits into
testfrom
task/3409715697838336

Conversation

@YufJi

@YufJi YufJi commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

配合vue2源码依赖库拆分功能

Summary by CodeRabbit

发布说明

  • Bug Fixes

    • 修复了组件在多次调用安装过程中可能重复注册的问题,已加入跨调用去重防护,避免重复安装与依赖处理。
  • Performance

    • 优化了生产环境的代码分割与缓存策略,调整了代码块的归类规则与请求分配方式,提升资源加载与缓存效率。

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 962d81e8-3d23-49e5-b258-c6a5a8521ec0

📥 Commits

Reviewing files that changed from the base of the PR and between be3ed7e and 13c190b.

📒 Files selected for processing (1)
  • packages/vue2/src/utils/install.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vue2/src/utils/install.js

Walkthrough

vue.config.js 生产环境配置中,重构了 splitChunkscacheGroups,调整了 vue/lcap/vendors 三个分组的匹配规则与优先级。在 install.js 中,为 installComponents 函数添加了基于 WeakMapWeakSet 的去重机制,防止对同一 Components 实例重复注册。

Changes

Vue2 构建分包配置与组件安装去重

Layer / File(s) Summary
生产环境 splitChunks 缓存分组重构
packages/vue2/source/vue.config.js
移除 maxInitialRequests/maxAsyncRequests 顶层限制,将 cacheGroupsvue 组的正则扩展至 pinia/vue-router/vue-i18nvendors 组新增 chunks: 'initial',各组 priority 相应调整。
installComponents 去重机制
packages/vue2/src/utils/install.js
模块级新增 installed WeakMap(以 Vue 实例为 key,对应 WeakSet 为 value),installComponents 入口处检查 Components 引用,已安装则直接返回;安装完成后将 Components 加入对应 WeakSet,拦截后续重复调用。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • netease-lcap/lcap-template#368: 同样修改了 packages/vue2/source/vue.config.jsoptimization.splitChunkscacheGroups(vue/lcap/vendors 分块规则),与本 PR 的分包配置变更直接相关。

Poem

🐇 小兔子跳进代码丛,
分包配置重新梳,
vue 与 pinia 同一路,
重复安装不再有,
installed WeakSet 守门户,
构建更快兔欢呼! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题清晰准确地总结了主要改动:优化Vue2组件安装逻辑并避免重复安装,与raw_summary和pr_objectives中的改动完全对应。
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/3409715697838336

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/vue2/src/utils/install.js`:
- Around line 24-27: The deduplication logic in the installComponents function
only tracks Components without considering the Vue instance, causing the same
Components to be incorrectly skipped if installed to different Vue constructors.
Change the installed tracking mechanism from a simple Set that stores only
Components to a structure that tracks the combination of both Vue and Components
(such as using a composite key or Map). Update the check at line 26 to verify if
the specific (Vue, Components) pair has been installed, and ensure the pair is
added to the tracking structure after registration. Apply the same fix to the
similar check mentioned at line 59 to maintain consistency across all
deduplication points in the function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 02b64977-20fb-4b20-8ccd-752f48be92ec

📥 Commits

Reviewing files that changed from the base of the PR and between 9875eda and be3ed7e.

📒 Files selected for processing (2)
  • packages/vue2/source/vue.config.js
  • packages/vue2/src/utils/install.js

Comment thread packages/vue2/src/utils/install.js Outdated
@YufJi YufJi merged commit c63b762 into test Jun 22, 2026
2 checks passed
@YufJi YufJi deleted the task/3409715697838336 branch June 22, 2026 05:29
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