Repository navigation
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40520Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40520" |
|
Hey there @MykhailoDav! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
|
/review expert-review-with-gate |
|
Warning Your |
|
|
||
| updates = 0; | ||
| mockDeviceDisplay.SetMainDisplayOrientation(DisplayOrientation.Portrait); | ||
| Assert.Equal(0, updates); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - The post-removal assertion cannot distinguish unsubscription from handler disconnection. Setting secondWindow.Page = null calls Window.OnPageChanged, which invokes DisconnectHandlers and clears flyoutPage.Handler. Consequently, OnMainDisplayInfoChanged produces zero mapper updates even if _displayInfoProxy.Unsubscribe() is removed and the detached page remains subscribed. Reattach a mapper handler after removal, or assert the mock's subscription count, so this negative regression case detects a leftover display subscription.
### Description of Change `FlyoutPage` has the same static `DeviceDisplay.MainDisplayInfoChanged` subscription that #40453 fixed for `OrientationStateTrigger` and `DisplayRotationStateTrigger`. It subscribes when its window is set and unsubscribes only when the window becomes null. That causes two problems: - `Window.Destroying` doesn't clear `Page`, so on Android every Activity recreation leaves the previous `FlyoutPage` rooted by the static event when `CreateWindow` returns a new one. - When a page moves straight from one window to another (for example a page reused through DI), it subscribes twice. The handler then runs twice per display change, and one subscription is left behind after the page leaves the window. `FlyoutPage` now subscribes through `WeakDisplayInfoChangedProxy`, the proxy added in #40453. It keeps the delegate in a field, because the proxy holds the handler weakly. `Subscribe` drops the previous subscription first, which fixes the double subscription. `OnMainDisplayInfoChanged` is unchanged. #40453 is in `candidate/11.0.1xx-sr2` but not yet in `net11`. This PR adds the proxy class to `WeakEventProxy.cs` with exactly the content #40453 gave the file, so merging into a branch that already has #40453 doesn't change it. ### Tests Two tests in `FlyoutPageUnitTests`: - `FlyoutPageInWindowDoesNotStayAlive` puts a `FlyoutPage` in a window, drops both, and checks the page is collected. Without the fix: `FlyoutPage should not be alive!` - `FlyoutPageMovedToAnotherWindowHandlesDisplayChangesOnce` moves the page from one window to another, checks that one display change updates `FlyoutBehavior` once, and that nothing updates after the page leaves the window. Without the fix: `Expected: 1, Actual: 2`. FlyoutPage tests: 55/57 → 57/57. Full Controls.Core.UnitTests: 6735 passed, 1 failed, the same failure as on clean `net11` (`TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, a decimal-comma locale issue on my machine). **Before / after** (sandbox app, Android emulator API 37, Release): `CreateWindow` returns a new `FlyoutPage`. The font scale was changed four times to recreate the Activity, and the label shows how many `FlyoutPage` instances are still alive after a GC. | Before: 5 of 5 FlyoutPages still alive | After: 1 of 5 alive | |---|---| |  |  | Full clips: [before.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/flyoutpage-leak-before.mp4) · [after.mp4](https://raw.githubusercontent.com/MykhailoDav/maui/media-pr-2026-11-12/flyoutpage-leak-after.mp4) Not checked: iOS, Mac Catalyst and Windows (the change is in shared code), and the window-to-window case in a real app (unit test only). ### Issues Fixed Related to #40450 Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
Conflicts: FlyoutPage keeps the weak DeviceDisplay proxy (dotnet#40520) with net11's window-and-handler-aware subscription; MemoryTests and WindowHandlerTests.Windows keep the tests added on both sides. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Description of Change
FlyoutPagehas the same staticDeviceDisplay.MainDisplayInfoChangedsubscription that #40453 fixed forOrientationStateTriggerandDisplayRotationStateTrigger. It subscribes when its window is set and unsubscribes only when the window becomes null. That causes two problems:Window.Destroyingdoesn't clearPage, so on Android every Activity recreation leaves the previousFlyoutPagerooted by the static event whenCreateWindowreturns a new one.FlyoutPagenow subscribes throughWeakDisplayInfoChangedProxy, the proxy added in #40453. It keeps the delegate in a field, because the proxy holds the handler weakly.Subscribedrops the previous subscription first, which fixes the double subscription.OnMainDisplayInfoChangedis unchanged.#40453 is in
candidate/11.0.1xx-sr2but not yet innet11. This PR adds the proxy class toWeakEventProxy.cswith exactly the content #40453 gave the file, so merging into a branch that already has #40453 doesn't change it.Tests
Two tests in
FlyoutPageUnitTests:FlyoutPageInWindowDoesNotStayAliveputs aFlyoutPagein a window, drops both, and checks the page is collected. Without the fix:FlyoutPage should not be alive!FlyoutPageMovedToAnotherWindowHandlesDisplayChangesOncemoves the page from one window to another, checks that one display change updatesFlyoutBehavioronce, and that nothing updates after the page leaves the window. Without the fix:Expected: 1, Actual: 2.FlyoutPage tests: 55/57 → 57/57. Full Controls.Core.UnitTests: 6735 passed, 1 failed, the same failure as on clean
net11(TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull, a decimal-comma locale issue on my machine).Before / after (sandbox app, Android emulator API 37, Release):
CreateWindowreturns a newFlyoutPage. The font scale was changed four times to recreate the Activity, and the label shows how manyFlyoutPageinstances are still alive after a GC.Full clips: before.mp4 · after.mp4
Not checked: iOS, Mac Catalyst and Windows (the change is in shared code), and the window-to-window case in a real app (unit test only).
Issues Fixed
Related to #40450