Skip to content

feat: support force rendering expanded rows - #1503

Merged
zombieJ merged 5 commits into
react-component:masterfrom
nikzanda:feat/expandable-force-render
Jul 31, 2026
Merged

feat: support force rendering expanded rows#1503
zombieJ merged 5 commits into
react-component:masterfrom
nikzanda:feat/expandable-force-render

Conversation

@nikzanda

@nikzanda nikzanda commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add expandable.forceRender
  • Render collapsed expanded-row content ahead of the first expansion
  • Keep expanded content mounted across expand/collapse transitions
  • Support regular and virtual tables; in virtual mode, only currently mounted rows are force-rendered
  • Keep force-rendered rows hidden until expanded

Related issue

Closes ant-design/ant-design#54798
Supersedes #1386

Summary by CodeRabbit

Summary by CodeRabbit

  • 新功能
    • 新增 expandable.forceRender 配置项(默认值 false)。
    • 启用后,可展开行会在真正展开前按需预渲染并保持挂载;未展开时展开区域隐藏(display: none),展开/收起切换仅切换可见性不卸载。
    • 虚拟表格模式下仅对当前已挂载的虚拟行执行强制渲染。
  • 文档
    • 更新中英文 API 文档,补充 forceRender 的虚拟模式行为说明。
  • 测试
    • 增加对预渲染不卸载、DOM复用与 rowSpan 场景的覆盖验证。

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 509e3f10-1e2f-45d1-8029-a86533575215

📥 Commits

Reviewing files that changed from the base of the PR and between adf0701 and 95500e8.

📒 Files selected for processing (11)
  • .github/workflows/react-doctor.yml
  • README.md
  • README.zh-CN.md
  • src/Body/BodyRow.tsx
  • src/Table.tsx
  • src/VirtualTable/BodyLine.tsx
  • src/context/TableContext.tsx
  • src/hooks/useRowInfo.tsx
  • src/interface.ts
  • tests/ExpandRow.spec.jsx
  • tests/Virtual.spec.tsx
🚧 Files skipped from review as they are similar to previous changes (11)
  • src/context/TableContext.tsx
  • src/hooks/useRowInfo.tsx
  • src/VirtualTable/BodyLine.tsx
  • README.zh-CN.md
  • README.md
  • src/Body/BodyRow.tsx
  • tests/ExpandRow.spec.jsx
  • .github/workflows/react-doctor.yml
  • src/interface.ts
  • src/Table.tsx
  • tests/Virtual.spec.tsx

Walkthrough

新增 expandable.forceRender 配置,并将其传递至行信息。普通表格和虚拟表格会提前渲染展开行,未展开时隐藏内容。测试覆盖挂载复用和 rowSpan 场景。react-doctor 工作流也已更新。

Changes

展开行强制渲染

Layer / File(s) Summary
配置契约与上下文传递
src/interface.ts, src/context/TableContext.tsx, src/hooks/useRowInfo.tsx, src/Table.tsx
ExpandableConfig 新增可选属性 forceRender: booleanTableContextProps 新增必填属性 forceRender: booleanuseRowInfo 返回类型和字段选择添加 forceRenderTableexpandableConfig.forceRenderundefined 时设置默认值 false,并在 useMemo 依赖数组中添加该字段。
展开行渲染行为
src/Body/BodyRow.tsx, src/VirtualTable/BodyLine.tsx
BodyRow 解构 forceRender,扩展行渲染条件新增该字段。BodyLine 解构 forceRender,展开行创建条件改为排除 extra 行后在 forceRenderexpanded 任一为真时创建。虚拟表格未展开时使用 display: none 隐藏展开行容器。
行为验证与 API 文档
tests/ExpandRow.spec.jsx, tests/Virtual.spec.tsx, README.md, README.zh-CN.md
新增两个测试用例验证普通表格预渲染、隐藏和挂载复用。新增三个测试用例验证虚拟表格的预渲染、隐藏、挂载复用及 rowSpan 场景。中英文文档补充 forceRender 说明,阐述虚拟模式下仅强制渲染已挂载行的行为。

react-doctor 工作流更新

