Skip to content

Conversation

Linkodt
Copy link
Contributor

@Linkodt Linkodt commented Sep 18, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

ant-design/ant-design#55039
close #55039

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

clone the column title without ref

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English change the measureCell to use the clone column title without ref
🇨🇳 Chinese 修改 measureCell 使用不带 ref 的 columnTitle

Summary by CodeRabbit

  • 新增修复
    • 修复当列标题为 React 元素时导致测量单元处理异常与控制台警告的问题。现在会自动规范化标题并移除无效引用,确保标题正确显示与测量,提升表格渲染的稳定性与兼容性。

Copy link

vercel bot commented Sep 18, 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 21, 2025 5:53pm

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 @Linkodt, 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 bug within the MeasureRow component where column titles containing ref properties could cause issues during the measurement process. The fix involves cloning the column title elements and explicitly nullifying their ref property when they are used for measurement, ensuring proper ref assignment to the actual column header and preventing unintended side effects.

Highlights

  • Bug Fix for MeasureRow: Addresses an issue in the MeasureRow component where column titles, especially those containing ref properties, were not handled correctly during the measurement process, potentially leading to errors or unexpected behavior.
  • Ref Handling in Column Titles: Implements a solution to explicitly clone column title elements and set their ref property to null before passing them to MeasureCell. This ensures that the ref points to the intended columnHeader and prevents conflicts during measurement.
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.

@Linkodt
Copy link
Contributor Author

Linkodt commented Sep 18, 2025

当前还存在的问题:
只是进行了浅层的 ref 去除
是否需要进行递归 去除 可能会存在的深度ref 引用?

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 a ref on a column title was being incorrectly used by the MeasureRow component, which is intended for measuring column widths. The fix correctly clones the title element while nullifying its ref, preventing potential ref conflicts and ensuring the original ref points to the correct column header element. The implementation is clean and effectively solves the described issue. To prevent regressions, it would be beneficial to add a test case that covers this specific scenario.

@afc163
Copy link
Member

afc163 commented Sep 19, 2025

https://github.com/react-component/table/actions/runs/17836173599/job/50718050719?pr=1362

Run npx tsc --noEmit
src/Body/MeasureRow.tsx(41,46): error TS2769: No overload matches this call.
  The last overload gave the following error.
    Object literal may only specify known properties, and 'ref' does not exist in type 'Partial<unknown> & Attributes'.
Error: Process completed with exit code 2.

Copy link

codecov bot commented Sep 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.11%. Comparing base (ee7bfc1) to head (e2ee887).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1362   +/-   ##
=======================================
  Coverage   96.10%   96.11%           
=======================================
  Files          57       57           
  Lines        3441     3445    +4     
  Branches      630      632    +2     
=======================================
+ Hits         3307     3311    +4     
  Misses        129      129           
  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.

Copy link

coderabbitai bot commented Sep 21, 2025

Walkthrough

在 MeasureRow 中引入对列标题的清洗:从 column.title 派生 titleForMeasure。若标题为 React 元素则克隆并移除 ref(设为 null);否则直接使用原值。随后以 titleForMeasure 替代原先的 column?.title 传入 MeasureCell。其余渲染流程保持不变。

Changes

Cohort / File(s) Change Summary
Measure 标题清洗与传递
src/Body/MeasureRow.tsx
新增 titleForMeasure:从 column.title 生成,若为 React 元素则 clone 且移除 ref;否则原样使用。以该值传给 MeasureCell,替换原来的 column?.title。无导出/公共 API 变更。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant MR as MeasureRow
  participant C as Column
  participant MC as MeasureCell

  MR->>C: 读取 column.title
  alt 标题为 React 元素
    MR->>MR: cloneElement(title, { ref: null })\n生成 titleForMeasure
  else 非元素
    MR->>MR: 直接使用原始 title 作为 titleForMeasure
  end
  MR->>MC: 渲染并传入 titleForMeasure
  MC-->>MR: 完成测量渲染
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

Poem

小兔敲键轻如风,
标题洗净不留痕。
若是元素摘其“ref”,
非也原味递测分。
行间度量更从容,
耳畔代码哼小吟 🐇✨

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 PR 标题明确地概括了主要改动:在 MeasureRow 中克隆 column 并移除 ref,以便 ref 指向真实的 columnHeader,表述具体且与提交的代码修改(MeasureRow.tsx 的 title 克隆与 ref 移除)直接对应,便于审阅者快速理解目的。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

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/Body/MeasureRow.tsx (1)

37-39: 小优化:避免在 map 中重复线性查找列(O(n²))。

列数较多时可见。可预构建 Map 提升可读性与性能,属非功能性建议。

可以这样处理(在组件内、columns 变更时重建索引):

const columnByKey = React.useMemo(
  () => new Map(columns.map(c => [c.key, c] as const)),
  [columns],
);

// 使用处
const column = columnByKey.get(columnKey);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee7bfc1 and e2ee887.

📒 Files selected for processing (1)
  • src/Body/MeasureRow.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). (1)
  • GitHub Check: test / react component workflow
🔇 Additional comments (3)
src/Body/MeasureRow.tsx (3)

39-42: 关于“是否需要递归移除嵌套 ref”——不建议,移除顶层 ref 足够。

  • 目标是防止列头外部传入的“顶层 ref”被度量行劫持;处理顶层即可达成目的。
  • 深度清洗会破坏子树内部组件自用的 ref,副作用大且成本高。
  • 若后续出现真实用例需要,可在受控开关下再考虑深度处理。

请确认相关 Issue 中的案例仅依赖顶层 ref(与目前修复相符)。若发现仍被子节点 ref 干扰,可补充复现用例再权衡。


48-48: 将清洗后的 title 传给 MeasureCell 的改动是正确的。

这能避免度量行篡改外部 ref 的归属,符合修复目标。


40-42: 修复 TS2769:避免向 cloneElement 传递 ref(CI 类型错误)

位置:src/Body/MeasureRow.tsx:40-42

React 18 的类型签名对 cloneElement 第二参较严格,直接传 { ref: null } 会在多数 @types/react 版本报 TS2769;改为用 createElement 重新构造元素可自然丢弃 ref 并避免类型问题。

-          const titleForMeasure = React.isValidElement<React.RefAttributes<any>>(rawTitle)
-            ? React.cloneElement(rawTitle, { ref: null })
-            : rawTitle;
+          const titleForMeasure = React.isValidElement(rawTitle)
+            ? React.createElement(
+                (rawTitle as React.ReactElement).type,
+                {
+                  ...(rawTitle as React.ReactElement).props,
+                  // 仅保留 key,不传 ref(自然被丢弃)
+                  key: (rawTitle as React.ReactElement).key,
+                },
+              )
+            : rawTitle;

验证:

  • 本地运行:npx tsc --noEmit,应无类型错误。
  • 手动检查 MeasureCell 中 title 渲染正常、样式/事件未丢失。

@afc163
Copy link
Member

afc163 commented Sep 22, 2025

是否需要进行递归 去除 可能会存在的深度ref 引用?

递归调用我担心有性能问题,先按你这个最简单的方式处理。

另外 Tour target 如果用 id 和 className 来拿节点,目前也会有问题,暂不处理。

@afc163 afc163 merged commit a887d56 into react-component:master Sep 22, 2025
9 checks passed
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.

3 participants