fix(table): route NaN through the missing-value branch in defaultCompare#3586
Open
arham766 wants to merge 1 commit into
Open
fix(table): route NaN through the missing-value branch in defaultCompare#3586arham766 wants to merge 1 commit into
arham766 wants to merge 1 commit into
Conversation
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
|
@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. |
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
Fixes #3585.
typeof NaN === 'number', so a NaN cell takesdefaultCompare's numeric fast path and the comparator returns NaN — whichArray.prototype.sortcoerces 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