From e7787f4c3f65b2e0ad23f5a1f6ade0bc4e578016 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 18 Aug 2026 16:07:34 +0300 Subject: [PATCH] Set the room list mode synchronously on a warm launch The room summary provider subscription only delivers its current state through an async main queue hop, which can end up queued behind the first render. On a warm launch, where the cached rooms have already been published before the home screen exists, that leaves the skeletons up for the whole duration. Read the current state at the end of init instead, alongside the rooms which were already being read there. --- .../Sources/Screens/HomeScreen/HomeScreenViewModel.swift | 8 ++++++++ UnitTests/Sources/HomeScreenViewModelTests.swift | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 8503ba4ed..60c6a6d6f 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -176,6 +176,14 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol setupRoomListSubscriptions() updateRooms() + + // The subscription above only delivers the current state through an async main queue + // hop, which can end up queued behind the first render and leave the skeletons up on a + // warm launch, where the provider has already published the cached rooms. + if let roomSummaryProvider { + updateRoomListMode(with: roomSummaryProvider.statePublisher.value, + hasRooms: !roomSummaryProvider.roomListPublisher.value.isEmpty) + } } // MARK: - Public diff --git a/UnitTests/Sources/HomeScreenViewModelTests.swift b/UnitTests/Sources/HomeScreenViewModelTests.swift index 2d038efda..93fd80712 100644 --- a/UnitTests/Sources/HomeScreenViewModelTests.swift +++ b/UnitTests/Sources/HomeScreenViewModelTests.swift @@ -384,6 +384,14 @@ final class HomeScreenViewModelTests { enum InviteType { case rooms, spaces } + @Test + func roomListModeIsSetSynchronouslyOnAWarmLaunch() { + setupViewModel() + + // No awaiting, the mode must not need the subscription's async delivery. + #expect(context.viewState.roomListMode == .rooms) + } + @Test func roomListModeWaitsForTheRoomsToPublish() async throws { let (roomListSubject, stateSubject) = setupViewModelWithManualProvider()