-
Notifications
You must be signed in to change notification settings - Fork 360
fix(Form): add fullPath to FormList and FormItem
#3957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
8d008d5 to
0f8dd66
Compare
commit: |
There was a problem hiding this 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 critical issues with nested FormLists (3+ levels deep) by introducing fullPath tracking for FormItem and FormList components. The changes ensure proper path resolution in complex nested scenarios and prevent data mutation issues through strategic use of cloneDeep.
- Adds
fullPathcomputation to track complete paths in nested FormList scenarios - Implements defensive cloning to prevent accidental data mutation during add/remove operations
- Fixes multiple form methods (setFieldsValue, reset, validate, clearValidate) to work with deeply nested fields
- Optimizes key generation to avoid unnecessary re-renders when data hasn't changed
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
packages/components/form/utils/index.ts |
Adds utility functions normalizeNamePath and concatNamePath for path handling; refactors findFormItemDeep and calcFieldValue to support fullPath |
packages/components/form/type.ts |
Updates onValuesChange type signature from Record<string, unknown> to Record<string, any> for flexibility |
packages/components/form/hooks/useInstance.tsx |
Enhances form instance methods to support deep field lookup using findFormItemDeep; adds cloneDeep for data integrity; implements reset callback with onValuesChange |
packages/components/form/hooks/useFormItemInitialData.ts |
Adds optional chaining for safer array length check |
packages/components/form/__tests__/form-list.test.tsx |
Adds comprehensive test coverage for 3-level nested FormLists with operations like add, remove, validate |
packages/components/form/FormList.tsx |
Core changes: computes fullPath for nested lists; refactors add/remove/move operations with cloneDeep; optimizes key generation to reduce re-renders |
packages/components/form/FormItem.tsx |
Integrates fullPath calculation; updates all map operations and value updates to use fullPath |
packages/components/form/FormContext.tsx |
Adds fullPath field to FormListContext for parent path tracking |
packages/components/form/Form.tsx |
Adds cloneDeep to onFormItemValueChange callback to prevent external mutation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aade667 to
2579707
Compare
2579707 to
b9bac37
Compare
b9bac37 to
628f85b
Compare
b70cc1f to
dfebbfa
Compare
dfebbfa to
b5d16be
Compare
f7a36d2 to
288e1c3
Compare

🤔 这个 PR 的性质是?
🔗 相关 Issue
(非动态表单 ➕ 数字
name场景)💡 需求背景和解决方案
测试代码存档
fullPath的计算,确保复杂的路径能匹配正确📝 更新日志
fix(Form): 修复嵌套三层及以上的 FormList 相关方法失效的问题
fix(Form): 优化
key的生成,更新值与当前表单值相同时不刷新元素fix(Form): 修复
reset时没有触发onValueChange的问题fix(Form): 修复初始化调用
setFieldsValue时没有触发onValuesChange的问题fix(Form): 修复非动态表单场景下,
name为数字或含有数字时setFieldValues失败的问题本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单