Skip to content

Fix dashboard 30s+ spinner on Dark theme cold start - #40

Open
T0liver wants to merge 1 commit into
mainfrom
c-fix-dashboard-dark-coldstart-8fd8
Open

T0liver wants to merge 1 commit into
mainfrom
c-fix-dashboard-dark-coldstart-8fd8

Conversation

@T0liver

@T0liver T0liver commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Fixes #37

Root cause (medium-high confidence)

On cold start with Settings → Theme = Dark, ThemeViewModel initially exposes ThemeMode.SYSTEM (light on a light emulator) until DataStore emits the saved value. That forces a full ViNotesTheme light→dark recomposition around the time the Home dashboard starts observing data.

Since PR #26 (#20), the dashboard kept isLoading = true until a single combine(recentTastings, dashboardStats, getAppPreferences) produced a value. getAppPreferences() is itself a 5-way DataStore combine, and the same preferences pipeline is already collected at the activity level for theme/locale. When DataStore delivery is delayed or interrupted by the theme flip / locale setup, the combined emission never arrives while the UI shows only the empty-state loading branch (isLoading && recentTastings.isEmpty()).

Light-theme cold starts often avoid the theme flip (system already light → saved Light), which matches the A/B in the issue.

Fix

  1. DashboardViewModel: observe Room stats/tastings in one long-lived combine that clears isLoading; collect preferences in a parallel job for username / welcome dialog only (preserves [Automated test] Dashboard spins forever after "Delete all data" #20’s single-subscription behavior for DB flows).
  2. MainActivity: read saved theme and language once before setContent, apply locales early, and use those values until ThemeViewModel catches up so the first frame uses the correct theme.

Tests

  • Added clearsLoadingWithoutWaitingOnPreferences.
  • Existing dashboard loading tests unchanged.

Local: ./gradlew assembleDebug testDebugUnitTest (with -Dorg.gradle.jvmargs=-Xmx4g) — BUILD SUCCESSFUL.

Open in Web Open in Cursor 

Stop gating isLoading on DataStore preferences and apply saved theme
and locale before the first Compose frame so dashboard Room flows can
clear the loading state promptly after #26.

Co-authored-by: T0liver <T0liver@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Test Results

20 tests  +1   20 ✅ +1   1s ⏱️ ±0s
 5 suites ±0    0 💤 ±0 
 5 files   ±0    0 ❌ ±0 

Results for commit c27dcb6. ± Comparison against base commit e7ecd3a.

This branch has not been deployed

No deployments
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.

[Automated test] Dashboard shows only a spinner for 30 s+ on cold start with Dark theme (Found by automated testing, Release Tester, v1.1.0)

2 participants