Skip to content

fix(table): route NaN through the missing-value branch in defaultCompare#3586

Open
arham766 wants to merge 1 commit into
facebook:mainfrom
arham766:fix/table-sort-nan
Open

fix(table): route NaN through the missing-value branch in defaultCompare#3586
arham766 wants to merge 1 commit into
facebook:mainfrom
arham766:fix/table-sort-nan

Conversation

@arham766

@arham766 arham766 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3585.

typeof NaN === 'number', so a NaN cell takes defaultCompare's numeric fast path and the comparator returns NaN — which Array.prototype.sort coerces to +0 ("equal"). The comparator becomes inconsistent, and the sort silently mis-orders the other, valid rows: [5, NaN, 1, 3] sorted ascending stays [5, NaN, 1, 3] (verified by execution; the corruption is data-dependent, so it looks intermittent in real apps).

NaN now routes through the same missing-value branch as null/undefined: it groups at the end in ascending order (start in descending), and the valid numbers sort correctly.

Test plan

  • New tests: valid numbers stay ordered with a NaN cell present (ascending and descending), NaN groups with null
  • Full Table suite green: 15 files, 322 tests
  • typecheck + eslint clean

typeof NaN === 'number', so NaN cells hit the numeric fast path and the
comparator returned NaN, which Array.prototype.sort coerces to +0.
That makes the comparator inconsistent (NaN reads equal to values that
are ordered relative to each other), and sort skips insertion positions
for other, valid rows — [5, NaN, 1, 3] sorted ascending stayed
[5, NaN, 1, 3]. NaN now groups at the end with null/undefined and the
valid numbers sort correctly.

Fixes facebook#3585
@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

@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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Table sort: a single NaN cell silently corrupts the order of valid numbers (comparator returns NaN)

1 participant