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: virtual scroll ref #1217

Merged
merged 2 commits into from
Jan 8, 2025
Merged

fix: virtual scroll ref #1217

merged 2 commits into from
Jan 8, 2025

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Jan 7, 2025

fix ant-design/ant-design#52276

Summary by CodeRabbit

  • 依赖更新

    • rc-util 依赖版本从 ^5.41.0 升级到 ^5.44.3
  • 新功能

    • 新增 getOffset 实用函数,用于跨浏览器兼容的元素偏移计算
  • 测试

    • 重命名现有的粘性滚动测试用例
    • 添加带自定义容器的粘性滚动测试用例

Copy link

vercel bot commented Jan 7, 2025

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

Name Status Preview Comments Updated (UTC)
table ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 8, 2025 2:44am

Copy link

coderabbitai bot commented Jan 7, 2025

变更概览

演练

此次更改主要涉及 rc-table 项目中的依赖版本更新和实用函数重构。具体包括在 package.json 中将 rc-util 依赖升级到 5.44.3 版本,在 src/utils/offsetUtil.ts 中新增 getOffset 函数,并相应地更新了 src/stickyScrollBar.tsx 中的导入语句。同时,在测试文件 tests/Sticky.spec.jsx 中添加了一个新的测试用例。

变更

文件 变更摘要
package.json 更新 rc-util 依赖版本从 ^5.41.0^5.44.3
src/stickyScrollBar.tsx 修改 getOffset 函数的导入路径
src/utils/offsetUtil.ts 新增 getOffset 实用函数
tests/Sticky.spec.jsx 重命名现有测试用例,添加新的 getContainer 测试用例

对链接问题的评估

目标 已解决 说明
解决 getBoundingClientRect 不是函数的错误 [#52276] 新的 getOffset 函数提供了更健壮的元素偏移计算方法

可能相关的 PR

建议的审阅者

  • afc163

诗歌

兔子轻跳代码海,
依赖升级显神威,
工具函数新生长,
测试用例添翅膀,
代码之路永无碍!
🐰✨🚀


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

codecov bot commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.76%. Comparing base (b12a943) to head (a3e5511).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1217   +/-   ##
=======================================
  Coverage   97.76%   97.76%           
=======================================
  Files          75       76    +1     
  Lines        7427     7443   +16     
  Branches     1126     1128    +2     
=======================================
+ Hits         7261     7277   +16     
  Misses        160      160           
  Partials        6        6           

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

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 (5)
src/utils/offsetUtil.ts (3)

3-3: 注释需要更新

注释 "Copy from rc-util/Dom/css.js" 应该包含更多上下文信息,比如为什么要复制这段代码而不是直接使用原始库。


9-9: 建议移除过时的浏览器兼容性注释

IE8 的兼容性注释已经过时,建议移除或更新这个注释以反映当前的浏览器支持情况。


4-20: 建议增强类型安全性和错误处理

函数实现基本正确,但建议做以下改进:

  1. 添加对 getDOM 返回值的空值检查
  2. boxdocElem 添加类型断言
 export function getOffset(node: HTMLElement | Window) {
   const element = getDOM(node);
+  if (!element) {
+    throw new Error('无法获取 DOM 元素');
+  }
   const box = element.getBoundingClientRect();
   const docElem = document.documentElement;
+  if (!docElem) {
+    throw new Error('无法获取 document.documentElement');
+  }

   return {
     left:
       box.left +
       (window.pageXOffset || docElem.scrollLeft) -
       (docElem.clientLeft || document.body.clientLeft || 0),
     top:
       box.top +
       (window.pageYOffset || docElem.scrollTop) -
       (docElem.clientTop || document.body.clientTop || 0),
   };
 }
tests/Sticky.spec.jsx (2)

59-59: 测试用例命名需要更有描述性

将测试用例从 'Sticky scroll' 重命名为 'Sticky scroll1' 不够描述性。建议使用更有意义的名称来描述测试场景。


Line range hint 59-201: 建议重构测试代码以提高可维护性

测试代码中存在重复的设置逻辑,建议提取共用的测试数据和设置到辅助函数中:

  1. 提取模拟的滚动值和事件
  2. 创建通用的表格数据生成器
+const createMockScrollData = () => ({
+  scrollLeft: 100,
+  scrollTop: 100,
+  scrollWidth: 200,
+  clientWidth: 100,
+  offsetHeight: 100,
+});
+
+const createTestTableData = (count) => 
+  Array.from({ length: count }, (_, i) => ({
+    light: 'bamboo',
+    bamboo: 'light',
+    key: i + 1,
+  }));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b12a943 and 48d74a6.

📒 Files selected for processing (4)
  • package.json (1 hunks)
  • src/stickyScrollBar.tsx (1 hunks)
  • src/utils/offsetUtil.ts (1 hunks)
  • tests/Sticky.spec.jsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/stickyScrollBar.tsx
🔇 Additional comments (1)
package.json (1)

60-60: 依赖更新看起来合适

rc-util 的版本更新(^5.41.0 -> ^5.44.3)与当前的改动相符,支持新的 DOM 操作功能。

tests/Sticky.spec.jsx Outdated Show resolved Hide resolved
@@ -0,0 +1,20 @@
import { getDOM } from 'rc-util/lib/Dom/findDOMNode';

// Copy from `rc-util/Dom/css.js`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥要 copy 过来?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 v6 里,rc-util 所有的 .js 后缀代码都会删掉。这个 offset 可以抽成其他方法在 rc-virtual-list 里复用,所以临时复制出来。重构的时候换个新的。

@zombieJ zombieJ merged commit b3d5c37 into master Jan 8, 2025
12 checks passed
@zombieJ zombieJ deleted the fix-virtual branch January 8, 2025 09:22
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.

Antd Virtual Table node.getBoundingClientRect is not a function
2 participants