From 5888dfd29dc426e21835cee5322d057b529cbdf2 Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Tue, 28 Oct 2025 20:18:07 +0530 Subject: [PATCH] Return RLS instance through function to avoid import side effect (#31091) * Attach function that returns instance So that just importing this file does not create a RLS instance. * Fix jest test --- src/@types/global.d.ts | 2 +- src/stores/room-list-v3/RoomListStoreV3.ts | 2 +- .../viewmodels/roomlist/RoomListHeaderViewModel-test.tsx | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 289bda3f49..9d43a13ca4 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -98,7 +98,7 @@ declare global { mxToastStore: ToastStore; mxDeviceListener: DeviceListener; mxRoomListStore: RoomListStore; - mxRoomListStoreV3: RoomListStoreV3Class; + getRoomListStoreV3: () => RoomListStoreV3Class; mxRoomListLayoutStore: RoomListLayoutStore; mxPlatformPeg: PlatformPeg; mxIntegrationManagers: typeof IntegrationManagers; diff --git a/src/stores/room-list-v3/RoomListStoreV3.ts b/src/stores/room-list-v3/RoomListStoreV3.ts index f5fb48df07..e0461c3a5f 100644 --- a/src/stores/room-list-v3/RoomListStoreV3.ts +++ b/src/stores/room-list-v3/RoomListStoreV3.ts @@ -373,4 +373,4 @@ export default class RoomListStoreV3 { } } -window.mxRoomListStoreV3 = RoomListStoreV3.instance; +window.getRoomListStoreV3 = () => RoomListStoreV3.instance; diff --git a/test/unit-tests/components/viewmodels/roomlist/RoomListHeaderViewModel-test.tsx b/test/unit-tests/components/viewmodels/roomlist/RoomListHeaderViewModel-test.tsx index eb92208fc9..ba93dc9072 100644 --- a/test/unit-tests/components/viewmodels/roomlist/RoomListHeaderViewModel-test.tsx +++ b/test/unit-tests/components/viewmodels/roomlist/RoomListHeaderViewModel-test.tsx @@ -48,6 +48,9 @@ describe("useRoomListHeaderViewModel", () => { beforeEach(() => { matrixClient = stubClient(); space = mkStubRoom("spaceId", "spaceName", matrixClient); + jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string): any => { + if (name === "RoomList.preferredSorting") return SortingAlgorithm.Recency; + }); }); afterEach(() => {