-
Notifications
You must be signed in to change notification settings - Fork 32
Properly init in-memory usage when restoring the state #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() | |
} |
Copilot uses AI. Check for mistakes.
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 theDisposableEffect
is invoked after theNavController
starts the restored destination, so the ViewModel and its dependencies don't use the in-memory storage as they should.Moving the
DisposableEffect
to a Composable higher up in the hierarchy fixes this timing issue.Testing Steps
secrets.properties
file with namedemo-app.bearer.token
.View Profile