ant-design / ant-design/pro-components

🐛[BUG] menu中配置中,如果直接修改了defaultMenuData中的信息,会在生产环境导致404

Open
#8,355 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 描述

layout配置中,配置了menu.request,在方法里,如果直接修改defaultMenuData中的数据,移除了某些路由项,会导致直接前端页面跳转404

我通过做defaultMenuData和自己系统的ACL做匹配进行权限管控,如果ACL中没有和defaultMenuData中name相同的内容则不显示菜单。我认为defaultMenuData只对菜单进行控制,于是直接将没在ACL中的项进行了移除。导致前端直接跳转某些hiddenInMenu的页面报404(因为hideInMenu项并不在我的ACL中,我的ACL只控制了显示菜单项)而诡异的是,如果对这个页面进行刷新,该页面又能正常访问。

并且该问题仅在生产环境中出现。开发调试过程中没有。通过抓包发现,正常前端跳转至这个页面不会触发远程加载页面js,即没有p__xxx__index.xxxx.js请求。而通过刷新或者重进入该页面,会进行p__xxx__index.xxxx.js请求,并正常加载页面。

猜测:因为更改了defaultMenuData,导致某些优化丢弃了该页面的引用,导致前端跳转404.

### 📷 复现步骤
layout配置中,配置menu.request,直接修改defaultMenuData,丢弃某些页面。编译发布至正式环境,点击进入这些页面的链接,页面报404,并且不会进行页面js远程加载。在该404页面进行页面刷新,能够正常浏览该页面。

### 🏞 期望结果

经过测试,如果对defaultMenuData进行直接更改会触发这个bug,如果对defaultMenuData进行一定程度的深度拷贝(例如每一项都{...item})则可以规避这一bug。
期望可以将defaultMenuData的入参就是已经拷贝过的入参。

### 💻 复现代码

```tsx
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
//....
menu: {
request: async (params, defaultMenuData) => {
//直接移除defaultMenuData中的一些item
}
//....
}
```

### © 版本信息

- ProComponents 版本:^2.6.48
- umi 版本 4.1.4
- 浏览器环境 edge 124.0.2478.51
- 开发环境 Windows

Contributor guide

Open the contributing guide

Research direction

Start with the layout configuration's menu.request entry point and the defaultMenuData argument, then reproduce the issue with a production build using the provided TypeScript example. Compare direct mutation with copying each menu item and verify that navigation loads the page JavaScript and avoids a 404 without requiring a refresh.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.