ant-design / ant-design/pro-components

🐛[BUG] ProTable columnsState 设置 persistenceType 后初次加载会触发 onChange

Open
#8,260 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 描述
1、ProTable组件columnsState 设置 persistenceType 后初次加载会触发 onChange,不设置persistenceType时初次加载不会触发 onChange 事件
2、当设置value通过受控方式设置列状态时,初次加载触发onChange事件,如果storage里还没有缓存persistenceKey对应的内容,onChange回调获得的值非value设置的值,而是所有列字段 { "show": true },随后storage里缓存的列状态对象设置成value对应的值

### 📷 复现步骤

1、设置columnsState的persistenceType、persistenceKey、value、onChange(console.log打印获得的列状态value)
2、清空persistenceType对应的storage
3、加载组件

### 🏞 期望结果
在设置persistenceKey、persistenceType、value前提下
1、初次加载时,并未通过界面操作改变列状态,不希望触发onChange事件
2、可以接受加载时触发onChange事件,但希望获得的值是value对应的值,而不是所有列字段 { "show": true }

onChange中会对列状态的改变进行一些校验,例如限制显示列的数量,上述问题会导致由于第一次加载时所有列字段 { "show": true },触发了校验

### 💻 复现代码

复现地址:https://codesandbox.io/p/sandbox/shu-xing-zhan-shi-forked-y9kk9r?file=%2FApp.tsx

### © 版本信息

- ProComponents 版本: 2.6.50
- umi 版本
- 浏览器环境
- 开发环境 [e.g. mac OS]

### 🚑 其他信息
![image](https://github.com/ant-design/pro-components/assets/4035181/c8c326b2-cf86-48c8-b200-5c651abf3728)
![image](https://github.com/ant-design/pro-components/assets/4035181/e885c0ad-18c8-4c79-b083-58cd220508ed)

Contributor guide

Open the contributing guide

Research direction

Start with the linked CodeSandbox reproduction and the ProTable columnsState initialization path, using an empty persistence storage with persistenceKey, persistenceType, value, and onChange. Compare the initial controlled value with the value sent to onChange and persisted to storage. Done means initial loading does not invoke onChange, or invokes it with the controlled value rather than all columns set to {"show":true}.

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
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.