Skip to content

fix(table): recompute the paginated slice when current changes - #4483

Closed
lnuxe wants to merge 1 commit into
Tencent:developfrom
lnuxe:fix/table-select-all-controlled-pagination
Closed

lnuxe wants to merge 1 commit into
Tencent:developfrom
lnuxe:fix/table-select-all-controlled-pagination

Conversation

@lnuxe

@lnuxe lnuxe commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

🤔 这个 PR 的性质是?

  • 日常 bug 修复

🔗 相关 Issue

无(本 PR 直接修复受控分页下全选按旧页计算)

📝 描述

同步 currentPaginateData 的 effect 依赖数组漏了分页字段:

useEffect(() => {
  if (reserveSelectedRowOnPaginate) return;
  const { pageSize, current, defaultPageSize, defaultCurrent } = pagination ?? {};
  ...
  setCurrentPaginateData(newData);
}, [data, reserveSelectedRowOnPaginate]);

本地数据 + 父组件控制 pagination.current 时,data 引用不变,切片永远停在第一页。表格渲染第 2 页是对的,但全选/半选仍基于第 1 页的行——在第 2 页点表头复选框,回传的是第 1 页的 key。

改动

把 effect 实际读取的分页字段补进依赖:

-    [data, reserveSelectedRowOnPaginate],
+    [
+      data,
+      reserveSelectedRowOnPaginate,
+      pagination?.current,
+      pagination?.pageSize,
+      pagination?.defaultCurrent,
+      pagination?.defaultPageSize,
+    ],

🔍 自测

修复前(还原 useRowSelect.tsx 后跑新测试):

× Table > scenarios > select all with controlled pagination > selects the rows of the current page after current changes
  → expected [ 1, 2 ] to deeply equal [ 3, 4 ]
Tests  1 failed (1)

修复后:

✓ Table > scenarios > select all with controlled pagination > selects the rows of the current page after current changes
✓ Table > scenarios > select all with controlled pagination > still selects the first page rows when current stays at 1
Tests  2 passed (2)

第二个用例确认第 1 页的行为没有被改变。

回归:

npx vitest run packages/components/table
Test Files  6 passed (6)
     Tests  53 passed (53)

✅ 贡献者检查

  • 我的代码遵循这个项目的代码风格
  • 我已经自己检查了自己的代码
  • 我已经添加了必要的测试
  • 我已经在本地通过了所有测试

@lnuxe lnuxe closed this Nov 13, 2026
@lnuxe
lnuxe force-pushed the fix/table-select-all-controlled-pagination branch from fcf6478 to 2bc63e2 Compare November 13, 2026 03:07
@lnuxe lnuxe reopened this Nov 13, 2026
currentPaginateData was recomputed by a useMemo whose dependency list only
held [data, reserveSelectedRowOnPaginate]. Changing the page left the slice
pointing at the previous page, so select-all on page 2 selected the rows of
page 1.

Add the pagination fields the slice actually reads.

Verified:
- new test fails on the previous implementation
  (expected [ 1, 2 ] to deeply equal [ 3, 4 ])
- new test passes with the fix
- table: 49 tests pass
@lnuxe
lnuxe force-pushed the fix/table-select-all-controlled-pagination branch from 904be9b to a40f908 Compare November 17, 2026 02:06
@lnuxe

lnuxe commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

先关掉,收敛一下数量。

本仓库我这边积压的 open PR 偏多,维护者审不过来,反而稀释了每个 PR 的信号。这个修复本身是有效的,分支保留在 fork:fix/table-select-all-controlled-pagination,需要时可以随时重开。

保留的是影响面更大、或已经有维护者反馈的那几个。

@lnuxe lnuxe closed this Nov 19, 2026
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.

1 participant