fix(conversation-list): keep showing cached conversations while paging reloads after navigation#4834
Closed
MohamadJaara wants to merge 5 commits into
Closed
fix(conversation-list): keep showing cached conversations while paging reloads after navigation#4834MohamadJaara wants to merge 5 commits into
MohamadJaara wants to merge 5 commits into
Conversation
fb51dd2 to
30a84bb
Compare
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (76.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #4834 +/- ##
===========================================
+ Coverage 51.16% 51.19% +0.03%
===========================================
Files 611 612 +1
Lines 21139 21163 +24
Branches 3399 3402 +3
===========================================
+ Hits 10816 10835 +19
- Misses 9308 9312 +4
- Partials 1015 1016 +1
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
…igation and prevent unnecessary reloads
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What's new in this PR?
Issues
After navigating away from the conversation list (e.g. opening a conversation) and back, if the underlying data had changed while the user was away, the list area briefly flashed:
LoadingListContent)before the conversations re-appeared. This broke visual continuity and scroll-state expectations on back-navigation.
This is the residual flicker the previous PR (#) flagged but could not fully eliminate.
Causes
paging-compose 3.3.x changed
collectAsLazyPagingItemsso that it emits an emptyLazyPagingItemson the very first composition before the cachedPagingDatareplays. WhencachedInis invalidated upstream — which happens any time conversation activity occurs while the user is on another screen — the newLazyPagingItemsinstance starts withitemCount == 0andloadState.refresh == Loadinguntil the new pages finish loading.The previous PR mitigated this for the no-data-change case by adding
shareInon top ofcachedInso the upstream subscriber stays alive, but the consumer-sideLazyPagingItemsis still rebuilt on every composition and there was no in-memory source for the screen to fall back to during the empty frame.Solutions
ConversationListViewModelnow exposesitemSnapshotCache: StateFlow<PersistentList<ConversationItemType>>. It lives inviewModelScope, so it survives back-stack navigation and is scoped perConversationsSource(Main, Archive, Favorites…).ConversationsScreenContentfeeds the cache fromLazyPagingItems.itemSnapshotListviasnapshotFlow, filtering out empty snapshots so the transient empty frame never overwrites the cache.ConversationList(conversationItemsSnapshot: ImmutableList<ConversationItemType>, …)overload renders from a plain list using the same keys, content types, andConversationItemFactorycallbacks as the paged variant.ConversationsScreenContentis now:ConversationList.Reloadingand cache non-empty → snapshotConversationList(new bridge — eliminates the flash).Dependencies
Needs releases with:
shareInto the conversation paging flow and simplifiescollectAsLazyPagingItemsWithLifecycle). This PR is built on top of those changes.Testing
Test Coverage
Added
given snapshot cache update, when reading itemSnapshotCache, then it reflects the latest valuetoConversationListViewModelTest.How to Test
Prerequisite: at least one conversation in the list.
Notes
ConversationListViewModelinstance (keyed byConversationsSource), so each list flavor has its own fallback and they don't bleed into one another.ConversationListoverloads share rendering logic but are intentionally not deduplicated yet — the paged variant usesLazyPagingItems.itemKey/itemContentTypehelpers that don't apply to a plain list. Happy to extract a sharedLazyListScopeextension as a follow-up if reviewers prefer.kotlinx.collections.immutableandandroidx.lifecycle.composealready present in the project.