Properly init in-memory usage when restoring the state#610
Conversation
When restoring the state after the activity got killed, the NavController would immidiately launch the previous destination even before running the DisposableEffect. Moving the effect up fixes this timing issue.
📲 You can test the changes from this Pull Request in Gravatar Demo by scanning the QR code below to install the corresponding build.
|
etoledom
left a comment
There was a problem hiding this comment.
I was able to reproduce the issue in trunk, and these changes fixes it 🎉
I also saw another problem where the profile card wasn't showing when opening the QE with a given token, but this also seem to have been fixed with these changes.
This last issue I wasn't to reproduce it again in trunk, so I can't get a video now.
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a timing issue with state restoration by ensuring that in-memory token storage is activated before the ViewModel and its dependencies are created. The changes include moving the DisposableEffect for token storage initiation from GravatarQuickEditorPage to GravatarQuickEditorBottomSheet, and updating state persistence in the demo app.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/bottomsheet/GravatarQuickEditorBottomSheet.kt | Moves DisposableEffect logic to a higher composition level for proper initialization. |
| gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/GravatarQuickEditorPage.kt | Removes redundant DisposableEffect logic from the navigation page. |
| demo-app/src/main/java/com/gravatar/demoapp/ui/AvatarUpdateTab.kt | Updates state handling with rememberSaveable for persistence. |
| QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage() | ||
| } |
There was a problem hiding this comment.
Consider conditionally calling resetUseInMemoryTokenStorage() within the onDispose block only when authenticationMethod is Bearer. This will ensure that the reset is only performed if the in-memory token storage was actually enabled.
| QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage() | |
| } | |
| if (authenticationMethod is AuthenticationMethod.Bearer) { | |
| QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage() | |
| } |
Closes #609
Description
When the "Don't keep activities" is ON, the Quick Editor state won't properly display the data inside. It's caused by a timing issue. The
QuickEditorContainer.getInstance().useInMemoryTokenStorage()that is called in theDisposableEffectis invoked after theNavControllerstarts the restored destination, so the ViewModel and its dependencies don't use the in-memory storage as they should.Moving the
DisposableEffectto a Composable higher up in the hierarchy fixes this timing issue.Testing Steps
secrets.propertiesfile with namedemo-app.bearer.token.View Profile