Skip to content

Attempt to fix crash on ProductListToolbarHelper #11484

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 4 commits into from
May 13, 2024

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented May 10, 2024

Closes: #11089 Closes: #11480

Description

This is just an attempt to fix the crash occurring on ProductListToolbarHelper, my theory of the crash is this: "if we check the events in Sentry, we can see that it always occur during a configuration change, and since we post the action to refresh the menu to the Toolbar's handler, there seems to be a race condition where the posting happens, and then a configuration change happens before the callback is executed, which means that when it does, the app's NavHostFragment could be still not attached"

To solve this, I did two changes to the ProductListToolbarHelper:

  1. I updated it to observe the View's Lifecycle instead of the Fragment's one, this is needed to ensure onDestroy is called during the View's detachment, and not after.
  2. I added logic to remove the menu refresh Runnable from the Toolbar's Handler when the view is destroyed.

Testing instructions

I couldn't reproduce the crash, so it's just code review, and ensuring nothing breaks.

Images/gif

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@hichamboushaba hichamboushaba added type: crash The worst kind of bug. category: tablet Specific to tablet devices such as a Galaxy Tab or an iPad. labels May 10, 2024
@hichamboushaba
Copy link
Member Author

@kidinov @jd-alexander I requested your review since you seem to have some past background about this, I'm keeping the PR as draft for now, my goal is just to start a discussion, and see if the theory above makes sense, then discuss if the fix is the appropriate one.

@hichamboushaba hichamboushaba changed the title Attempts to fix crash on ProductListToolbarHelper Attempt to fix crash on ProductListToolbarHelper May 10, 2024
@@ -86,7 +90,7 @@ class ProductListToolbarHelper @Inject constructor(
this.viewModel = productListViewModel
this.binding = binding

fragment.lifecycle.addObserver(this)
fragment.viewLifecycleOwner.lifecycle.addObserver(this)
Copy link
Member Author

@hichamboushaba hichamboushaba May 10, 2024

Choose a reason for hiding this comment

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

This change also ensures that we don't leak the fragment's view, we were setting binding to null in the fragment's onDestroy due to tying it to its Lifecycle, but now it'll be executed correctly on a matching callback of onDestroyView.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 10, 2024

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
FlavorJalapeno
Build TypeDebug
Commitb8867f0
Direct Downloadwoocommerce-prototype-build-pr11484-b8867f0.apk

@codecov-commenter
Copy link

codecov-commenter commented May 10, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 40.88%. Comparing base (e734909) to head (53d96e7).

❗ Current head 53d96e7 differs from pull request most recent head b8867f0. Consider uploading reports for the commit b8867f0 to get more accurate results

Files Patch % Lines
...droid/ui/products/list/ProductListToolbarHelper.kt 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #11484      +/-   ##
============================================
+ Coverage     40.84%   40.88%   +0.04%     
  Complexity     5180     5180              
============================================
  Files          1068     1067       -1     
  Lines         62283    62208      -75     
  Branches       8495     8484      -11     
============================================
- Hits          25437    25436       -1     
+ Misses        34559    34486      -73     
+ Partials       2287     2286       -1     

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

@kidinov kidinov self-assigned this May 13, 2024
Copy link
Contributor

@kidinov kidinov left a comment

Choose a reason for hiding this comment

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

@hichamboushaba Thank you! The potential fix makes sense to me

Have you considered adding a line in the release notes?

@hichamboushaba hichamboushaba marked this pull request as ready for review May 13, 2024 11:05
@hichamboushaba
Copy link
Member Author

Thanks @kidinov for the review.

Have you considered adding a line in the release notes?

Done.

@hichamboushaba hichamboushaba enabled auto-merge May 13, 2024 11:06
@hichamboushaba hichamboushaba merged commit 796a359 into trunk May 13, 2024
15 of 16 checks passed
@hichamboushaba hichamboushaba deleted the products/attempt-fix-crash branch May 13, 2024 11:42
@malinajirka malinajirka added this to the 18.7 milestone May 15, 2024
Copy link

sentry-io bot commented May 17, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ IllegalStateException: Fragment NavHostFragment{158d7f8} (e5f27f72-9492-48d8-bd99-77f34de9d016) has not been attached yet. Dashboard View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: tablet Specific to tablet devices such as a Galaxy Tab or an iPad. type: crash The worst kind of bug.
Projects
None yet
5 participants