Skip to content

fix: Render ColGroup even if table has no data to maintain layout consistency#1490

Open
wanpan11 wants to merge 2 commits into
react-component:masterfrom
wanpan11:fix/issue-57916
Open

fix: Render ColGroup even if table has no data to maintain layout consistency#1490
wanpan11 wants to merge 2 commits into
react-component:masterfrom
wanpan11:fix/issue-57916

Conversation

@wanpan11
Copy link
Copy Markdown

@wanpan11 wanpan11 commented May 28, 2026

Ensures FixedHolder renders the colgroup as long as column widths are available, fixing layout issues when the table is empty but has fixed columns. Fixes ant-design/ant-design/issues/57916

Summary by CodeRabbit

改进

  • Bug Fixes
    • 优化表格在无数据或部分列宽可用时的渲染判断:只要列宽信息存在,仍保持表头、数据行与汇总行的列布局一致,避免布局错位。

Review Change Stack

…sistency

Ensures FixedHolder renders the colgroup as long as column widths are available,
fixing layout issues when the table is empty but has fixed columns.
Fixes #57916.
Copilot AI review requested due to automatic review settings May 28, 2026 18:18
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c83cac73-62d8-494f-bc16-bd439724add1

📥 Commits

Reviewing files that changed from the base of the PR and between 2f44600 and d56e0c5.

📒 Files selected for processing (1)
  • src/FixedHolder/index.tsx
💤 Files with no reviewable changes (1)
  • src/FixedHolder/index.tsx

Walkthrough

将 FixedHolder 中用于决定是否渲染 ColGroup 的 isColGroupEmpty 条件从同时检查 noData 与列宽,改为仅基于列宽(mergedColumnWidth),并在 props 解构中移除 noData。

变更内容

列组渲染逻辑优化

Layer / File(s) Summary
isColGroupEmpty 条件判断调整
src/FixedHolder/index.tsx
从 props 解构中移除 noDataisColGroupEmpty 的 useMemo 返回条件由原先的 `noData

🎯 3 (Moderate) | ⏱️ ~20 minutes

相关 PR

  • react-component/table#1358: 在同一文件中调整 FixedHolderisColGroupEmpty/渲染决策并引入 colGroup 相关渲染变更。
  • react-component/table#1352: 修改 ColGroup 的空判断和在无有效 mergedColumnWidth 时返回 null 的处理,与本次对 isColGroupEmpty 判定的调整相关联。

建议审阅者

  • afc163

总体说明(更新)

本 PR 对 FixedHolder 组件中 isColGroupEmpty 的渲染判断逻辑进行了调整,使其不再在无数据时立即跳过 ColGroup 的渲染,而是始终根据列宽信息来决定,以确保表头、表体、表尾在布局上保持一致。

🐰 诗歌

我是小兔来报到,列宽真时别跑,
即便数据尚未到,ColGroup 也别少;
表头表体同队形,布局一致最美好,
祝这次改动顺利,渲染稳定不飘摇~ 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题清晰准确地概括了主要变更:在表格无数据时仍渲染ColGroup以保持布局一致性,与文件变更内容完全相符。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Removes the noData condition from the isColGroupEmpty check in FixedHolder so that the calculated ColGroup widths are used even when the table has no data, keeping Header/Body/Summary layouts aligned.

Changes:

  • Drop noData from the isColGroupEmpty memo and its dependency array.
  • Update the inline comment to describe the new behavior and reference ant-design issue #57916.
  • Update the FixedColumn snapshot to reflect the new colgroup widths emitted for the scrollXY-without-data case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/FixedHolder/index.tsx Removes noData from the ColGroup-empty check so calculated widths apply even with no data.
tests/snapshots/FixedColumn.spec.tsx.snap Updates the no-data snapshot to match the new col widths produced by the change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@wanpan11 is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
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 updates FixedHolder to render the ColGroup as long as column widths are available, even when there is no data, ensuring layout consistency. A review comment correctly points out that noData is now an unused variable in FixedHolder and suggests resolving this to prevent potential ESLint warnings.

Comment thread src/FixedHolder/index.tsx
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@wanpan11
Copy link
Copy Markdown
Author

@gemini-code-assist review

@wanpan11 wanpan11 requested a review from Copilot May 28, 2026 18:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
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 updates the FixedHolder component to render the ColGroup as long as column widths are available, even when there is no data, which maintains layout consistency. A review comment notes that removing noData from the destructuring assignment could cause it to leak into restProps and be forwarded to DOM elements, potentially triggering React console warnings. It is recommended to keep noData in the destructuring to prevent this issue.

Comment thread src/FixedHolder/index.tsx
Comment on lines 51 to 54
const {
className,
style,
noData,
columns,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

By removing noData from the destructuring assignment, it now implicitly falls into restProps. Since restProps is passed down to the children render prop (which eventually renders the header elements), noData will be forwarded down and may end up being spread onto DOM elements, triggering React console warnings (e.g., React does not recognize the noData prop on a DOM element).

To prevent this prop leakage, keep noData in the destructuring assignment so it is excluded from restProps, even if it is not directly used within FixedHolder.

Suggested change
const {
className,
style,
noData,
columns,
const {
className,
style,
noData,
columns,

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

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数据为空时,thead和summary会错位

2 participants