Skip to content

Fix debloater component toggle UI not updating after state change#1356

Merged
lihenggui merged 1 commit into
mainfrom
fix/debloater-component-toggle-ui
Nov 4, 2025
Merged

Fix debloater component toggle UI not updating after state change#1356
lihenggui merged 1 commit into
mainfrom
fix/debloater-component-toggle-ui

Conversation

@lihenggui

Copy link
Copy Markdown
Owner

Problem

In the DebloaterScreen, component toggle switches would not update in the UI after enabling/disabling a component, even though the controller successfully changed the component state. Users had to restart the app to see the changes.

Root Cause

The DebloaterViewModel used a continuous flow collection pattern that would overwrite optimistic UI updates when new data was emitted from the repository. The init block had:

init {
    viewModelScope.launch {
        debloatableComponentsFromRepository.collect { result ->
            _debloatableUiState.value = result  // Overwrites optimistic updates!
        }
    }
}

Solution

Refactored DebloaterViewModel to use one-time data loading with .first() similar to the RuleDetailViewModel pattern:

  • Changed from continuous flow collection to one-time loading in loadData() method
  • Added drop(1) to search query collection to avoid duplicate loads on initialization
  • Updated tests to initialize data before ViewModel creation

This prevents repository emissions from overwriting the optimistic UI updates made during component control operations.

Testing

  • All existing unit tests updated and passing
  • Verified component toggle behavior matches RuleDetailViewModel (SDK page) pattern

The debloater screen had a bug where component toggle switches would
not update in the UI after enabling/disabling a component, even though
the controller successfully changed the component state. This required
users to restart the app to see the changes.

Root cause: The ViewModel used a continuous flow that would overwrite
optimistic UI updates when new data was emitted from the repository.

Solution: Refactored DebloaterViewModel to use one-time data loading
with .first() similar to RuleDetailViewModel pattern. The init block
now calls loadData() once on initialization and when search query changes,
instead of continuously collecting from repository flow. This prevents
repository emissions from overwriting the optimistic UI updates made
during component control operations.

Changes:
- Modified DebloaterViewModel to use loadData() method with .first()
- Added drop(1) to search query collection to avoid duplicate loads
- Updated tests to initialize data before ViewModel creation
- All unit tests passing
@lihenggui lihenggui merged commit 0b92d7f into main Nov 4, 2025
4 checks passed
@lihenggui lihenggui deleted the fix/debloater-component-toggle-ui branch November 4, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant