From efc237164d10a667e5199726e563eb5c2b7cc8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Mazur?= Date: Tue, 14 Oct 2025 19:15:15 +0200 Subject: [PATCH] Make sorting of group instances stable (#1419) --- src/shared/utils/compare.js | 17 +++++++++++++++++ src/stores/instance.js | 13 +++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/shared/utils/compare.js b/src/shared/utils/compare.js index 76a4b48a..fd5c8e63 100644 --- a/src/shared/utils/compare.js +++ b/src/shared/utils/compare.js @@ -89,6 +89,22 @@ function compareByDisplayName(a, b) { return a.displayName.localeCompare(b.displayName); } +/** + * ascending + * @param {object} a + * @param {object} b + * @returns + */ +function compareById(a, b) { + if ( + typeof a.id !== 'string' || + typeof b.id !== 'string' + ) { + return 0; + } + return a.id.localeCompare(b.id); +} + /** * * @param {object} a @@ -252,6 +268,7 @@ export { compareByCreatedAtAscending, compareByUpdatedAt, compareByDisplayName, + compareById, compareByMemberCount, compareByPrivate, compareByStatus, diff --git a/src/stores/instance.js b/src/stores/instance.js index 476e5822..9214f254 100644 --- a/src/stores/instance.js +++ b/src/stores/instance.js @@ -9,6 +9,7 @@ import { instanceContentSettings } from '../shared/constants'; import { checkVRChatCache, compareByDisplayName, + compareById, compareByLocationAt, displayLocation, getAvailablePlatforms, @@ -727,17 +728,21 @@ export const useInstanceStore = defineStore('Instance', () => { return -1; } // sort by number of users when no friends in instance - if (a.users.length === 0 && b.users.length === 0) { + if (a.users.length === 0 && b.users.length === 0 && a.ref?.userCount !== b.ref?.userCount) { if (a.ref?.userCount < b.ref?.userCount) { return 1; } return -1; } // sort by number of friends in instance - if (a.users.length < b.users.length) { - return 1; + if (a.users.length !== b.users.length) { + if (a.users.length < b.users.length) { + return 1; + } + return -1; } - return -1; + // sort by id + return compareById(a, b) }); D.rooms = rooms; }