Skip to content

fix(DataTable): clamp pagination when the total count shrinks - #8798

Open
nemo-crypto wants to merge 5 commits into
primer:mainfrom
nemo-crypto:nemo/table-pagination-shrinking-count
Open

nemo-crypto wants to merge 5 commits into
primer:mainfrom
nemo-crypto:nemo/table-pagination-shrinking-count

Conversation

@nemo-crypto

Copy link
Copy Markdown
Contributor

Problem

Filtering or deleting rows can leave Table.Pagination on a page greater than the new page count. Clamp the current index and persist the adjusted state so the selected page and visible bounds stay valid after the data changes.

Verification

Added a Chromium regression for shrinking from four pages to two and then to an empty table. The pagination suite passed (34 tests).

@nemo-crypto
nemo-crypto requested a review from a team as a code owner November 19, 2026 06:54
@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fb5d3d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

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.

🟡 Changes recommended

Pagination clamping fails to notify consumers after row counts shrink, potentially leaving empty pages, and can override a simultaneous reset to index zero.

3 open issues
What changed in this PR

Addresses out-of-range pagination in Primer React tables when filtering or deletion reduces the row count.

Changes:

  • Clamps the selected page to the available range and persists the adjusted index.
  • Adds a regression covering four pages shrinking to two, then an empty table.
  • Adds an @primer/react patch changeset.
File Description
packages/​react/​src/​DataTable/​Pagination.tsx Derives and stores a bounded page index.
packages/​react/​src/​DataTable/​__tests__/​Pagination.test.tsx Adds coverage for shrinking row counts.
.changeset/​table-pagination-shrinking-count.md Records the pagination fix for release.

Review effort: Max

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

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.

🟡 Changes recommended

Pagination can still crash on NaN page counts, report clamped indices twice, and display invalid ranges for empty tables.

4 open issues
3 resolved since last review

Review effort: Max

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

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.

🟡 Changes recommended

Pagination rejects valid empty-table defaults and incorrectly suppresses change notifications after clamps or batched row-count reductions, leaving pager selection and parent state inconsistent.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Accept default page index 0 when the table is empty

packages/​react/​src/​DataTable/​Pagination.tsx:350

Starting at index 3, emptying the table and echoing the clamp as defaultPageIndex={0} leaves defaultIndex at 3 because zero is rejected when there are no pages. Requesting index 3 again before or when the rows return then goes undetected, leaving the pager on the first page. Accept index 0 as a valid empty-table default and add a regression for this sequence.

Medium severity Notify parent when a page-count shrink triggers a clamp

packages/​react/​src/​DataTable/​Pagination.tsx:376

When selecting page 2 with a stable onChange that also shrinks totalCount from 50 to 25, the pager clamps back to index 0 but only reports index 1 to the parent. The final index and existing effect dependencies are unchanged from the previous commit, so the clamp notification is skipped and the parent's row state remains out of bounds. Include pageCount in the effect dependencies and add a regression for this batched selection and shrink.

4 resolved since last review

Review effort: Max

tay1orjones and others added 2 commits November 24, 2026 16:06

Copilot AI left a comment

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.

🔵 Needs a closer look

Public Table.Pagination callbacks now run post-commit and fire on automatic clamps, using heuristic echo suppression that needs maintainer review and validation against server-paginated consumers.

No open issues 🎉

1 resolved since last review

Review effort: Max

This branch was successfully deployed

1 active deployment
github-pages — fb5d3d3e Deployed Nov 24, 2026 by tay1orjones via deploy-preview #30861
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.

4 participants