Skip to content

Conversation

@li-jia-nan
Copy link
Member

@li-jia-nan li-jia-nan commented Oct 2, 2025

Summary by CodeRabbit

发布说明

  • Chores

    • 升级 React 及相关依赖至 19.2.0 版本,包括 react-is 和类型定义
    • 更新配置,直接使用 React 19.2.0 稳定版本
  • Tests

    • 更新测试以支持 React 19 行为
    • 移除过时的测试覆盖

@vercel
Copy link

vercel bot commented Oct 2, 2025

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

Project Deployment Preview Comments Updated (UTC)
util Ready Ready Preview Comment Nov 7, 2025 5:22am

@coderabbitai
Copy link

coderabbitai bot commented Oct 2, 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.

概览

此PR升级依赖至React 19.2.0,并规范化ref初始化为显式的null值,同时更新测试以反映React 19的ref行为变化。移除React 17特定的useId测试。

改动

聚合 / 文件(s) 变更摘要
示例ref规范化
docs/examples/getScrollBarSize.tsx, docs/examples/portal.tsx, src/Portal.tsx
将ref初始化从useRef()/useRef<Type>()改为显式的useRef<Type>(null),从undefined变更为null初始值,加强类型安全
React 19依赖升级
package.json
react-is、@types/react、@types/react-dom、@types/react-is升级至^19.2.0;react和react-dom从npm别名条目改为直接^19.2.0引脚;peerDependencies保持>=18.0.0
React 19 ref行为测试更新
tests/ref-19.test.tsx, tests/ref.test.tsx, tests/toArray-19.test.tsx
移除Jest mock块;更新supportRef/supportNodeRef期望值为truthy以反映React 19 ref合并行为;更新组件类型声明使用PropsWithChildren
移除React 17 useId测试
tests/hooks-17.test.tsx
删除整个测试文件,含SSR和hydration相关的useId测试覆盖

代码审查工作量估算

🎯 2 (简单) | ⏱️ ~10 分钟

  • 关键关注点
    • tests/ref.test.tsx中supportRef/supportNodeRef期望值的变更需确认与React 19 ref行为一致
    • package.json中直接版本固定方式确保所有React 19相关包版本对齐
    • 确认ref初始化为null不会在初始渲染或ref赋值逻辑中引入副作用

可能相关的PR

建议审查人员

  • zombieJ

诗歌

🐰✨ React 19已至,ref初值归null;
依赖齐升级,行为尽规范。
旧测移其身,新验显true光—
又是一次升级的魔法时刻!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了主要变更内容——将 React 从版本 18 升级到版本 19。这与所有修改的文件和代码变更(依赖版本更新、类型声明调整、测试用例更新)完全相关。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch react-19-up

📜 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 dcabdc2 and e3e2448.

📒 Files selected for processing (1)
  • package.json (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). (3)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: test / react component workflow
  • GitHub Check: test / react component workflow
🔇 Additional comments (2)
package.json (2)

71-74: peerDependencies版本范围的考虑。

当前peerDependencies保持为>=18.0.0,这保持了向后兼容性。但由于devDependencies已升级至React 19,建议验证:

  • 此库是否真正支持React 18和19两个主版本
  • 如果仅支持React 19,考虑更新peerDependencies为>=19.0.0^19.0.0以清晰传达最低要求

根据最佳实践,peerDependencies应准确反映库真正支持的版本范围。


42-42: 确认React 19升级中eslint-plugin-react-hooks的版本。

根据React 19官方文档,eslint-plugin-react-hooks需要升级到6.x版本以上(最低6.0.0)。请在package.json中验证以下事项:

  • eslint-plugin-react-hooks是否已升级到6.x版本;
  • 所有JSX文件是否使用新版JSX Transform(2020+);
  • 是否已运行官方迁移codemod:npx codemod@latest react/19/migration-recipe

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.

@gemini-code-assist
Copy link

Summary of Changes

Hello @li-jia-nan, 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!

