-
Notifications
You must be signed in to change notification settings - Fork 73
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
fix(menu): 修复menu组件在app平台报错的问题 #443
Conversation
Walkthrough该拉取请求对 Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for nutui-uniapp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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
🧹 Outside diff range and nitpick comments (1)
packages/nutui/components/menuitem/menuitem.vue (1)
90-97
: 将 renderTitle 重构为计算属性是个很好的改进
这个改动解决了递归更新的问题,原因如下:
- 计算属性具有响应式缓存机制,只有在依赖发生变化时才会重新计算
- 避免了在模板中多次调用函数可能导致的性能问题
建议考虑以下优化:
- 为计算属性添加类型注解,提高代码的可维护性
- 考虑将 options 的查找逻辑抽离为独立的计算属性,进一步优化性能
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- packages/nutui/components/menu/menu.vue (1 hunks)
- packages/nutui/components/menuitem/menuitem.vue (2 hunks)
🔇 Additional comments (2)
packages/nutui/components/menu/menu.vue (1)
104-104
: 修改渲染逻辑解决了递归更新问题
将 renderTitle()
方法调用改为直接使用 title
计算属性是个很好的改进,这样可以避免在渲染过程中触发递归更新。
运行以下脚本验证 menuitem 组件中是否正确定义了 title 计算属性:
packages/nutui/components/menuitem/menuitem.vue (1)
134-134
: 确保 title 计算属性被正确导出
在 setup 返回对象中添加 title 计算属性是正确的做法,这样确保了组件接口的一致性。
运行以下脚本验证 menu 组件是否正确使用了新的 title 计算属性:
✅ Verification successful
title 计算属性已正确实现和导出
经过验证,menuitem.vue 组件中已正确实现了 title 计算属性:
- 在 setup 中通过 computed 定义
- 正确处理了 props.title 和从 options 中获取文本的逻辑
- 在 setup 的返回对象中正确导出
- 在模板中被正确使用
代码实现完全符合预期,不需要进行任何修改。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:验证 menu 组件中是否还存在对 renderTitle 的调用
# 测试:搜索可能存在的 renderTitle 调用
rg "renderTitle" --type vue
Length of output: 55
Script:
#!/bin/bash
# 搜索所有可能的 Vue 文件中的 renderTitle
rg "renderTitle" --type-list # 首先检查支持的文件类型
rg "renderTitle" -g "*.vue" # 使用 glob 模式搜索 .vue 文件
# 查找相关的 MenuItem 组件引用
rg "MenuItem" -g "*.vue" -A 5 -B 5
# 检查 menuitem.vue 文件的完整内容
fd -g "menuitem.vue" --exec cat {}
Length of output: 9874
(cherry picked from commit 9501324)
Description
menu
组件在app平台会报错,导致menu-item
渲染错误Maximum recursive updates exceeded in component <nut-menu>. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.
将
renderTitle
改为computed
后可解决Linked Issues
Additional Context