-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
refactor: rc-component/form #747
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
概述遍历这些变更主要涉及从 变更
诗歌
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (3)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #747 +/- ##
=======================================
Coverage 99.44% 99.44%
=======================================
Files 18 18
Lines 1258 1259 +1
Branches 311 317 +6
=======================================
+ Hits 1251 1252 +1
Misses 7 7 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/Field.tsx (1)
564-564
: 默认属性的处理方式改进将默认属性从
defaultProps
移动到getControlled
方法中是一个好的改进:
- 更好的类型推断
- 更清晰的代码组织
- 更容易进行单元测试
建议添加注释说明这些默认值的用途。
const { name, - trigger = 'onChange', // Default trigger event + trigger = 'onChange', // 默认的触发事件,用于处理表单控件值的变更 validateTrigger, getValueFromEvent, normalize, - valuePropName = 'value', // Default value property + valuePropName = 'value', // 默认的值属性名,用于指定表单控件的值 getValueProps, fieldContext, } = this.props;Also applies to: 568-568
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
package.json
(2 hunks)src/Field.tsx
(2 hunks)src/FieldContext.ts
(1 hunks)src/List.tsx
(1 hunks)src/useForm.ts
(1 hunks)src/useWatch.ts
(1 hunks)src/utils/validateUtil.ts
(2 hunks)src/utils/valueUtil.ts
(1 hunks)tests/index.test.tsx
(1 hunks)tests/initialValue.test.tsx
(1 hunks)tests/list.test.tsx
(1 hunks)
✅ Files skipped from review due to trivial changes (9)
- tests/initialValue.test.tsx
- src/List.tsx
- tests/list.test.tsx
- tests/index.test.tsx
- src/useForm.ts
- src/useWatch.ts
- src/utils/valueUtil.ts
- src/FieldContext.ts
- src/utils/validateUtil.ts
🔇 Additional comments (2)
package.json (1)
54-54
: 依赖包更新符合新的命名约定将
rc-util
替换为@rc-component/util
是一个好的改动,保持了包命名的一致性。src/Field.tsx (1)
1-3
: 导入路径更新符合新的包结构导入路径从
rc-util/lib
更新为@rc-component/util/lib
的修改是正确的,与包名变更保持一致。
New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/Form.tsx (1)
141-141
: 引用初始化改进使用
null
作为prevFieldsRef
的初始值是一个更安全的做法。不过建议考虑使用undefined
来保持与 TypeScript 的undefined | FieldData[]
类型推断的一致性。- const prevFieldsRef = React.useRef<FieldData[] | undefined>(null); + const prevFieldsRef = React.useRef<FieldData[] | undefined>(undefined);tests/useWatch.test.tsx (2)
291-294
: 不建议将参数名改为_values
将参数名从
values
改为_values
不恰当,因为该参数在函数中被实际使用。通常下划线前缀用于表示未使用的参数,这种改动可能会降低代码的可读性。建议还原为:
- const values2 = Form.useWatch( - _values => ({ newName: _values.name, newAge: _values.age }), - form, - ); + const values2 = Form.useWatch( + values => ({ newName: values.name, newAge: values.age }), + form, + );
400-400
: formRef 的初始化方式变更是多余的将
formRef
的初始化从隐式 undefined 改为显式 undefined 没有实际的功能差异。除非是为了满足特定的代码规范要求,否则这个改动是不必要的。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
package.json
(3 hunks)src/Field.tsx
(3 hunks)src/Form.tsx
(2 hunks)src/List.tsx
(2 hunks)src/useForm.ts
(2 hunks)tests/useWatch.test.tsx
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- src/List.tsx
- src/Field.tsx
- src/useForm.ts
🔇 Additional comments (5)
src/Form.tsx (1)
20-20
: 类型定义优化将
RenderProps
的返回类型简化为React.ReactNode
是一个很好的改进,因为React.ReactNode
已经包含了JSX.Element
类型,这样可以让类型定义更加简洁。tests/useWatch.test.tsx (1)
296-297
: 类型注解的添加很好为
useWatch
添加了明确的类型参数,这样可以提高类型安全性和代码的可维护性。package.json (3)
2-3
: 重大变更:包名和版本号的变化需要更新迁移指南!请运行以下脚本以检查是否有相关的迁移文档:
#!/bin/bash # 检查是否存在迁移指南文档 fd -e md -e mdx "migration|upgrade|changelog" # 检查是否有其他包依赖于旧包名 curl -s https://registry.npmjs.org/rc-field-form | jq '.dependents'
63-63
: 注意:React 类型定义升级可能需要更新最低支持版本将
@types/react
升级到^19.0.6
可能需要相应调整项目的 React 最低支持版本。请确认:
- 是否需要更新
peerDependencies
中的 React 版本要求- 是否需要在文档中说明新的版本要求
54-54
: 依赖包更新:验证 @rc-component/util 的兼容性从
rc-util
迁移到@rc-component/util
可能会带来兼容性问题。请运行以下脚本以验证新旧依赖包的 API 兼容性:
✅ Verification successful
依赖更新已验证安全
- 代码已完全迁移到
@rc-component/util
- 此更新是 RC 组件生态系统规范化的一部分,将
rc-*
包迁移至@rc-component/*
命名空间- 所有被使用的工具函数(warning、toArray、isEqual 等)在新包中都可用
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 检查两个包的导出是否一致 curl -s https://registry.npmjs.org/rc-util | jq '.versions."5.32.2".exports' curl -s https://registry.npmjs.org/@rc-component/util | jq '.versions."1.1.0".exports'Length of output: 177
Script:
#!/bin/bash # Find all imports from rc-util echo "=== Searching for rc-util imports ===" rg "from 'rc-util" -A 1 --type ts --type tsx --type js --type jsx echo -e "\n=== Searching for rc-util requires ===" rg "require\(['\"']rc-util" -A 1 --type ts --type tsx --type js --type jsxLength of output: 386
Script:
#!/bin/bash # Search for both old and new package imports echo "=== Searching for both package usages ===" rg "rc-util|@rc-component/util" -l # Check the git diff for context echo -e "\n=== Checking git diff ===" git diff origin/master -- package.jsonLength of output: 1301
Script:
#!/bin/bash # Check actual imports from the files echo "=== Checking imports in source files ===" for file in src/*.ts src/*.tsx src/utils/*.ts; do if [ -f "$file" ]; then echo "=== $file ===" rg "from ['\"]rc-util|from ['\"]@rc-component/util" "$file" -A 1 fi doneLength of output: 4940
Summary by CodeRabbit
重大更新
rc-field-form
更改为@rc-component/form
1.0.0
依赖变更
rc-util
替换为@rc-component/util
@types/react
版本至^19.0.6
代码重构
Field
组件的静态默认属性RenderProps
类型的返回值定义ListProps
接口中的children
属性类型这些变更主要涉及包的重命名和依赖重构,对用户功能影响较小。