This pull request focuses on a significant upgrade of the project's React dependency from version 18 to 19. The changes involve updating the package.json to reflect the new React versions and their associated type definitions. Additionally, several TypeScript adjustments were made across various files, primarily to explicitly initialize useRef hooks with null and to handle type compatibility with React.cloneElement, ensuring the codebase remains robust and type-safe with the latest React version.

Highlights

  • React Version Bump: Upgraded the core React and React DOM dependencies from version 18 to 19, along with their corresponding type definitions and react-is.
  • TypeScript Type Safety Enhancements: Modified several React.useRef calls across example and source files to explicitly initialize with null, improving type inference and aligning with stricter type checking practices for React 19.
  • Dependency Cleanup: Removed the react-19 and react-dom-19 aliases from package.json as React 19 is now the primary version.
  • Test File Adjustments: Applied a type assertion to React.cloneElement in tests/ref-19.test.tsx to ensure compatibility with React 19's type definitions.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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.

@socket-security
Copy link

socket-security bot commented Oct 2, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​types/​react-dom@​18.3.7 ⏵ 19.2.21001007593100
Updated@​types/​react@​18.3.26 ⏵ 19.2.2100 +11007996100
Addedreact-is@​19.2.010010010097100

View full report

Copy link

@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

This pull request upgrades React from version 18 to 19. The changes primarily involve updating dependencies in package.json and modifying useRef calls to align with React 19's new requirements, such as initializing DOM refs with null. Most of the changes are correct and necessary for the upgrade. However, I found a critical issue in src/hooks/useEvent.ts where a useRef call was updated incorrectly, leading to a read-only ref being mutated. My review includes a specific suggestion to fix this typing issue.

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 (2)
tests/ref-19.test.tsx (1)

42-42: 建议使用更具体的类型而非 any

当前使用 React.cloneElement<any> 削弱了类型安全性。考虑使用更具体的类型,例如:

-          {React.cloneElement<any>(children, { ref: mergedRef })}
+          {React.cloneElement<React.ReactElement>(children, { ref: mergedRef })}

不过,如果 React 19 的类型定义导致更具体的类型出现冲突,当前的 <any> 用法在测试场景中是可以接受的。

tests/toArray-19.test.tsx (1)

5-5: 考虑使用更具体的基础类型。

当前使用 React.PropsWithChildren<any> 中的 any 可以进一步具体化。由于该组件不需要额外的 props,可以使用空对象类型:

-class UL extends React.Component<React.PropsWithChildren<any>> {
+class UL extends React.Component<React.PropsWithChildren<{}>> {

或者使用 Record<string, never> 来明确表示没有额外属性:

-class UL extends React.Component<React.PropsWithChildren<any>> {
+class UL extends React.Component<React.PropsWithChildren<Record<string, never>>> {

不过在测试场景中,当前的实现也是可以接受的。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e080a1 and 18fb369.

📒 Files selected for processing (3)
  • package.json (2 hunks)
  • tests/ref-19.test.tsx (1 hunks)
  • tests/toArray-19.test.tsx (1 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). (2)
  • GitHub Check: test / react component workflow
  • GitHub Check: test / react component workflow
🔇 Additional comments (1)
package.json (1)

42-42: 依赖升级正确且一致。

所有 React 相关的依赖和类型定义都已正确升级到 v19.2.0,保持了版本一致性。peerDependencies 保持 >=18.0.0 也是合理的,确保了对 React 18 和 19 的兼容性。

Also applies to: 50-52, 67-68

@codecov
Copy link

codecov bot commented Oct 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.70%. Comparing base (7558cb8) to head (e3e2448).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #690      +/-   ##
==========================================
- Coverage   90.28%   88.70%   -1.59%     
==========================================
  Files          37       37              
  Lines         885      885              
  Branches      301      287      -14     
==========================================
- Hits          799      785      -14     
- Misses         84       97      +13     
- Partials        2        3       +1     

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

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