Skip to content

Conversation

EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Sep 12, 2025

关联issue:ant-design/ant-design#54854
替换 useMergedState 为 useControlledState

Summary by CodeRabbit

  • 新特性
    • 分页交互更稳定:当前页会根据总数与每页数量自动校正,避免越界,输入显示与实际页码更一致。
  • Chores
    • 升级依赖 @rc-component/util 至 ^1.3.0,改进兼容性与维护性。

Copy link

vercel bot commented Sep 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
pagination Error Error Sep 12, 2025 6:26am

Copy link

coderabbitai bot commented Sep 12, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Warning

Rate limit exceeded

@EmilyyyLiu has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2f3ffdc and 1df56cc.

📒 Files selected for processing (1)
  • src/Pagination.tsx (2 hunks)

Walkthrough

本次变更更新了 package.json@rc-component/util 依赖版本至 ^1.3.0,并在 src/Pagination.tsx 中将分页组件的内部受控状态管理由 useMergedState 切换为 useControlledState,引入基于 pageSizetotal 的派生 current 值(含范围钳制),并相应调整初始化与变量命名。

Changes

Cohort / File(s) Summary
依赖版本更新
package.json
将依赖 @rc-component/util^1.2.0 更新为 ^1.3.0
分页状态管理重构
src/Pagination.tsx
pageSizecurrent 的管理由 useMergedState 替换为 useControlledState;新增派生的 current(对 1..calculatePage(..., pageSize, total) 进行钳制);初始化 internalInputVal 依赖新派生 current;调整相关变量命名与导入。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant P as Pagination
  participant Props as Props(current,pageSize,total,...)
  participant Hook as useControlledState
  participant Util as calculatePage/clamp

  Note over P,Hook: 初始化
  P->>Hook: init pageSize (defaultPageSize || 10), controlled by pageSizeProp
  P->>Hook: init internalCurrent (defaultCurrent || 1), controlled by currentProp

  Note over P,Util: 派生 current
  P->>Util: calculatePage(undefined, pageSize, total)
  Util-->>P: totalPages
  P->>Util: clamp(internalCurrent, 1..totalPages)
  Util-->>P: derived current
  P->>P: init internalInputVal = derived current

  Note over Props,P: 受控/非受控更新
  Props-->>P: on pageSize/current prop change
  P->>Hook: update controlled state
  P->>Util: 重新计算 totalPages 与 derived current
  P-->>Props: onChange/onShowSizeChange 回调(若触发)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • chore: use rc-component/util #635: 同样涉及 Pagination.tsx 的 hook 迁移与对 @rc-component/util 的依赖调整,可能是同一系列变更的前置或并行步骤。

Suggested reviewers

  • zombieJ
  • MadCcc

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题“refactor: Upgrade utils and replace useMergedState” 简洁且准确概括了 PR 的两项核心改动:升级依赖(@rc-component/util)和将 useMergedState 替换为 useControlledState,因此与变更集高度相关并能让审阅者快速把握主要意图。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

小兔举耳听页声,
一跳一翻控与合。
钳住边界不越格,
星光点点页数阔。
胡萝卜做指针,翻到一三或一二。
嗖——新钩生,页页不差错。

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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!

此拉取请求通过升级一个实用工具依赖并替换内部状态 Hook,重构了 Pagination 组件中的状态管理。此更改旨在通过从 useMergedState 迁移到 useControlledState 来现代化组件的状态处理,使其与更新的实用工具库保持一致。

Highlights

  • 依赖升级: package.json@rc-component/util 依赖从 ^1.2.0 升级到 ^1.3.0
  • Hook 替换: src/Pagination.tsx 中,将 useMergedState 替换为 useControlledState
  • 状态管理逻辑调整: src/Pagination.tsxpageSizecurrent 的状态管理逻辑已更新,以适应 useControlledState 的新 API,包括将 postState 逻辑应用于 current 外部。
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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 升级到了 ^1.3.0,并使用新的 useControlledState hook 替换了已废弃的 useMergedState。整体实现是正确的,将 postState 的逻辑移出到 hook 之外也是合理的。我发现有两处代码可以稍微简化,以提高代码的可读性,请查看我的具体评论。

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 (1)
src/Pagination.tsx (1)

194-202: 确认:changePageSize 中对页大小变更的边界处理正确(可选优化)

calculatePage(size, ...) 已使用新的 pageSize 计算新总页数 newCurrent;当 current > newCurrent 且 newCurrent !== 0 时会将 current 调整为 newCurrent,避免越界。可选改进:onShowSizeChange 目前传入旧的 current,建议改为传 nextCurrent(位置:src/Pagination.tsx:193-202)。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f897f6 and 2f3ffdc.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/Pagination.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: Socket Security: Pull Request Alerts
🔇 Additional comments (7)
package.json (1)

45-45: 确认:@rc-component/util v1.3.0 已导出 useControlledState(实现为 useMergedState)
已检查仓库源码与类型定义:hook 实现在 src/hooks/useMergedState.ts,并在 1.3.0 发布包中作为导出提供;依赖升级到 ^1.3.0 可接受。

src/Pagination.tsx (6)

2-2: 导入更新正确

useMergedState 更新为 useControlledState 的导入符合 PR 目标。


78-81: 页面大小状态管理改进

使用 useControlledState 替代原来的 useMergedState 来管理页面大小状态是一个好的改进,提供了更清晰的受控/非受控状态处理。


83-86: 当前页码状态管理重构

将当前页码重命名为 internalCurrent 并使用 useControlledState 管理是合理的重构,为后续的派生计算做准备。


88-91: 派生当前页码的边界检查

引入派生的 current 值并使用 Math.maxMath.min 进行边界钳制是一个很好的改进。这确保了当前页码始终在有效范围内 [1, maxPage],避免了无效的页码状态。


93-93: 输入值初始化正确

internalInputVal 现在基于派生的 current 值进行初始化,这确保了输入框显示的值与实际的当前页码保持一致。


205-226: handleChange 边界与 internalInputVal 更新已验证 — 无需更改

已检查 src/Pagination.tsx 中的 handleChange 实现和 tests/simple.test.tsx、tests/sizer.test.tsx;函数会将输入页码 clamp 到 [1, maxPage],仅在 newPage 与 internalInputVal 不同时更新 internalInputVal,并调 setCurrent/onChange,现有测试覆盖空值、非数字、越界、回车与上下键场景,行为符合预期。

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link

codecov bot commented Sep 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.03%. Comparing base (5f897f6) to head (1df56cc).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #657   +/-   ##
=======================================
  Coverage   99.03%   99.03%           
=======================================
  Files           3        3           
  Lines         310      310           
  Branches      139      139           
=======================================
  Hits          307      307           
  Misses          3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ merged commit d990433 into react-component:master Sep 16, 2025
9 checks passed
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