Repository navigation
Conversation
…tedRowOnPaginate is false
lnuxe
requested review from
HaixingOoO,
NWYLZW,
RylanBot,
ZWkang,
carolin913,
honkinglin and
uyarn
as code owners
November 10, 2026 07:13
5 of 16 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 这个 PR 的性质是?
🔗 相关 Issue
reserveSelectedRowOnPaginate={false}时全选越过当前页)💡 需求背景和解决方案
reserveSelectedRowOnPaginate={false}的语义是「全部选中操作停留在当前页,不跨分页」(见table.md第 126 行的 API 说明),但表头全选实际选中了全部数据,表头全选框的 checked/indeterminate 也是按全部数据计算的。Root cause | 根因
packages/components/table/hooks/useRowSelect.tsx中:普通(非树形)表格下
allTreeRows恒等于完整data,而数组在||中恒为真值,导致后面的currentPaginateData分支是死代码:currentRows= 全部 6 条 / 10 条数据,而不是当前页的 2 条 / 5 条。于是:handleSelectAll()用enabledRows(=currentRows过滤 disabled)取 key → 全选写入全部数据;renderCheckAll()的allEnabledSelected/isChecked/isIndeterminate也都基于全部数据 → 表头状态与当前页不符。另外两处会放大问题:
currentPaginateData的 effect 只按[data, reserveSelectedRowOnPaginate]触发,且无条件data.slice(...);远程分页(data已是当前页数据)会再切一次导致当前页变成空数组,因此不能在修currentRows时直接启用它。handleSelectAll()里「保留禁用行 key」的过滤条件是!enabledRowsSet.has(id),它同时把其他分页的 key 当作禁用行保留了下来,导致false模式下全选仍然带着其它页的 key。Fix | 修复
只改
useRowSelect.tsx,保持 API、默认值(true)与树形表格语义不变:usePagination的shouldPaginate保持一致(pagination存在、未设置disableDataPage、且data.length > pageSize);currentRows改为:树形数据 / 跨页保留选中 / 未做本地分页时用全部数据,否则用当前页数据;currentPaginateData的同步 effect 改用同一个判断,受控分页取pagination.current,未做本地分页时直接使用data(不再二次切片,避免破坏远程分页);handleSelectAll()中,reserveSelectedRowOnPaginate=false时只保留当前页的禁用行 key,其他分页的 key 不再参与全选。🧪 Reproducible case | 复现用例
新增
packages/components/table/__tests__/row-select-paginate.test.tsx(6 行数据、pageSize: 2、reserveSelectedRowOnPaginate={false}),覆盖:checked;reserveSelectedRowOnPaginate={true}、无分页、远程分页(data已是当前页)三种对照不回归。☑️ Verification | 验证
真实浏览器(Chrome,1000×780@2x):10 条数据、
pageSize: 5、reserveSelectedRowOnPaginate={false},第 1 页只有 5 行,点击表头全选框,读取onSelectChange写入 DOM 的selectedRowKeys。selectedRowKeys (10): 1 … 10当前页只有 5 行,却选中了 10 条
selectedRowKeys (5): 1, 2, 3, 4, 5只选中当前页的 5 行
浏览器侧原始输出:
单测(
row-select-paginate.test.tsx,同一份用例在修复前后各跑一次):执行的命令:
npx vitest run packages/components/table/ # 55 passed npx vitest run packages/components/table/__tests__/row-select-paginate.test.tsx npx eslint packages/components/table/hooks/useRowSelect.tsx packages/components/table/__tests__/row-select-paginate.test.tsx --max-warnings 0📝 更新日志
tdesign-react
reserveSelectedRowOnPaginate={false}时表头全选包含其他分页数据、全选框状态按全部数据计算的问题 @lnuxe☑️ 请求合并前的自查清单