CommunityToolkit / CommunityToolkit/Maui

[BUG] [iOS] CommunityToolkit.Maui Popup crashes with PopupNotFoundException on CloseAsync

Open
#3,218 7 comments 0 reactions 1 assignee Claimed by @TheCodeTraveler View on GitHub
bug unverified
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Did you read the "Reporting a bug" section on Contributing file?

- [x] 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 repeatedly opening and closing a CommunityToolkit.Maui.Views.Popup on iOS, the following exception is eventually thrown:

CommunityToolkit.Maui.Views.PopupNotFoundException
Unable to close popup: could not locate PopupPage.

I suspect this happens because CloseAsync() can be triggered multiple times for the same popup instance, causing the internal popup state to become invalid.

Observed behavior:

Popup opens/closes normally at first
After repeated open/close cycles the exception is thrown
In some cases the app terminates afterwards on iOS

### Expected Behavior

Calling CloseAsync() multiple times should either be ignored safely or handled gracefully without throwing PopupNotFoundException.

### Steps To Reproduce

1. Clone and run the reproduction repository on iOS (preferably on a physical device).

2. Open the popup using the button on the main page.

3. Close the popup using the button inside the popup.

Additional notes:

* The issue is easier to reproduce on a physical iPhone.
* Rapidly tapping both buttons with two fingers seems to increase the likelihood significantly.
* Rapid double tapping outside the popup backdrop may potentially be the actual trigger, but this could not be confirmed yet.
* The exception usually appears after a few minutes of repeated interaction.

### Link to public reproduction project repository

https://github.com/MatthewJer/TestPopup

### Environment

```markdown
* .NET MAUI CommunityToolkit: 14.1.1
* OS: iOS (physical device)
* .NET MAUI: 10.0.60
* Xcode: 26.4
* Reproduced on: iPhone
```

### Anything else?

A potentially related issue was previously reported here:

* [[CommunityToolkit/Maui Issue #2738](https://github.com/CommunityToolkit/Maui/issues/2738?utm_source=chatgpt.com)](https://github.com/CommunityToolkit/Maui/issues/2738?utm_source=chatgpt.com)

However, that report contains less detail and I could not find other issues clearly matching this behavior.

Since I now have:

* a minimal reproduction repository
* a fairly reliable reproduction path
* and additional observations regarding rapid repeated interactions

I decided to open a dedicated issue.

At the moment, this is currently our number one crash cause on iOS.

Any suggested workarounds or mitigation strategies would be highly appreciated while waiting for a proper fix.

Observed stacktrace:

Unable to close popup: could not locate PopupPage. ShowPopup or ShowPopupAsync must be called before CloseAsync. If using a custom implementation of Popup, override the CloseAsync method
at CommunityToolkit.Maui.Views.PopupPage.CloseAsync(PopupResult result, CancellationToken token) in /_/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs:line 86
at MauiApp1.MyPopup.Button_Clicked(Object sender, EventArgs e) in /Volumes/SDCard/WorkSpace/PopupTest/Popups/MyPopup.xaml.cs:line 14
at System.Threading.Tasks.Task.<>c.b__124_0(Object state)
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply()

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.