Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Body/MeasureRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import isVisible from '@rc-component/util/lib/Dom/isVisible';
import { useContext } from '@rc-component/context';
import TableContext from '../context/TableContext';
import type { ColumnType } from '../interface';
import { prepareMeasureTitle } from '../utils/measureUtil';

export interface MeasureRowProps {
prefixCls: string;
Expand Down Expand Up @@ -38,8 +37,9 @@ const MeasureRow: React.FC<MeasureRowProps> = ({
{columnsKey.map(columnKey => {
const column = columns.find(col => col.key === columnKey);
const rawTitle = column?.title;
const titleForMeasure = prepareMeasureTitle(rawTitle);

const titleForMeasure = React.isValidElement<React.RefAttributes<any>>(rawTitle)
? React.cloneElement(rawTitle, { ref: null })
: rawTitle;
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This revert re-introduces an issue where unique identifiers in column titles (like id, data-testid, etc.) can be duplicated in the DOM. The MeasureRow is a hidden element used for measuring, and if it renders a column title that is a React component with such identifiers, it will create duplicate IDs. This is invalid HTML and can cause problems with accessibility and testing frameworks.

The previous implementation that is being removed (prepareMeasureTitle from the now-deleted measureUtil.ts) correctly stripped these problematic props. By reverting to only nullifying the ref, the original bug is being brought back.

If there was a specific problem with the previous fix that prompted this revert, it would be beneficial to document it. Otherwise, it would be best to avoid re-introducing this bug.

Comment on lines +40 to +42
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

请说明回滚原因并验证不会重新引入原 bug。

此 PR 回滚了修复重复唯一标识符的 #1376。建议:

  1. 在 PR 描述中说明回滚的原因(原修复是否引入了其他问题?)
  2. 验证回滚后不会重新引入原来的重复 ID 问题
  3. 确认当前的内联逻辑能够正确处理所有边缘情况

另外,类型注解 React.RefAttributes<any> 使用了 any,建议改为更具体的类型以提高类型安全性。

运行以下脚本搜索 PR #1376 的相关讨论和测试用例:


🏁 Script executed:

#!/bin/bash
# 查找 PR #1376 的相关信息和测试
gh pr view 1376 --json title,body,comments

# 搜索相关的测试文件
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts | xargs rg -l "MeasureRow|duplicate.*id" 

Length of output: 22036


澄清回滚原因并验证不再引入重复唯一标识符问题

建议:

  1. 在 PR 描述中说明此次回滚的具体原因(例如 measureUtilDashboardColumnTitle 等自定义组件内部的 id/data-* 属性无法递归清理)并规划后续解决方案。
  2. 确认目前的内联逻辑已涵盖 prepareMeasureTitle 原有的递归过滤能力,并为嵌套组件场景添加单元测试。
  3. React.RefAttributes<any> 替换为更精确的类型(如 JSX.Element 或自定义泛型),提升类型安全。

return (
<MeasureCell
key={columnKey}
Expand Down
96 changes: 0 additions & 96 deletions src/utils/measureUtil.ts

This file was deleted.