Skip to content
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

Merged
merged 8 commits into from
Jan 17, 2025
Merged

refactor: rc-component/form #747

merged 8 commits into from
Jan 17, 2025

Conversation

li-jia-nan
Copy link
Member

@li-jia-nan li-jia-nan commented Jan 13, 2025

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 属性类型

这些变更主要涉及包的重命名和依赖重构,对用户功能影响较小。

@li-jia-nan li-jia-nan requested a review from zombieJ January 13, 2025 00:51
Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
field-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 9:15am

Copy link

coderabbitai bot commented Jan 13, 2025

概述

遍历

这些变更主要涉及从 rc-util@rc-component/util 的包重构。包括更新 package.json 中的包名和依赖项,以及在多个源文件中修改导入路径。版本号从 2.7.0 降到 1.0.0,并且移除了静态 defaultProps,转而在方法中直接设置默认值。

变更

文件 变更摘要
package.json 包名从 rc-field-form 更改为 @rc-component/form,版本降至 1.0.0-0,依赖项从 rc-util 更换为 @rc-component/util,同时更新了 @types/react 的版本
src/Field.tsx 移除静态 defaultProps,直接在 getControlled 方法中设置 triggervaluePropName 的默认值,更新导入路径
src/FieldContext.ts 更新 warning 的导入路径
src/List.tsx 更新 children 属性的类型签名,更新导入路径
src/useForm.ts 更新 mergewarning 的导入路径,初始化 formRefnull
src/useWatch.ts 更新 warning 的导入路径
src/utils/validateUtil.ts 更新 warningmerge 的导入路径
src/utils/valueUtil.ts 更新 getValuesetValue 的导入路径
tests/index.test.tsx 更新 resetWarned 的导入路径
tests/initialValue.test.tsx 更新 resetWarned 的导入路径
tests/list.test.tsx 更新 resetWarned 的导入路径
src/Form.tsx 更新 RenderProps 的类型签名,初始化 prevFieldsRefnull
tests/useWatch.test.tsx 修改 useWatch 的参数名,增加新的测试用例

诗歌

🐰 兔子的重构之歌
包名变换如春风,
依赖跳跃换新装。
版本重置归零点,
代码整装待启航!
重构的魔法,悄然绽放。 🌈


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ea86f8 and 667dca8.

📒 Files selected for processing (1)
  • package.json (2 hunks)
🔇 Additional comments (3)
package.json (3)

2-3: 包名和版本号的重大变更需要特别关注!

这是一个破坏性变更,包含以下重要修改:

  1. 包名从 rc-field-form 改为 @rc-component/form
  2. 版本号从 2.7.0 重置为 1.0.0-0

请确保:

  • 更新所有依赖此包的项目的依赖配置
  • 更新相关文档
  • 通知所有使用方进行相应更新

62-62: 验证 React 类型定义版本的兼容性

@types/react 的版本 ^19.0.6 可能存在潜在问题:

  • React 19 尚未正式发布
  • 这可能导致类型定义与实际使用的 React 版本不匹配

建议:

  • 确认是否确实需要 React 19 的类型定义
  • 考虑暂时保持在 React 18 的类型定义,直到 React 19 正式发布

53-53: 依赖更新和现代化改进

依赖更新显示了积极的现代化改进:

  • 采用了新的 @rc-component/util 替代 rc-util
  • 移除了 @babel/runtime 依赖

建议:

  • 确保 @rc-component/util 提供了所有必需的功能
  • 验证移除 @babel/runtime 不会影响运行时兼容性
✅ Verification successful

依赖更新验证完成,迁移成功

  • @rc-component/util 已完全替代 rc-util,所有必需功能(warning、set、get 等)均已正确导入
  • 未发现任何遗留的 rc-util@babel/runtime 引用
  • 代码库中的依赖引用保持一致性,迁移质量良好
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证 @rc-component/util 的使用情况
echo "检查 @rc-component/util 的导入..."
rg "from ['|\"]@rc-component/util" -l

# 验证是否仍有 rc-util 的使用
echo "检查是否还存在 rc-util 的使用..."
rg "from ['|\"]rc-util" -l

Length of output: 390


Script:

#!/bin/bash
# 检查从 @rc-component/util 导入的具体工具函数
echo "检查 @rc-component/util 的具体导入..."
rg "from ['|\"]@rc-component/util.*" -g "!{dist,es,lib}/*"

# 检查是否还存在 @babel/runtime 的使用
echo "检查是否还存在 @babel/runtime 的使用..."
rg "from ['|\"]@babel/runtime" -l

Length of output: 1393


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.44%. Comparing base (811792a) to head (667dca8).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 811792a and 9e5ed94.

📒 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 的修改是正确的,与包名变更保持一致。

package.json Outdated Show resolved Hide resolved
Copy link

socket-security bot commented Jan 13, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@rc-component/[email protected] 🔁 npm/@rc-component/[email protected] None 0 8.71 kB afc163
npm/@rc-component/[email protected] environment +1 202 kB zombiej

View full report↗︎

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e5ed94 and 2ea86f8.

📒 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 最低支持版本。请确认:

  1. 是否需要更新 peerDependencies 中的 React 版本要求
  2. 是否需要在文档中说明新的版本要求

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 jsx

Length 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.json

Length 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
done

Length of output: 4940

@zombieJ zombieJ merged commit f7f4eb2 into master Jan 17, 2025
12 checks passed
@zombieJ zombieJ deleted the v6-update branch January 17, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants