Skip to content
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

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

RJQingHuan
Copy link
Member

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

Copy link

coderabbitai bot commented Oct 30, 2024

Walkthrough

该拉取请求对 menu.vuemenuitem.vue 组件进行了修改。在 menu.vue 中,菜单项标题的渲染逻辑由调用 item.renderTitle() 改为直接引用 item.title,简化了标题渲染过程。menuitem.vue 中,renderTitle 函数被重命名为计算属性 title,增强了标题的响应性。整体组件结构和功能保持不变。

Changes

文件路径 更改摘要
packages/nutui/components/menu/menu.vue 将菜单项标题渲染从 item.renderTitle() 改为直接引用 item.title
packages/nutui/components/menuitem/menuitem.vue renderTitle 函数重命名为计算属性 title,并将其包含在 setup 函数的返回对象中。

Possibly related PRs

  • feat(menu): add scroll-top prop #377: 此 PR 涉及对 menu.vue 文件的修改,特别是引入了新的 scroll-top 属性,增强了菜单的功能,直接与主 PR 中的渲染逻辑变化相关。

Suggested labels

size/M

Suggested reviewers

  • yang1206
  • xiaohe0601

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for nutui-uniapp ready!

Name Link
🔨 Latest commit 407a411
🔍 Latest deploy log https://app.netlify.com/sites/nutui-uniapp/deploys/67218861eed1bd0008fd81bb
😎 Deploy Preview https://deploy-preview-443--nutui-uniapp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 95 (🔴 down 1 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 70 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@RJQingHuan RJQingHuan requested a review from yang1206 October 30, 2024 01:15
Copy link

@coderabbitai coderabbitai bot 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

🧹 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

📥 Commits

Files that changed from the base of the PR and between 7b3bc4b and 407a411.

📒 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

@yang1206 yang1206 merged commit 9501324 into nutui-uniapp:main Oct 30, 2024
5 checks passed
xiaohe0601 pushed a commit that referenced this pull request Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants