Skip to content

Conversation

@JounQin
Copy link
Collaborator

@JounQin JounQin commented Dec 24, 2025

Summary

render empty nav items correctly not link, empty items should already be handlered at

return menuItem.items.length > 0 ? (
<li
className="rp-nav-menu__item"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onClick={handleMouseEnter}
>
{inner}
{hoverGroup}
</li>
) : (
<li className="rp-nav-menu__item">{inner}</li>
);
}

Related Issue

N/A

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 24, 2025 14:24
@netlify
Copy link

netlify bot commented Dec 24, 2025

Deploy Preview for rspress-v2 ready!

Name Link
🔨 Latest commit 2991dc5
🔍 Latest deploy log https://app.netlify.com/projects/rspress-v2/deploys/694e8c7f4156c100087e98d1
😎 Deploy Preview https://deploy-preview-2929--rspress-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where navigation items with empty children arrays were incorrectly rendered as links instead of being handled as parent menu items. The fix removes the length check when determining whether an item should be treated as a menu with children, allowing the downstream NavMenuItemWithChildren component (which already handles empty arrays at lines 47-60) to properly render these items.

Key Changes:

  • Removed the item.items.length > 0 check from the condition in NavMenuItem, now only checking if items property exists and is an array
  • This ensures items with empty children arrays are passed to NavMenuItemWithChildren instead of being incorrectly cast to NavItemWithLink

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JounQin JounQin force-pushed the fix/nav_empty_items branch from 4c9bb62 to ef93163 Compare December 24, 2025 14:35
@JounQin JounQin force-pushed the fix/nav_empty_items branch from ef93163 to ad5bbb6 Compare December 25, 2025 16:18
@JounQin JounQin requested a review from SoonIter December 25, 2025 16:19
@SoonIter
Copy link
Member

遇到了什么问题吗,预期是 items: [] 时,<SvgDown className="rp-nav-menu__item__icon" /> 也不会显示

@JounQin
Copy link
Collaborator Author

JounQin commented Dec 26, 2025

遇到了什么问题吗,预期是 items: [] 时,<SvgDown className="rp-nav-menu__item__icon" /> 也不会显示

现在 items: [] 时渲染了 NavMenuItemWithLink,没有 link 配置但渲染出了空 link

<Link href={menuItem.link} className="rp-nav-menu__item__container">

menuItem.items.length > 0 的逻辑已经在下面判断了

return menuItem.items.length > 0 ? (


@SoonIter 加了个判断 2991dc5

这里其实 item 就是 NavItemWithLink,直接用 NavScreenMenuItemWithLink 渲染就行了,不用递归 NavScreenMenuItemWithChildren 导致还是用可选链判断

@JounQin JounQin mentioned this pull request Dec 26, 2025
2 tasks
@JounQin JounQin force-pushed the fix/nav_empty_items branch from cc7d72a to b0c2cc6 Compare December 26, 2025 12:48
@JounQin JounQin force-pushed the fix/nav_empty_items branch from b0c2cc6 to 2991dc5 Compare December 26, 2025 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants