Skip to content

Properly init in-memory usage when restoring the state#610

Merged
AdamGrzybkowski merged 2 commits into
trunkfrom
adam/609_state_retoration_fix
Apr 22, 2025
Merged

Properly init in-memory usage when restoring the state#610
AdamGrzybkowski merged 2 commits into
trunkfrom
adam/609_state_retoration_fix

Conversation

@AdamGrzybkowski

Copy link
Copy Markdown
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

wpmobilebot commented Apr 18, 2025

Copy link
Copy Markdown
Collaborator
📲 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

@etoledom etoledom left a comment

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown

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()
}

Copilot AI Apr 22, 2025

Copy link

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
@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

4 participants