diff --git a/.changeset/easy-laws-talk.md b/.changeset/easy-laws-talk.md new file mode 100644 index 0000000000000..51ff0a2702f2b --- /dev/null +++ b/.changeset/easy-laws-talk.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes non-deterministic comparator in team's channel desertion table diff --git a/apps/meteor/client/views/teams/ChannelDesertionTable/ChannelDesertionTable.tsx b/apps/meteor/client/views/teams/ChannelDesertionTable/ChannelDesertionTable.tsx index 61e6ca129e201..ec0bea58e17c6 100644 --- a/apps/meteor/client/views/teams/ChannelDesertionTable/ChannelDesertionTable.tsx +++ b/apps/meteor/client/views/teams/ChannelDesertionTable/ChannelDesertionTable.tsx @@ -39,7 +39,20 @@ const ChannelDesertionTable = ({ const direction = sortDirection === 'asc' ? 1 : -1; - return rooms.sort((a, b) => (a[sortBy] && b[sortBy] ? (a[sortBy]?.localeCompare(b[sortBy] ?? '') ?? 1) * direction : direction)); + return rooms.toSorted((a, b) => { + const aValue = a[sortBy] ?? ''; + const bValue = b[sortBy] ?? ''; + if (!aValue && !bValue) { + return 0; + } + if (!aValue) { + return 1; + } + if (!bValue) { + return -1; + } + return aValue.localeCompare(bValue) * direction; + }); }, [rooms, sortBy, sortDirection]); return (