Skip to content

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

Merged
merged 2 commits into from
Apr 22, 2025

Conversation

AdamGrzybkowski
Copy link
Contributor

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 the DisposableEffect is invoked after the NavController 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.

Before After
state_before state_after

Testing Steps

  1. Enable Developer Options on your device
  2. Launch the demo app
  3. Move to the Avatar update tab
  4. Paste in your WP token and select the checkbox next to it. You can also add it to secrets.properties file with name demo-app.bearer.token.
  5. Tap the avatar to launch the QE
  6. Tap on the View Profile
  7. Go back with a system button or a gesture
  8. Confirm the QE is restored and no errors are visible

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.
@AdamGrzybkowski AdamGrzybkowski added Bug Something isn't working [Feature] Gravatar-Quickeditor Gravatar Quick Editor module labels Apr 18, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Apr 18, 2025

📲 You can test the changes from this Pull Request in Gravatar Demo by scanning the QR code below to install the corresponding build.
App NameGravatar Demo
Commit78837cc
Direct Downloadgravatar-demo-prototype-build-pr610-78837cc.apk

Copy link
Contributor

@etoledom etoledom left a 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.

@AdamGrzybkowski AdamGrzybkowski requested a review from Copilot April 22, 2025 06:33
Copy link

@Copilot Copilot AI left a 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.

Comment on lines +111 to +112
QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage()
}
Copy link
Preview

Copilot AI Apr 22, 2025

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.

Suggested change
QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage()
}
if (authenticationMethod is AuthenticationMethod.Bearer) {
QuickEditorContainer.getInstance().resetUseInMemoryTokenStorage()
}

Copilot uses AI. Check for mistakes.

@AdamGrzybkowski AdamGrzybkowski merged commit ae201ff into trunk Apr 22, 2025
15 of 16 checks passed
@AdamGrzybkowski AdamGrzybkowski deleted the adam/609_state_retoration_fix branch April 22, 2025 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working [Feature] Gravatar-Quickeditor Gravatar Quick Editor module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Session expired" after re-opening the QuickEditor
3 participants