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()