ant-design / ant-design/pro-components

🐛[BUG] BetaSchemaFom 传入 request ,filedProps 为函数, 请求完成后 select 组件选择一项, 拿到的 form 是空对象

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

Description

复现步骤:
1. BetaSchemaFom 传入 filedProps 为函数, 传入 request
2. 请求完成后 select 组件选择一项,
3. 此时查看console.log拿到的 form 是空对象。
4. 第二次操作,才拿到了正常的 form。
![image](https://github.com/ant-design/pro-components/assets/133521363/30875433-53a6-473b-a689-0423debb433e)

期望: 第一次拿到的就为带有各类方法的 form

代码调试发现bug原因:
1. BaseForm 定义 formRef = useRef({});
2. 然后 createField 的 changedProps 执行, 此时 formRef.current 为 {};
3. onInit 触发, 修改了 formRef.curent 的内容为带有方法的对象, 但此时对之前的 changedProps 行为不会生效;
4. 不生效的原因, components/SchemaForm/index 的 genItems 未重新执行, 因为其依赖是 !!formRef.current, formRef.current为{}再为带方法的对象并不会触发更新
![image](https://github.com/ant-design/pro-components/assets/33081977/146bf603-fe93-4311-aa03-7f269f388086)

解决方案: BaseForm/BaseForm 文件, 将 formRef = useRef({}) 改为 formRef = useRef(null)。此方案已在我本地调试时解决此bug,但不确定是否影响了其他功能

Contributor guide

Open the contributing guide

Research direction

Start in BaseForm/BaseForm and inspect how formRef is initialized and populated during onInit, then trace components/SchemaForm/index and genItems to confirm when the field properties are generated. Reproduce the request-backed BetaSchemaForm case and verify that the first select interaction returns a populated form with its methods, without regressing later interactions.

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
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.