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

chore: use @rc-component/resize-observer #302

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

li-jia-nan
Copy link
Member

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

Summary by CodeRabbit

  • 新功能

    • 将包名从 rc-virtual-list 更改为 @rc-component/virtual-list
    • 更新到 React 19 及相关依赖
  • 重构

    • 更新多个组件和测试文件中的导入路径
    • 调整引用和初始化方式,提高代码健壮性
  • 依赖变更

    • 更新 React 和相关类型定义到最新版本
    • 重置包版本为 1.0.0
  • 开发调整

    • 仅在开发环境设置组件 displayName
    • 更新 .gitignore 配置

Copy link

vercel bot commented Jan 28, 2025

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

Name Status Preview Comments Updated (UTC)
virtual-list ❌ Failed (Inspect) Jan 28, 2025 10:52am

Copy link

coderabbitai bot commented Jan 28, 2025

Warning

Rate limit exceeded

@li-jia-nan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 41 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 139d129 and 6411126.

📒 Files selected for processing (5)
  • .gitignore (1 hunks)
  • examples/no-virtual.tsx (5 hunks)
  • examples/switch.tsx (2 hunks)
  • src/Filler.tsx (2 hunks)
  • src/Item.tsx (1 hunks)

概述

演练

这个拉取请求主要涉及将包从 rc-virtual-list 重构为 @rc-component/virtual-list。更改包括更新导入路径、包名和版本,从 rc-utilrc-resize-observer 迁移到 @rc-component/util@rc-component/resize-observer。代码逻辑保持不变,主要是组织结构和依赖管理的调整。

变更

