From ac66b252c5ada8526d2b7405ac135a73f526ab31 Mon Sep 17 00:00:00 2001 From: KoheiYamashita Date: Fri, 27 Feb 2026 18:39:47 +0900 Subject: [PATCH] fix: resolve race condition where Detail screen shows infinite spinner When navigating to a section before schema fetch completes, onSectionSelected() would silently return due to null schema. Introduce pendingSectionKey so loadData() auto-triggers loadSection() once the fetch finishes. Co-Authored-By: Claude Opus 4.6 --- .../java/io/clawdroid/backend/config/ConfigViewModel.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/android/backend/config/src/main/java/io/clawdroid/backend/config/ConfigViewModel.kt b/android/backend/config/src/main/java/io/clawdroid/backend/config/ConfigViewModel.kt index edae1f1fd..d5d399b73 100644 --- a/android/backend/config/src/main/java/io/clawdroid/backend/config/ConfigViewModel.kt +++ b/android/backend/config/src/main/java/io/clawdroid/backend/config/ConfigViewModel.kt @@ -28,6 +28,7 @@ class ConfigViewModel(private val apiClient: ConfigApiClient) : ViewModel() { private var schema: ConfigSchema? = null private var configValues: JsonObject? = null private var saveJob: Job? = null + private var pendingSectionKey: String? = null init { loadData() @@ -40,6 +41,10 @@ class ConfigViewModel(private val apiClient: ConfigApiClient) : ViewModel() { fun onSectionSelected(sectionKey: String) { val current = _uiState.value.detailState if (current != null && current.sectionKey == sectionKey) return + if (schema == null) { + pendingSectionKey = sectionKey + return + } loadSection(sectionKey) } @@ -133,6 +138,10 @@ class ConfigViewModel(private val apiClient: ConfigApiClient) : ViewModel() { _uiState.update { it.copy(listState = ListState.Loaded(s.toSummaries())) } + pendingSectionKey?.let { key -> + pendingSectionKey = null + loadSection(key) + } } catch (e: Exception) { _uiState.update { it.copy(