Layer / File(s) Summary
工作流触发与操作配置
.github/workflows/react-doctor.yml
工作流新增 push 事件触发器。权限配置新增 issues: writestatuses: write。checkout 操作添加 fetch-depth: 0。react-doctor 操作更新版本并移除 github-token 配置。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Table
  participant TableContext
  participant RowInfo
  participant BodyRow
  participant BodyLine
  participant ExpandedRow
  Table->>TableContext: 写入 expandable.forceRender
  TableContext->>RowInfo: 选择 forceRender
  RowInfo->>BodyRow: 提供展开配置
  RowInfo->>BodyLine: 提供展开配置
  BodyRow->>ExpandedRow: forceRender 时预先渲染
  BodyLine->>ExpandedRow: forceRender 时创建并隐藏
  BodyLine->>ExpandedRow: 展开后移除隐藏样式
Loading

Possibly related PRs

  • react-component/table#1482:修改 src/VirtualTable/BodyLine.tsx 和虚拟表格展开行渲染逻辑,涉及不同的行为侧面。

Suggested reviewers: zombiej, afc163

Poem

小兔轻敲展开键,
未开先把内容见。
隐藏仍在不卸载,
点击显示状态连。
测试文档同步改,
胡萝卜旁庆更新。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地描述了PR的主要功能:添加对展开行强制渲染的支持。
Linked Issues check ✅ Passed PR完整实现了#54798中的需求:添加expandable.forceRender选项,支持常规表和虚拟表,渲染内容在首次展开前已挂载。
Out of Scope Changes check ✅ Passed 变更涉及.github/workflows/react-doctor.yml的非功能性修改,与核心需求无关,但不影响功能实现的有效性。
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/ExpandRow.spec.jsx (1)

62-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

补充重新折叠后的隐藏断言。

当前仅验证首次展开;若 forceRender 路径在折叠后未恢复 display: none,测试不会捕获回归。

  • tests/ExpandRow.spec.jsx#L62-L65:再次点击第一行展开图标,并断言第一条展开行恢复隐藏。
  • tests/Virtual.spec.tsx#L201-L205:再次点击展开图标,并断言虚拟展开行恢复隐藏。

依据 PR 目标,强制渲染的内容应在未展开时保持隐藏。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/ExpandRow.spec.jsx` around lines 62 - 65, Extend the expansion
assertions in tests/ExpandRow.spec.jsx lines 62-65 by clicking the first row’s
expand icon again and asserting its expanded row is hidden; apply the same
additional collapse interaction and hidden-state assertion in
tests/Virtual.spec.tsx lines 201-205. Ensure both force-render paths verify
content remains hidden after collapsing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/ExpandRow.spec.jsx`:
- Around line 62-65: Extend the expansion assertions in tests/ExpandRow.spec.jsx
lines 62-65 by clicking the first row’s expand icon again and asserting its
expanded row is hidden; apply the same additional collapse interaction and
hidden-state assertion in tests/Virtual.spec.tsx lines 201-205. Ensure both
force-render paths verify content remains hidden after collapsing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b021e53e-c774-4b76-af09-561b172fd7ff

📥 Commits

Reviewing files that changed from the base of the PR and between adf0701 and 2a55be7.

📒 Files selected for processing (10)
  • README.md
  • README.zh-CN.md
  • src/Body/BodyRow.tsx
  • src/Table.tsx
  • src/VirtualTable/BodyLine.tsx
  • src/context/TableContext.tsx
  • src/hooks/useRowInfo.tsx
  • src/interface.ts
  • tests/ExpandRow.spec.jsx
  • tests/Virtual.spec.tsx

@nikzanda

Copy link
Copy Markdown
Contributor Author

Related work

This PR overlaps with #1386. Thanks to @rubbishmaker for the earlier implementation.

Compared with #1386, this PR:

I'm happy to rework or close this PR if maintainers prefer continuing from #1386.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.05%. Comparing base (adf0701) to head (95500e8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1503   +/-   ##
=======================================
  Coverage   99.05%   99.05%           
=======================================
  Files          45       45           
  Lines        1372     1374    +2     
  Branches      411      413    +2     
=======================================
+ Hits         1359     1361    +2     
  Misses         13       13           

☔ View full report in Codecov by Harness.
📢 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.

@yoyo837
yoyo837 requested a review from zombieJ July 30, 2026 02:30
@yoyo837

yoyo837 commented Jul 30, 2026

