Skip to content

Remove runBlocking call to restore sessions when the app starts#6193

Merged
jmartinesp merged 6 commits intodevelopfrom
fix/remove-runblocking-when-starting-app
Feb 24, 2026
Merged

Remove runBlocking call to restore sessions when the app starts#6193
jmartinesp merged 6 commits intodevelopfrom
fix/remove-runblocking-when-starting-app

Conversation

@jmartinesp
Copy link
Member

Content

This should take care of a few ANRs, although it may make loading the initial state a bit slower (not that I noticed that myself).

This is touching the most critical part of the app, so we need to be extra careful when testing it.

Motivation and context

This runBlocking was a constant source of ANR issues. With this maybe the ANR rate will drop significantly.

Tests

  • Start the app. The logged in UI should load just fine.
  • Open a different app and use adb shell am kill io.element.android.x.debug. The logs in AS should display the app has been killed.
  • Reopen the app, the previous session should be restored shortly after.

I also tried this 'kill the app, then open it' flow with a share intent, so it seems like it can work on different scenarios and not just the base 'app opened' scenario.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 16

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

@jmartinesp jmartinesp requested a review from a team as a code owner February 12, 2026 15:00
@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Feb 12, 2026
@jmartinesp jmartinesp requested review from bmarty and removed request for a team February 12, 2026 15:00
@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/LUyN1Z

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.42%. Comparing base (beaf59a) to head (13a48e4).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...n/io/element/android/appnav/ReplaceAllOperation.kt 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6193      +/-   ##
===========================================
- Coverage    81.42%   81.42%   -0.01%     
===========================================
  Files         2570     2571       +1     
  Lines        69799    69802       +3     
  Branches      8950     8950              
===========================================
  Hits         56833    56833              
- Misses        9645     9649       +4     
+ Partials      3321     3320       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmartinesp jmartinesp force-pushed the fix/remove-runblocking-when-starting-app branch from 3224995 to 0e64d9c Compare February 17, 2026 11:52
@jmartinesp
Copy link
Member Author

FWIW I've been using a release version with the latest changes of this branch for the past couple of days and I've had no issues with restoration either when coming back to the app through the launcher, or when using incoming share or opening notifications.

@jmartinesp
Copy link
Member Author

I've been using this for a week in a day-to-day scenario and had no issues, so it seems fine to merge this if we're comfortable with the changes.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

/**
* Restore the saved state for navigation in the current backstack.
*
* **WARNING:** this is an unsafe operation abusing the internals of the Appyx library, but it's the only way allow async state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a this warning in a comment above the line where Appyx version is set (here) too? Else I am pretty sure we may miss to check this during the next Appyx lib upgrade (if there is any)

@jmartinesp jmartinesp enabled auto-merge (squash) February 24, 2026 08:40
Sadly, to do this we need to manually handle restoring the state from Appyx using internal values. At least it doesn't seem like they're going to change any time soon (or ever).

This should take care of a few ANRs, although it may make loading the initial state a bit slower
It was added twice because previously both instances logged a different message
@jmartinesp jmartinesp force-pushed the fix/remove-runblocking-when-starting-app branch from f0a0042 to 13a48e4 Compare February 24, 2026 09:14
@sonarqubecloud
Copy link

@ElementBot
Copy link
Collaborator

Warnings
⚠️

gradle/libs.versions.toml#L6 - A newer version of com.android.tools.build:gradle than 8.13.2 is available: 9.0.1

⚠️

gradle/libs.versions.toml#L194 - A newer version of org.jsoup:jsoup than 1.21.2 is available: 1.22.1

Generated by 🚫 dangerJS against 13a48e4

@jmartinesp jmartinesp merged commit dfde64b into develop Feb 24, 2026
29 of 30 checks passed
@jmartinesp jmartinesp deleted the fix/remove-runblocking-when-starting-app branch February 24, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Bugfix For bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants