fix(core): guard Pagination pageSize against 0/NaN/negative values#3380
Merged
Merged
Conversation
pageSize is typed as number, so 0, NaN, and negatives pass the type check
but Math.ceil(totalItems / pageSize) yields Infinity/NaN page counts, and
Array.from({length: Infinity}) crashes the dots variant. Coerce to a
positive integer at the destructure; the Table pagination plugin gets the
same guard because it computes totalPages independently and passes it down
as an explicit prop, bypassing Pagination's own coercion.
Fixes facebook#3372
|
@arham766 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
cixzhang
approved these changes
Jul 2, 2026
cixzhang
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the report and fix!
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.
Summary
Implements the fix proposed in #3372.
pageSizeis typednumber, so0,NaN, and negatives pass the type check, butMath.ceil(totalItems / pageSize)turns them intoInfinity/NaNpage counts: thedotsvariant crashes withRangeError: Invalid array length(Array.from({length: Infinity})),compactrendersPage 1 of Infinity, and negative values make the component silently render nothing.Pagination.tsx: coercepageSizeto a positive integer at the destructure; non-finite values fall back to the default (10). Same pattern CodeBlock already uses forchunkSize.useTablePagination.tsx: same guard, because the plugin computestotalPagesindependently and passes it down as an explicit prop, which bypasses Pagination's own coercion.paginateData.ts: same coercion, so apageSizeof 0 no longer slices every page empty underneath a working paginator.Pagination.doc.mjs: one-line note on the coercion (en, zh, dense).Flooring fractional values also fixes a real mismatch:
Array.prototype.slicetruncates its arguments, sopageSize={2.5}previously sliced 2 items per page (25 real pages) while the chrome claimed 20, leaving the last items unreachable.Fixes #3372
Test plan
pageSize guardingblock inPagination.test.tsx:pageSize={0}no longer crashes the dots variant and paginates per item;NaNfalls back to the default (Page 1 of 5for 50 items);-10clamps to 1;2.5floors to 2 (Page 1 of 25).useTablePagination.test.tsx: table plugin withpageSize={0}renders a finite page count (Go to page 5, noGo to page Infinity) and page 1 shows its row instead of an empty slice.npx vitest run packages/core/src/Pagination/Pagination.test.tsx packages/core/src/Table/plugins/pagination/useTablePagination.test.tsx: 90/90 pass.node scripts/check-changesets.mjspasses.