Skip to content

Conversation

@cactuser-Lu
Copy link
Contributor

@cactuser-Lu cactuser-Lu commented Sep 3, 2025

fix: ant-design/ant-design#54856

Summary by CodeRabbit

  • 修复
    • 虚拟表格列宽现遵循最小宽度设置,避免列过窄与布局错乱。
    • 处理缺失宽度时的计算异常,防止出现 NaN,提升稳定性与可读性。

@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

在虚拟表格的 BodyGrid 中重写列宽计算逻辑:引入 minWidth 与 width 的对比,使用最大值作为最终列宽,累计总宽并在下游(如 onColumnResize)消费该最终宽度,避免缺失 width 时出现 NaN。

Changes

Cohort / File(s) Summary
虚拟表格列宽计算修正
src/VirtualTable/BodyGrid.tsx
计算列宽时解构 widthminWidth,以 `max(width

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as 用户
  participant VT as BodyGrid
  participant C as 列定义
  participant R as 渲染层

  U->>VT: 触发布局/滚动/尺寸变更
  VT->>C: 读取列的 width 与 minWidth
  C-->>VT: 返回 { key, width, minWidth }
  rect rgba(200,230,255,0.2)
    note right of VT: 新逻辑
    VT->>VT: finalWidth = max(width||0, minWidth||0)
    VT->>VT: total += finalWidth
  end
  VT->>R: 传递 { key, finalWidth, total }
  R-->>U: 根据 finalWidth 渲染单元格与布局
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 分钟

Assessment against linked issues

Objective Addressed Explanation
修复虚拟化表格中列的 minWidth 未正确应用(#54856)

Assessment against linked issues: Out-of-scope changes

(无)

Poem

小兔抬耳量列宽,min 与 width 较高低;
一拍小爪定边界,NaN不再来捣奇;
虚拟长河行稳舟,单元随尺不偏移;
咔哒一声宽生效,表格舒展更如意。

✨ 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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
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 @cactuser-Lu, 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 resolves a long-standing bug affecting virtualized tables where the minWidth property for columns was not being respected. The change ensures that table columns correctly adhere to their minimum width constraints, improving the visual consistency and layout of virtualized tables.

Highlights

  • Bug Fix: Addresses an issue where the minWidth property was not correctly applied to table columns when virtualization was enabled, leading to incorrect column sizing and display.
  • Column Width Calculation Improvement: Modifies the column width calculation logic within src/VirtualTable/BodyGrid.tsx to properly account for both width and minWidth properties, ensuring that the larger of the two values is used as the final column width.
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.

@vercel
Copy link

vercel bot commented Sep 3, 2025

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

Project Deployment Preview Comments Updated (UTC)
table Ready Ready Preview Comment Sep 3, 2025 0:49am

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

This pull request addresses a bug where the minWidth property on columns was not being respected in virtualized tables. The change correctly calculates the final column width by taking the maximum of width and minWidth. My feedback includes a suggestion to improve code clarity by removing unnecessary type assertions.

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/VirtualTable/BodyGrid.tsx (1)

60-63: 用显式数值校验替代类型断言,避免 Math.max 接收到 NaN/字符串

当前写法依赖 (width as number)(minWidth as number) 的类型断言。若外部误传入了非 number(例如运行态为字符串或 NaN),Math.max 会产生 NaN 并重新引入累计宽度异常。建议在计算前做“有限且非负”的数值归一化,降低隐性回归风险。

可在当前位置内联收敛到有限非负数:

-    return flattenColumns.map(({ width, minWidth, key }) => {
-      const finalWidth = Math.max((width as number) || 0, (minWidth as number) || 0);
+    return flattenColumns.map(({ width, minWidth, key }) => {
+      const w = typeof width === 'number' && Number.isFinite(width) ? Math.max(width, 0) : 0;
+      const mw = typeof minWidth === 'number' && Number.isFinite(minWidth) ? Math.max(minWidth, 0) : 0;
+      const finalWidth = Math.max(w, mw);
       total += finalWidth;
       return [key, finalWidth, total];
     });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 688d72a and eba4efa.

📒 Files selected for processing (1)
  • src/VirtualTable/BodyGrid.tsx (1 hunks)
🔇 Additional comments (1)
src/VirtualTable/BodyGrid.tsx (1)

60-63: 方向正确:在虚拟化 Body 中同时约束列宽与最小宽度,能修复 minWidth 只在表头生效的问题

  • 使用 finalWidth = Math.max(width, minWidth) 并对缺省值回落到 0,有效避免了 total 累加为 NaN 的老问题;同时确保 Body 单元格与表头在窄屏下遵守相同的最小宽度约束,契合 PR 目标(#54856)。

@afc163 afc163 merged commit 5d0f833 into react-component:master Sep 4, 2025
7 checks passed
@codecov
Copy link

codecov bot commented Sep 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.07%. Comparing base (b94558d) to head (eba4efa).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1334      +/-   ##
==========================================
- Coverage   96.18%   96.07%   -0.11%     
==========================================
  Files          57       57              
  Lines        3408     3417       +9     
  Branches      620      622       +2     
==========================================
+ Hits         3278     3283       +5     
- Misses        125      129       +4     
  Partials        5        5              

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

Table columns minWidth props doesn't work properly when virtualized

2 participants