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

fix: use rc-util getNodeRef to resolve React 19 warning #502

Merged
merged 1 commit into from
Dec 9, 2024
Merged

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Dec 9, 2024

ref ant-design/ant-design#49267

Summary by CodeRabbit

  • 新特性
    • 更新了依赖项 rc-util 的版本。
    • TriggerWrapper 组件中改进了子组件引用的处理方式。

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

此次更改涉及两个主要文件。首先,package.json 文件中 rc-util 依赖的版本从 ^5.38.0 更新为 ^5.44.0。其次,在 src/TriggerWrapper.tsx 文件中,引入了 getNodeRef 方法,并修改了 TriggerWrapper 组件中处理子组件引用的逻辑,使用 getNodeRef(children) 替代了之前的 (children as any).ref

Changes

文件 更改摘要
package.json 更新 rc-util 依赖版本从 ^5.38.0^5.44.0
src/TriggerWrapper.tsx 引入 getNodeRef,修改 mergedRef 的引用获取方式

Possibly related PRs

  • fix: try to fix createPortal close case #492: 该PR涉及对 TriggerWrapper 组件及其引用处理的更新,可能与PR #492中涉及的 createPortal 功能相关,因为两者都涉及 Trigger 组件的行为和事件处理。

Poem

在兔子洞里跳跃欢快,
引用更新真是妙不可言,
rc-util 新版本来临,
组件引用更灵活,
小小变化大不同,
兔子乐在其中,
代码世界真精彩! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3b4218f and 33ad329.

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

1-6: 导入 getNodeRef 函数以支持 React 19

从 rc-util 中导入 getNodeRef 函数是一个很好的改进,这样可以更安全地处理组件引用。


29-29: 使用 getNodeRef 替换直接引用访问

(children as any).ref 替换为 getNodeRef(children) 是一个很好的改进:

  • 避免了直接使用 any 类型
  • 符合 React 19 的最佳实践
  • 提供了更安全的引用访问方式
✅ Verification successful

代码库中已经完全移除了不安全的 ref 访问方式

通过验证,我们发现:

  • 代码库中没有发现任何使用 as any.ref 或类似不安全 ref 访问的模式
  • getNodeRef 函数的使用仅在 TriggerWrapper.tsx 中出现
  • 代码库中的 ref 类型定义都使用了类型安全的方式(如 TriggerRef
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证是否还有其他地方使用不安全的 ref 访问方式
rg "as any\.ref" 

Length of output: 18


Script:

#!/bin/bash
# 搜索所有可能的不安全 ref 访问模式
rg -i "\.ref\s+as\s+any" 

# 搜索 getNodeRef 的使用情况
ast-grep --pattern 'getNodeRef($_)'

# 搜索可能的 ref 类型转换
rg "as\s+.*Ref"

# 查找 getNodeRef 函数的定义
ast-grep --pattern 'function getNodeRef'

Length of output: 218


Script:

#!/bin/bash
# 搜索 getNodeRef 的导入来源
rg "import.*getNodeRef"

# 搜索其他可能的 ref 相关工具函数
ast-grep --pattern 'export function $_(ref)'

# 查找可能存在的 ref 相关类型定义
rg "type.*Ref"

Length of output: 428

package.json (1)

72-72: 验证 rc-util 版本更新的兼容性

将 rc-util 升级到 ^5.44.0 版本以支持 getNodeRef 功能。建议:

  • 确认这是支持 getNodeRef 的最低要求版本
  • 验证此版本与其他依赖项的兼容性
  • 在升级前进行充分的测试
✅ Verification successful

rc-util 版本更新验证完成

经过验证,此版本更新是合理的:

  • 代码中使用了 rc-util/lib/ref 中的 getNodeRef 功能
  • 从 v5.44.0 的更新日志可以看到包含了 Ref 相关的更新支持
  • 项目中多处使用了 rc-util 的其他功能,版本更新不会造成破坏性变更
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查 rc-util 的版本历史和变更日志
gh api repos/react-component/util/releases | jq -r '.[].tag_name' | head -n 5

Length of output: 119


Script:

#!/bin/bash
# 检查代码库中使用 getNodeRef 的情况
rg "getNodeRef" -A 2

# 检查 rc-util 的 changelog 内容
gh api repos/react-component/util/releases | jq -r '.[] | select(.tag_name == "v5.44.0" or .tag_name == "v5.38.0") | {tag: .tag_name, body: .body}'

Length of output: 1307


Script:

#!/bin/bash
# 检查 rc-util 5.38.0 到 5.44.0 之间的所有版本变更记录
gh api repos/react-component/util/releases | jq -r '.[] | select(.tag_name | startswith("v5.") and (.[2:] | tonumber) >= 38 and (.[2:] | tonumber) <= 44) | {tag: .tag_name, body: .body}' | grep -A 5 "Ref"

# 检查代码中是否有其他依赖 rc-util 的相关引用
rg "from 'rc-util" -B 1 -A 1

Length of output: 4504


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 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 Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.75%. Comparing base (3b4218f) to head (33ad329).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #502   +/-   ##
=======================================
  Coverage   97.75%   97.75%           
=======================================
  Files          13       13           
  Lines         800      800           
  Branches      235      239    +4     
=======================================
  Hits          782      782           
  Misses         18       18           

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

@zombieJ zombieJ merged commit 626289a into master Dec 9, 2024
10 checks passed
@zombieJ zombieJ deleted the 19-cap branch December 9, 2024 06:30
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.

1 participant