ant-design / ant-design/pro-components

🐛[BUG] [ProLayout] 升级 3.1.14-7 后,异步菜单配置 defaultOpenAll 无法默认展开子菜单

Open
#9,697 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.8k
Forks
1.4k
Avg merge
10h 44m
Merged PRs (30d)
3

Description

### 🐛 bug 描述

升级 `@ant-design/pro-components` 后,ProLayout 的侧栏菜单无法按配置默认展开。

项目使用 `layout="mix"`、`splitMenus={true}`,通过 `menu.request` 异步加载菜单。非项目中心页面设置了:

```tsx
menu={{
defaultOpenAll: true,
ignoreFlatMenu: true,
}}
```

但菜单加载完成后,包含子菜单的节点仍然处于收起状态,例如截图中的「项目医院申请」「设置」。

上述配置在升级前可以正常使用,目前尚未确定引入问题的具体版本。

### 📷 复现步骤

1. 使用 ProLayout,设置 `layout="mix"` 和 `splitMenus={true}`。
2. 使用 `menu.request` 异步返回包含多级子菜单的菜单数据。
3. 设置 `menu.defaultOpenAll=true`、`menu.ignoreFlatMenu=true`。
4. 打开或刷新页面,等待菜单加载完成。
5. 观察侧栏:包含子菜单的节点没有默认展开。

### 🏞 期望结果

异步菜单加载完成后,侧栏所有子菜单默认展开。

用户仍然可以手动展开、收起子菜单。

### 💻 复现代码

以下是根据业务配置简化的示例,尚未在独立项目中验证:

```tsx
import { ProLayout } from '@ant-design/pro-components';

export default function Demo() {
return (
[
{
path: '/platform/project',
name: '项目',
children: [
{
path: '/platform/project/workbench',
name: '运营工作台',
},
{
path: '/platform/project/hospital',
name: '项目医院申请',
children: [
{
path: '/platform/project/hospital/list',
name: '申请列表',
},
],
},
{
path: '/platform/project/settings',
name: '设置',
children: [
{
path: '/platform/project/settings/project',
name: '项目设置',
},
{
path: '/platform/project/settings/form',
name: '表单设置',
},
],
},
],
},
],
}}
>
运营工作台

);
}
```

### © 版本信息

- ProComponents:`3.1.14-7`
- Umi:项目依赖 `@umijs/max: ^4.7.12`
- Ant Design:项目依赖 `antd: ^6.6.2`
- 浏览器环境:待补充浏览器名称及版本
- 开发环境:Windows,本地开发服务 `localhost:8000`

### 🚑 其他信息

已尝试:

- 将 `autoClose: true` 改为 `undefined`,问题仍然存在。
- 通过菜单结构生成 React `key`,在菜单数据变化时重新挂载菜单,问题仍然存在。

检查当前版本的 `BaseMenu` 源码发现,展开状态初始化依赖 `menu.defaultOpenAll`,相关 effect 的依赖包含 `matchMenuKeys`、`collapsed`,没有直接包含 `menuData`。这可能与异步加载或菜单切换有关,但尚未确认根因。

Contributor guide

Open the contributing guide

Research direction

Start with the ProLayout and BaseMenu entry points, reproducing the issue with layout="mix", splitMenus, menu.request, defaultOpenAll, and ignoreFlatMenu. Inspect how the BaseMenu effect responds when asynchronously loaded menuData changes, then verify that all nested menus open after loading while users can still expand and collapse them manually.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.