-
Notifications
You must be signed in to change notification settings - Fork 26
refactor: Upgrade utils and replace useMergedState #303
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: Upgrade utils and replace useMergedState #303
Conversation
Walkthrough将依赖 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User as 用户
participant Seg as Segmented组件
participant Hook as useControlledState(新)
participant Props as Props(value, defaultValue, options)
User->>Seg: 渲染(传入 Props)
Seg->>Hook: 初始化(value, defaultValue ?? options[0]?.value)
Hook-->>Seg: [state, setState]
note over Seg,Hook: 状态由受控值或默认值驱动
User->>Seg: 交互/选择项
Seg->>Hook: setState(新值)
Hook-->>Seg: 更新后的 state
Seg-->>User: 触发 onChange / 重渲染
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary of Changes
Hello @EmilyyyLiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
此 PR 主要进行了一项重构工作,通过升级核心工具库依赖并替换内部使用的状态管理 Hook,以优化代码结构和保持与最新库版本的兼容性。
Highlights
- 依赖升级: 将 @rc-component/util 依赖从 ^1.1.0 升级到 ^1.3.0。
- 状态管理 Hook 替换: 在 src/index.tsx 中,将 useMergedState 替换为 useControlledState。
- useControlledState 初始化逻辑调整: 调整了 useControlledState 的初始化值逻辑,现在优先使用 defaultValue,如果不存在则回退到 segmentedOptions[0]?.value。
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #303 +/- ##
=======================================
Coverage 99.38% 99.39%
=======================================
Files 2 2
Lines 163 164 +1
Branches 39 40 +1
=======================================
+ Hits 162 163 +1
Misses 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Code Review
本次 PR 升级了 @rc-component/util
依赖,并使用 useControlledState
替换了 useMergedState
。相关代码改动正确地保留了原有的逻辑,确保了组件在受控和非受控模式下的行为一致。这是一次不错的重构,提升了代码的可维护性。
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 (1)
src/index.tsx (1)
203-207
: 默认值仅在首次渲染读取首项;若 options 后置变更,初始未选中可能无法回填这改变了与
useMergedState
(带默认值配置对象)可能略有不同的时机。若希望在“非受控且当前值为 undefined”时,在 options 异步更新后仍自动选中第一项,可考虑添加同步逻辑(不会违背“不要在值不在 options 时强切换”的注释):@@ - const [rawValue, setRawValue] = useControlledState( - defaultValue ?? segmentedOptions[0]?.value, - value, - ); + const [rawValue, setRawValue] = useControlledState( + defaultValue ?? segmentedOptions[0]?.value, + value, + ); + // 当为非受控且当前值为 undefined,options 更新后回填首项 + React.useEffect(() => { + if (value === undefined && rawValue === undefined && segmentedOptions.length > 0) { + setRawValue(segmentedOptions[0].value); + } + }, [value, rawValue, segmentedOptions]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
package.json
(1 hunks)src/index.tsx
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: preview
🔇 Additional comments (2)
package.json (1)
52-52
: 依赖已升级至 @rc-component/util@^1.3.0,hooks 已全部切换为 useControlledState,无 useMergedState 残留且方法签名未变更,LGTM。src/index.tsx (1)
1-1
: 确认已移除所有 useMergedState 导入
扫描 src/** 目录未发现任何useMergedState
导入,已替换为useControlledState
并与项目风格保持一致。
关联issue:ant-design/ant-design#54854
替换 useMergedState 为 useControlledState
Summary by CodeRabbit