From c613175c6e11fe7a6577c4127faed4c5a0d94675 Mon Sep 17 00:00:00 2001 From: Garfie Date: Tue, 14 Apr 2026 18:15:01 -0500 Subject: [PATCH] fix(navigation): fully reset ConversationListStateHolder on logout reset() now clears pagination cursor, hasMore, isLoadingMore and isRefreshing state so the next user session does not inherit stuck spinners or stale cursors from the previous session. Also cancel and restart the search debounce collector so an in-flight debounced emission from the previous session cannot land after reset() and clobber the cleared grouped conversations list. --- .../navigation/ConversationListStateHolder.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/com/garfiec/librechat/shared/navigation/ConversationListStateHolder.kt b/shared/src/commonMain/kotlin/com/garfiec/librechat/shared/navigation/ConversationListStateHolder.kt index db08088..4c4323a 100644 --- a/shared/src/commonMain/kotlin/com/garfiec/librechat/shared/navigation/ConversationListStateHolder.kt +++ b/shared/src/commonMain/kotlin/com/garfiec/librechat/shared/navigation/ConversationListStateHolder.kt @@ -8,6 +8,7 @@ import com.garfiec.librechat.core.data.repository.ConversationRepository import com.garfiec.librechat.core.model.Conversation import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.Job import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -49,6 +50,8 @@ class ConversationListStateHolder( private val _isRefreshing = MutableStateFlow(false) val isRefreshing: StateFlow = _isRefreshing.asStateFlow() + private var searchObserverJob: Job? = null + init { observeConversations() observeSearchQuery() @@ -130,7 +133,8 @@ class ConversationListStateHolder( @OptIn(FlowPreview::class) private fun observeSearchQuery() { - scope.launch { + searchObserverJob?.cancel() + searchObserverJob = scope.launch { _searchQuery .filter { it.isNotBlank() } .debounce(SEARCH_DEBOUNCE_MS) @@ -144,10 +148,17 @@ class ConversationListStateHolder( } fun reset() { + searchObserverJob?.cancel() + searchObserverJob = null _recentConversations.value = emptyList() _groupedConversations.value = emptyList() _activeConversationId.value = null _searchQuery.value = "" + nextCursor = null + _hasMore.value = true + _isLoadingMore.value = false + _isRefreshing.value = false + observeSearchQuery() } private fun groupConversationsByDate(