文件 变更摘要
.gitignore 添加 pnpm-lock.yaml,更新 mock 目录排除规则
package.json 包名变更为 @rc-component/virtual-list,版本重置为 1.0.0,更新依赖
src/* 更新导入路径,调整 refs 初始化,条件性设置 displayName
tests/* 更新测试文件中的导入路径

可能相关的 PR

诗歌

🐰 兔子的重构之歌

代码跳跃,路径变换
组件重生,版本重启
@rc-component 旗帜飘扬
依赖重组,兔子欢唱
重构之路,代码飞翔!


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

socket-security bot commented Jan 28, 2025

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

Package New capabilities Transitives Size Publisher
npm/@rc-component/[email protected] environment 0 33.4 kB zombiej
npm/@rc-component/[email protected] environment +1 202 kB zombiej
npm/@types/[email protected] 🔁 npm/@types/[email protected] None 0 20.6 kB types
npm/@types/[email protected] 🔁 npm/@types/[email protected] None +1 2.05 MB types

🚮 Removed packages: npm/[email protected]

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

151-153: 改进:使用 useRef 的泛型类型

建议为 useRef 添加明确的泛型类型,以提高类型安全性:

-const componentRef = useRef<HTMLDivElement>(null);
-const fillerInnerRef = useRef<HTMLDivElement>(null);
-const containerRef = useRef<HTMLDivElement>(null);
+const componentRef = useRef<HTMLDivElement | null>(null);
+const fillerInnerRef = useRef<HTMLDivElement | null>(null);
+const containerRef = useRef<HTMLDivElement | null>(null);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82566ea and 139d129.

📒 Files selected for processing (14)
  • .gitignore (1 hunks)
  • examples/animate.tsx (5 hunks)
  • package.json (4 hunks)
  • src/Filler.tsx (2 hunks)
  • src/List.tsx (6 hunks)
  • src/ScrollBar.tsx (3 hunks)
  • src/hooks/useFrameWheel.ts (1 hunks)
  • src/hooks/useHeights.tsx (1 hunks)
  • src/hooks/useMobileTouchMove.ts (1 hunks)
  • src/hooks/useScrollDrag.ts (1 hunks)
  • src/hooks/useScrollTo.tsx (2 hunks)
  • src/mock.tsx (1 hunks)
  • tests/scroll.test.js (1 hunks)
  • tests/scrollWidth.test.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • src/mock.tsx
  • src/hooks/useScrollDrag.ts
  • src/hooks/useMobileTouchMove.ts
  • src/hooks/useHeights.tsx
  • tests/scrollWidth.test.tsx
  • src/hooks/useFrameWheel.ts
  • tests/scroll.test.js
🔇 Additional comments (14)
src/Filler.tsx (2)

2-2: 导入路径更新符合最新规范

rc-resize-observer 更新到 @rc-component/resize-observer 的变更与代码库中的其他更改保持一致。


98-100: 优化了生产环境的代码体积

在非生产环境下才设置 displayName,这样可以在保持开发体验的同时优化生产环境的代码体积。

src/hooks/useScrollTo.tsx (2)

3-3: 统一更新了工具函数的导入路径

rc-util 包中的工具函数导入路径更新为 @rc-component/util,保持了代码库的一致性。

Also applies to: 6-6, 7-7


40-40: 明确初始化 ref 值为 null

使用 null 显式初始化 React ref 是一个好的实践,可以避免 undefined 带来的潜在问题。

examples/animate.tsx (3)

8-8: 更新了 useLayoutEffect 的导入路径

将 useLayoutEffect 的导入路径从 rc-util 更新为 @rc-component/util,与代码库的其他部分保持一致。


138-138: 明确初始化 listRef

使用 null 显式初始化 listRef,这是一个推荐的做法。


148-148: 箭头函数的格式保持一致

代码格式的统一性有助于提高可读性和可维护性。

Also applies to: 162-165, 169-173

src/ScrollBar.tsx (2)

2-2: 更新了 raf 工具函数的导入路径

将 raf 的导入路径从 rc-util 更新为 @rc-component/util,保持了代码库的一致性。


52-53: 统一使用 null 初始化所有 ref

对所有 React ref 使用 null 进行显式初始化,包括:

  • scrollbarRef
  • thumbRef
  • visibleTimeoutRef
  • enableScrollRangeRef
  • enableOffsetRangeRef

这种做法提高了代码的类型安全性和可预测性。

Also applies to: 57-57, 123-126

package.json (2)

2-3: 需要更新 CHANGELOG

包名更改为 @rc-component/virtual-list 且版本从 3.18.1 重置为 1.0.0 是一个重大变更。建议:

  1. 在 CHANGELOG 中详细说明迁移步骤
  2. 添加迁移指南文档

68-69: 验证 React 19 兼容性

将 React 依赖更新到 19.0.0 版本是一个重大变更:

  1. 需要验证组件在 React 19 下的兼容性
  2. peerDependencies 设置为 >=16.9.0 可能需要重新评估

Also applies to: 72-74

✅ Verification successful

React 19 兼容性检查结果良好

代码库检查结果显示:

  • 未发现使用已废弃的生命周期方法
  • 主要使用 Hooks API,符合 React 现代最佳实践
  • 现有的 peerDependencies (>=16.9.0) 配置适用于 React 19
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否有使用已废弃的 React API
rg -l "componentWillMount|componentWillReceiveProps|componentWillUpdate" --type typescript

Length of output: 127


Script:

#!/bin/bash
# 检查废弃的生命周期方法和 API
echo "=== 检查废弃的 React API ==="
rg -l "componentWillMount|componentWillReceiveProps|componentWillUpdate|React\.createClass" --type js --type jsx --type ts --type tsx

echo -e "\n=== 检查类组件使用情况 ==="
rg -l "class.*extends.*React\.Component|class.*extends.*Component" --type js --type jsx --type ts --type tsx

echo -e "\n=== 检查 package.json 中的 peerDependencies ==="
cat package.json | jq '.peerDependencies'

echo -e "\n=== 检查 React Hooks 使用情况 ==="
rg -l "use[A-Z].*\(" --type js --type jsx --type ts --type tsx

Length of output: 772


Script:

#!/bin/bash
# 首先找到所有的 React 相关文件
echo "=== 查找 React 文件 ==="
fd -e js -e jsx -e tsx -e ts

echo -e "\n=== 检查文件内容 ==="
# 使用找到的文件进行内容搜索
fd -e js -e jsx -e tsx -e ts -x rg -l "componentWillMount|componentWillReceiveProps|componentWillUpdate|React\.createClass" {} \;

echo -e "\n=== 检查类组件 ==="
fd -e js -e jsx -e tsx -e ts -x rg -l "class.*extends.*React\.Component|class.*extends.*Component" {} \;

echo -e "\n=== 检查 Hooks 使用 ==="
fd -e js -e jsx -e tsx -e ts -x rg -l "use[A-Z].*\(" {} \;

Length of output: 1910

.gitignore (1)

11-11: 确保测试 mock 路径正确配置

mock 路径从 rc-util 更改为 @rc-component/util,请确保:

  1. 所有测试用例都已更新以使用新路径
  2. CI 管道中的测试配置已相应更新
src/List.tsx (2)

670-672: 优化:条件性设置 displayName

良好的实践:在非生产环境下设置 displayName 以便调试。


2-5: 更新依赖导入路径

已将导入路径从 rc-utilrc-resize-observer 更新为 @rc-component 范围。确保所有相关组件都已更新。

✅ Verification successful

导入路径更新已完成验证

经过全面检查,确认所有组件都已更新为使用 @rc-component 范围的新导入路径。代码库中未发现任何遗留的 rc-utilrc-resize-observer 旧路径引用。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否还有旧的导入路径
rg -l "from 'rc-(util|resize-observer)" --type typescript

Length of output: 97


Script:

#!/bin/bash
# Search for old import paths in .ts and .tsx files
rg -l -g '*.ts' -g '*.tsx' "from ['\"]rc-(util|resize-observer)" 

# Show the actual import statements with context
rg -A 1 -g '*.ts' -g '*.tsx' "from ['\"]rc-(util|resize-observer)"

Length of output: 139


Script:

#!/bin/bash
# Search for any mention of old package names
rg -g '*.ts' -g '*.tsx' "rc-util|rc-resize-observer"

Length of output: 54

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