fix(android): don't wipe viewer lists on rotation — reset only on genuine session change #1538
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/android-viewer-rotation-empty"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
Rotating the screen while a photo was open in the full-bleed viewer showed the empty state ("Der er ikke noget at vise lige nu.",
R.string.viewer_empty) instead of the photo. The same wipe hit the search, album-detail, map and people viewers, and the open tab's list state in general.Root-cause chain
MainActivityhas noconfigChanges→ rotation = Activity recreation, the composition restarts.MemoriesApp.ktsince ISSUE-121) survive recreation under the Activity'sViewModelStore…LaunchedEffect(session) { vm.reset() }re-launches in the fresh composition even thoughsessionis unchanged:authRepository.sessionis aStateFlow(app-scoped inAppContainer) that replays its current value to the new collector.reset()calls, andTimelineViewModel.reset()emptied_uiStatetoTimelineUiState()exactly while the viewer destinations rendereditems = timelineState.items— trippingMediaViewerScreen's empty-list guard (the ISSUE-121 belt-and-braces check).reset()'s documented intent: "forget everything about the PREVIOUS login", not the current one.Fix shape
All six sites now call a small private helper:
The
rememberis deliberately notrememberSaveable: the last-seen-session anchor must NOT survive recreation, so a fresh composition re-seeds it from the current session and the comparison stays quiet — while a genuine session identity change (loginnull→s1, logouts1→null, re-logins1→s2; login always mints a fresh token andStoredSessionis a data class, so structural inequality is exact) still trips the reset, preserving the ISSUE-121 requirement that one member's data never lingers under another member's login. Process death also re-seeds — correct, because the ViewModels are fresh anyway.Untouched on purpose:
LaunchedEffect(session)(harmless on recreation:currentRouteis restored, not LOGIN);MediaViewerScreen's empty-list guard (stays as the ISSUE-121 safety net);ensureLoaded()'s own reentry throttle, independent of reset).Validation
ANDROID_HOME=~/Android/Sdk rtk ./gradlew :app:compileDebugKotlin(fromapps/android/) → BUILD SUCCESSFUL; no new warnings from the touched file.ANDROID_HOME=~/Android/Sdk rtk ./gradlew :app:testDebugUnitTest→ BUILD SUCCESSFUL; aggregated XML results: 75 suites / 935 tests / 0 skipped / 0 failures / 0 errors — matches the pre-change baseline exactly.Bookkeeping
KNOWN_ISSUES.md: new entry ISSUE-237 (high/open/area:timeline) in the Active section, referencing this branch for the resolve step after merge.apps/android/CHANGELOG.md: new## [0.10.26] - 2026-11-16Fixed entry (user-facing wording).apps/android/app/build.gradle.kts:versionName = "0.10.25"→"0.10.26"(versionCode derives from versionName; per release policy the bump rides along because the changelog entry exists).Rotating the screen while a photo was open showed the viewer empty state instead of the photo. MainActivity has no configChanges, so rotation recreates the Activity; the six app-scoped shell ViewModels survive that recreation, but each `LaunchedEffect(session) { vm.reset() }` re-launches in the fresh composition because authRepository.session is a StateFlow that replays its current value — so every rotation ran all six resets and TimelineViewModel.reset() emptied the list the open viewer was rendering (R.string.viewer_empty). The reset's documented intent is to forget the PREVIOUS login, which a re-run on recreation contradicts. All six sites now go through ResetOnSessionChange(session), a wrapper whose plain (deliberately NOT rememberSaveable) remembered last-session state makes the reset fire only on a genuine session identity change: recreation re-seeds the anchor quietly, while login (null→s1), logout (s1→null) and re-login (s1→s2) still reset so one member's data never lingers under another member's login. StoredSession is a data class with freshly minted tokens, so structural inequality is exact. The session-navigation LaunchedEffect is untouched (harmless on recreation: currentRoute is restored), the viewer empty-list guard stays as the ISSUE-121 belt-and-braces check, and timeline refresh-on-re-entry keeps coming from ensureLoaded()'s own reentry throttle. KNOWN_ISSUES: ISSUE-237. Changelog + versionName 0.10.26. Validation: :app:compileDebugKotlin green; :app:testDebugUnitTest green (75 suites / 935 tests / 0 failures, baseline unchanged). Manual QA scenario: open photo → rotate → photo stays; login/logout → lists reset.