Maui: [BUG] Popup V2 - Android - ShowPopupAsync(INavigation) returns a Task that never completes
Is there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- I have read the “Reporting a bug” section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
When I call ShowPopupAsync and then call CloseAsync() from inside my popup, the popup closes but ShowPopupAsync’s task never completes so the result is never available.
Expected Behavior
I expect the task to complete when I close the popup.
Steps To Reproduce
- Derive a popup from Popup<bool?>
- Call OpenPopupAsync() on it, and close the popup from within using CloseAsync()
- Note that await OpenPopupAsync() never returns
Link to public reproduction project repository
https://github.com/mfeingol/repros/tree/master/CommunityToolkit_2703_repro
Environment
- .NET MAUI CommunityToolkit: 12.0.0
- OS: Windows 11
- .NET MAUI: 9.0.71
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 8
- Comments: 47 (19 by maintainers)
Commits related to this issue
- Add Popup Tests These tests were added when debugging https://github.com/CommunityToolkit/Maui/issues/2703 — committed to CommunityToolkit/Maui by TheCodeTraveler a year ago
@bijington I gave the PR bits a quick spin and they appear to have resolved the problem. Thanks for the legwork here.
@mfeingol I did find time to have a go and I have a PR https://github.com/CommunityToolkit/Maui/pull/2756 that should fix it.
If you get a chance before the PR merges then you could try testing the fix by following the guide at https://github.com/CommunityToolkit/Maui/wiki/Preview-Packages
@mfeingol excellent work! I can confirm that I can reproduce 100% of the time now.
I’ve had a Quick Look at our code and there is in fact a
WeakEventManagerinstance for handling the popup close events. I might not be able to look at it today but it looks like we might need a stronger reference.I think the first step will be to reproduce this in a unit test (which I hope should be straightforward given your investigation work) and then debug/fix it
@bijington:
OK, I think I have a winner. I added GC.Collect() calls before and after the call to CloseAsync() and I now have a 100% repro with and without hot reload and even without a debugger.
My point was just to highlight that the bug involved swallowing touch input which may have prevented your tapped event from firing.
@bijington: thanks for looking. I accepted your PR and made a couple of tweaks to the project to get it to build successfully on Android. The popup now renders in its full garish color glory. 😃
Now… without a debugger the sample does not reproduce. However, with a debugger attached to an Android emulator I’m able to reproduce the issue very reliably. I’ve attached a video of me clicking on the popup close button three times - in two cases the repro occurs.
https://github.com/user-attachments/assets/0c6d6ca4-eeee-4ac2-975f-4693f7b57a67
@mfeingol I managed to work out the rendering issues - I have opened a PR to your repros repository to fix this. It looks like you had some bugs in your repro https://github.com/mfeingol/repros/pull/1
As for the main topic of this bug I am still unable to reproduce the issue that you mention even with the debugger attached.
It seems to repro either way. Using the default shell mechanism was faster and I didn’t have a lot of time.
The problem seems to be in the TaskCompletionSource of the ShowPopupAsync method in the PopupExtensions class. If you bring the TaskCompletionSource inside the PopupPage class the close event is called. The Subscription object of the WeakEventManager class has the Target null when the Close of the popup is executed.
Thanks for looking into this @TheCodeTraveler , can you edit your test to actually return a DTO/value from the Popup? I’ve tried a lot different things but I just cannot get the task to return.
I think this is the same issue: https://developercommunity.visualstudio.com/t/Popup-v2-in-CommunityToolkitMaui-1200/10921966?viewtype=all&space=21&ftype=problem&sort=newest
I’m seeing the same issue. But only when I use the system back button (< ) (On android, haven’t tried iOs).
Example in Android …
TestPage.xaml
TestPage.xaml.cs
TestPopup.xaml
TestPopup.xaml.cs