Skip to content

Fix #142: Prevent Design Switcher from briefly showing 'Offline'#2421

Merged
dipenpradhan merged 1 commit intomainfrom
fix/142-switcher-offline-flash
Apr 15, 2026
Merged

Fix #142: Prevent Design Switcher from briefly showing 'Offline'#2421
dipenpradhan merged 1 commit intomainfrom
fix/142-switcher-offline-flash

Conversation

@anshu10sep
Copy link
Copy Markdown
Collaborator

Summary

Fixes the Design Switcher briefly flashing "Offline" status when switching documents.

Problem

When enableLiveUpdates() is called, it sets up a coroutine to collect the Figma token from a DataStore-backed flow. The flow's initial emission is null (before the stored value is read from disk), which momentarily sets isDocumentLive to false. The Design Switcher reads this value and briefly shows the "Offline" variant.

Timeline

1. enableLiveUpdates() called
2. collectLatest starts → first emission is null
3. isDocumentLive = false  ← Brief 'Offline' flash
4. DataStore reads stored token → emits actual value
5. isDocumentLive = true   ← Back to 'Live'

Fix

Set isDocumentLive = true optimistically at the start of enableLiveUpdates():

// Set live status optimistically
isDocumentLive.value = true

// The coroutine will correct to false if no token is found
activity.lifecycleScope.launch { ... }

Behavior

Scenario Before After
Has token Offline → Live (flash) Live (stable)
No token Offline → Live → Offline (flash) Live → Offline

Changes

  • designcompose/src/main/java/com/android/designcompose/DocServer.kt: Set isDocumentLive.value = true before launching the token collection coroutine

Validation

  • ./gradlew designcompose:compileDebugKotlin: Passes ✅

Fixes #142

When enableLiveUpdates() was called, it launched a coroutine to
collect the Figma token from the settings flow. The flow's initial
emission was null (before the stored value was read), which
momentarily set isDocumentLive to false, causing the Design
Switcher to flash 'Offline' before settling on 'Live'.

Fix: Set isDocumentLive to true optimistically at the start of
enableLiveUpdates(). The collectLatest coroutine will correct it
to false if no token is ultimately found.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.03%. Comparing base (af5409b) to head (9a4a39c).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2421      +/-   ##
============================================
- Coverage     44.05%   44.03%   -0.03%     
  Complexity       19       19              
============================================
  Files            39       39              
  Lines          4444     4444              
  Branches         51       51              
============================================
- Hits           1958     1957       -1     
- Misses         2472     2473       +1     
  Partials         14       14              
Flag Coverage Δ
kotlin 72.17% <ø> (ø)
rust 41.66% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@anshu10sep anshu10sep requested a review from dipenpradhan April 10, 2026 02:47
@github-actions
Copy link
Copy Markdown

Snapshot diff report vs base branch: main
Last updated: Thu Apr 9 19:56:29 PDT 2026, Sha: 9a4a39c
No differences detected

@dipenpradhan dipenpradhan added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit 05f7f00 Apr 15, 2026
23 checks passed
@dipenpradhan dipenpradhan deleted the fix/142-switcher-offline-flash branch April 15, 2026 01:27
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.

Design Switcher briefly shows "Offline" when switching documents

3 participants