Description
defaultCompare in packages/core/src/Table/plugins/sortable/useTableSortableState.tsx has a number fast path:
if (typeof aVal === 'number' && typeof bVal === 'number') {
return aVal - bVal;
}
typeof NaN === 'number', so a NaN cell takes this path and the comparator returns NaN, which Array.prototype.sort treats as +0 ("equal"). That makes the comparator inconsistent (NaN compares equal to both 5 and 1 while 5 > 1), and the sort skips insertion positions for other, valid rows.
Reproduction (executed)
useTableSortableState({
data: [{id:'a', score:5}, {id:'b', score:NaN}, {id:'c', score:1}, {id:'d', score:3}],
defaultSort: [{sortKey: 'score', direction: 'ascending'}],
});
// sortedData scores: [5, NaN, 1, 3] ← 5 renders before 1 and 3
Expected: valid numbers in ascending order with NaN grouped at an end (like null/undefined already are). The corruption is data-dependent — some datasets survive, others don't — which makes it look intermittent.
Why it matters
NaN is a routine value (failed parseFloat, 0/0, missing metric). The user clicks "sort by score" and gets a column of wrongly ordered valid numbers under correct-looking sort chrome — silent, and worse than a crash.
Suggested fix
Route NaN through the same "sort to the end" branch as null/undefined before the fast path. Happy to send the PR.
Astryx Version
main (d9932ea)
Description
defaultCompareinpackages/core/src/Table/plugins/sortable/useTableSortableState.tsxhas a number fast path:typeof NaN === 'number', so a NaN cell takes this path and the comparator returns NaN, whichArray.prototype.sorttreats as+0("equal"). That makes the comparator inconsistent (NaN compares equal to both 5 and 1 while 5 > 1), and the sort skips insertion positions for other, valid rows.Reproduction (executed)
Expected: valid numbers in ascending order with NaN grouped at an end (like null/undefined already are). The corruption is data-dependent — some datasets survive, others don't — which makes it look intermittent.
Why it matters
NaN is a routine value (failed
parseFloat,0/0, missing metric). The user clicks "sort by score" and gets a column of wrongly ordered valid numbers under correct-looking sort chrome — silent, and worse than a crash.Suggested fix
Route NaN through the same "sort to the end" branch as null/undefined before the fast path. Happy to send the PR.
Astryx Version
main (d9932ea)