Copy link
Copy Markdown
Member

Thanks for covering both the regular and virtual rendering paths. I reviewed the current head (536bdc8); the main implementation looks good, but I think the following points are worth addressing before merge.

1. Virtual table + rowSpan may mount expanded content twice

BodyGrid.extraRender creates an additional BodyLine for records that need the virtual rowSpan overlay. BodyLine currently renders expanded content without excluding these extra lines:

if (rowSupportExpand && (forceRender || expanded)) {
  const expandContent = expandedRowRender(...);
}

With forceRender: true, the normal line and the extra row-span line can therefore both call expandedRowRender and mount two copies for the same record. This is particularly risky for the motivating use case, since duplicate Form.Item names may be registered.

Could we suppress expanded-row rendering for the overlay line (for example, guard it with !extra) and add a virtual + rowSpan + forceRender regression test that verifies each record mounts only one expanded subtree?

Relevant paths:

  • src/VirtualTable/BodyLine.tsx
  • src/VirtualTable/BodyGrid.tsx

2. Please clarify the virtual-list limitation

In virtual mode, forceRender only affects BodyLine instances currently mounted by the virtual list. Rows outside the viewport are still unmounted, so this does not guarantee that every off-screen row's form fields remain registered.

I would document this explicitly, e.g.:

In virtual mode, only rows currently mounted by the virtual list are force-rendered. Off-screen rows may still be unmounted.

That keeps the feature compatible with virtualization without implying that all data rows remain in the DOM.

3. Add a test for the actual keep-mounted contract

The current tests verify presence and display: none, but the core requirement is that the expanded subtree is not unmounted across collapse/expand transitions.

It would be useful to add a small stateful child (or mount/unmount counters), then verify that:

  1. it mounts before the first expansion;
  2. collapsing does not run cleanup;
  3. re-expanding preserves its state / DOM identity.

Ideally this should cover both regular and virtual paths.

4. Minor cleanup

  • TableContextProps.forceRender is required boolean, while expandableConfig.forceRender can be undefined. Either use expandableConfig.forceRender ?? false when building the context, or make the context field optional.
  • The unrelated formatting changes to DataIndex and ColumnsType in src/interface.ts could be reverted to keep the diff focused.
  • The PR description could use Closes ant-design/ant-design#54798 and Supersedes #1386; close #1386 refers to another PR and is unlikely to close it automatically.

The main lint/TypeScript/compile/test workflow and coverage are green, so apart from the virtual row-span edge case these are mostly contract/documentation hardening.

@nikzanda

Copy link
Copy Markdown
Contributor Author

@yoyo837 Thanks for the detailed review. I’ve addressed the requested changes in c3558d8:

  • prevented expandedRowRender from running for virtual rowSpan overlay lines by guarding with !extra;
  • added a virtual + rowSpan + forceRender regression test that verifies each record mounts only one expanded subtree;
  • added stateful keep-mounted tests for both regular and virtual tables, covering mount count, cleanup, DOM identity, and preserved state;
  • documented that virtual mode only force-renders rows currently mounted by the virtual list;
  • normalized the context value with expandableConfig.forceRender ?? false;
  • reverted the unrelated DataIndex and ColumnsType formatting changes;
  • updated the PR description with Closes ant-design/ant-design#54798 and Supersedes #1386.

Validation completed successfully:

  • yarn test — 223 tests passed
  • yarn tsc
  • yarn lint

Thanks again. Please let me know if you’d like any further adjustments.

@zombieJ
zombieJ merged commit 4a3373a into react-component:master Jul 31, 2026
9 of 10 checks passed
@nikzanda
nikzanda deleted the feat/expandable-force-render branch July 31, 2026 09:13
@zombieJ

zombieJ commented Jul 31, 2026

Copy link
Copy Markdown
Member

+ @rc-component/table@1.11.0

@nikzanda

Copy link
Copy Markdown
Contributor Author

@zombieJ The follow-up Ant Design integration PR is now open: ant-design/ant-design#58860.

It upgrades @rc-component/table to 1.11.0, documents expandable.forceRender in English and Chinese, and adds a Form regression test covering validation before the first expansion.

Thanks again for reviewing and releasing the rc-table implementation.

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 expandable forceRender prop

3 participants