Repository navigation
[Windows] Fix crash when clicking a tab with sub tabs in the Shell TabBar overflow menu - #39412
Conversation
WinUI cant select a data bound NavigationView item with children while it sits in the overflow menu of the top tab bar, it fails with E_BOUNDS. In the overflow menu such a tab now only expands, and the navigation happens when one of its sub tabs is picked. Fixes dotnet#37985
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39412Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39412" |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Hey there @@Empiree! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Hey there @Empiree! 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.
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
| // a tab with sub tabs only expands, and the navigation happens when one of its sub tabs is picked. | ||
| static void OnOverflowMenuItemPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) | ||
| { | ||
| if (args.Element is NavigationViewItem item && item.DataContext is NavigationViewItemViewModel { MenuItemsSource: not null }) |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Logic and Correctness — SelectsOnInvoked is updated only during ElementPrepared/ElementClearing, so an already-prepared overflow NavigationViewItem is not updated when its bound NavigationViewItemViewModel.MenuItemsSource changes at runtime. Concrete scenario: a tab initially has a single ShellContent (prepared with default selectable behavior) and later receives another ShellContent via ItemsCollectionChanged/MapMenuItems, making MenuItemsSource non-null without recycling the existing overflow container; clicking it in overflow still follows the select path that this fix is meant to avoid (E_BOUNDS repro path).
There was a problem hiding this comment.
Fixed, MapMenuItems now updates SelectsOnInvoked of the overflow items that are already realized. Covered by TabBarOverflowMenuTabFollowsItsShellContentChanges.
| static void OnOverflowMenuItemPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) | ||
| { | ||
| if (args.Element is NavigationViewItem item && item.DataContext is NavigationViewItemViewModel { MenuItemsSource: not null }) | ||
| item.SelectsOnInvoked = false; |
There was a problem hiding this comment.
[major] Logic and Correctness - Keep SelectsOnInvoked synchronized with changes to an existing overflow item's MenuItemsSource. Open overflow for an inactive tab containing two ShellContents, remove one content, then change TabBar.Title to refresh MapMenuItems while the container remains realized. SyncItems retains the existing view model, and MapMenuItems sets its MenuItemsSource to null. The template updates its children, but neither ElementPrepared nor ElementClearing runs for that property update, leaving SelectsOnInvoked=false. The now-single-content tab cannot be selected and has no children through which to navigate. Update the restriction on child-source changes as well as container preparation, and cover this transition in the regression test.
There was a problem hiding this comment.
Fixed the same way, the new test also checks the other direction (sub tab removed, the tab is selectable again and navigates)
|
|
||
| // The tab only expands to show its sub tabs, the current page stays the same | ||
| Assert.True(nestedItem.IsExpanded); | ||
| Assert.NotEqual(nestedTab, shell.CurrentItem.CurrentItem); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - Add a negative-case assertion for an ordinary single-content tab in the overflow menu. The fixture creates seven such tabs but never invokes one; selecting Sub B exercises a child container, not a top-level container prepared by the overflow ItemsRepeater. Setting SelectsOnInvoked=false for every top-level overflow item would therefore still satisfy this test while preventing ordinary overflow tabs from navigating. That working case is an explicit counter-check in #37985. Invoke a single-content tab from the same overflow menu and assert that Shell switches to it, so the test distinguishes selective suppression from disabling all overflow selection.
There was a problem hiding this comment.
Added, the test now opens Tab 7 from the overflow menu first and checks the navigation.
kubaflo
left a comment
There was a problem hiding this comment.
Looks good, but could you please check the ai's suggestions?
Applying the NavigationView template again creates a new overflow menu, the new test checks that the handler follows it.
|
@kubaflo thanks for running it again. This time the review had no findings on the code, only the reviewer candidate with an extra template check in the test. I added that check, but as its own test TabWithSeveralShellContentsOnlyExpandsInNewTabBarOverflowMenuAfterTemplateIsAppliedAgain. It opens the overflow menu, applies the NavigationView template again and checks that Nested in the new overflow menu only expands. I didnt put it into the leaving overflow test like the candidate did. It looks like after the template is applied again WinUI stops reusing the overflow container for the bar, so that test passes even without the reset in ElementClearing, and the reset is what it was added for. Checked each part on my side. Without the reset only the leaving overflow test fails, without following the new template only the new test fails, with the full fix all four pass. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis🧪 CI Analysis — click to expand📊 maui-prNo failures found. 🧪 maui-pr-devicetestsNo failures found. 🧪 maui-pr-uitestsAll five
🧭 Follow-up — actions and refreshNext action: Inspect the MenuBar click target and unmatched screenshots; restore provisioning diagnostics and compare identical-setup outcomes.
|
Preserve the overflow-menu regression tests and helpers alongside the independent dynamically-added disabled-tab appearance test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Resolved and pushed the conflict with The only conflict was overlapping additions in Validation: scoped |
…bBar overflow menu (#39412) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change On Windows, clicking a Shell tab with more than one ShellContent in the overflow menu of the top tab bar (the ... button) crashed the app with E_BOUNDS (invalid vector subscript). The crash is inside WinUI NavigationView. From what I see in the WinUI code, in Top mode it cant find the container of a data bound item that sits in the overflow menu, so the clicked item never gets IsSelected, only IsChildSelected, and when it expands right after the click WinUI reads past the end of the selected index path. MAUI always fills the tab bar through MenuItemsSource, so every tab with sub tabs runs into it. A plain WinUI NavigationView with MenuItemsSource and a similar item template crashes the same way. Fixing up the selection state after the click only helps for the first click, other overflow bugs in WinUI show up after that (for example picking a sub tab from the overflow menu and closing the menu later crashes again). So now ShellItemHandler sets SelectsOnInvoked to false on overflow menu containers that have sub tabs, and clears it when the container leaves the overflow menu. MapMenuItems also updates the items that are already in the overflow menu, because a tab can get or lose sub tabs while it sits there. A click on such a tab just expands it, picking one of its sub tabs navigates like before and WinUI moves the tab into the bar. Tabs in the bar work like before. There are four device tests. The first one opens a tab with one ShellContent from the overflow menu, then clicks the tab with sub tabs, picks Sub B and checks the navigation. The second one adds and removes a sub tab of a tab that already sits in the open overflow menu and checks the item follows. The third one moves a tab with sub tabs from the overflow menu back into the bar and checks it gets selected there like before. The fourth one applies the NavigationView template again and checks the new overflow menu behaves the same. Without the fix the click makes WinUI kill the whole test app, so the tests check SelectsOnInvoked before clicking to fail in a normal way. ### Issues Fixed Fixes #37985 --------- Co-authored-by: Empiree <Empiree@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…bBar overflow menu (#39412) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change On Windows, clicking a Shell tab with more than one ShellContent in the overflow menu of the top tab bar (the ... button) crashed the app with E_BOUNDS (invalid vector subscript). The crash is inside WinUI NavigationView. From what I see in the WinUI code, in Top mode it cant find the container of a data bound item that sits in the overflow menu, so the clicked item never gets IsSelected, only IsChildSelected, and when it expands right after the click WinUI reads past the end of the selected index path. MAUI always fills the tab bar through MenuItemsSource, so every tab with sub tabs runs into it. A plain WinUI NavigationView with MenuItemsSource and a similar item template crashes the same way. Fixing up the selection state after the click only helps for the first click, other overflow bugs in WinUI show up after that (for example picking a sub tab from the overflow menu and closing the menu later crashes again). So now ShellItemHandler sets SelectsOnInvoked to false on overflow menu containers that have sub tabs, and clears it when the container leaves the overflow menu. MapMenuItems also updates the items that are already in the overflow menu, because a tab can get or lose sub tabs while it sits there. A click on such a tab just expands it, picking one of its sub tabs navigates like before and WinUI moves the tab into the bar. Tabs in the bar work like before. There are four device tests. The first one opens a tab with one ShellContent from the overflow menu, then clicks the tab with sub tabs, picks Sub B and checks the navigation. The second one adds and removes a sub tab of a tab that already sits in the open overflow menu and checks the item follows. The third one moves a tab with sub tabs from the overflow menu back into the bar and checks it gets selected there like before. The fourth one applies the NavigationView template again and checks the new overflow menu behaves the same. Without the fix the click makes WinUI kill the whole test app, so the tests check SelectsOnInvoked before clicking to fail in a normal way. ### Issues Fixed Fixes #37985 --------- Co-authored-by: Empiree <Empiree@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…bBar overflow menu (#39412) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change On Windows, clicking a Shell tab with more than one ShellContent in the overflow menu of the top tab bar (the ... button) crashed the app with E_BOUNDS (invalid vector subscript). The crash is inside WinUI NavigationView. From what I see in the WinUI code, in Top mode it cant find the container of a data bound item that sits in the overflow menu, so the clicked item never gets IsSelected, only IsChildSelected, and when it expands right after the click WinUI reads past the end of the selected index path. MAUI always fills the tab bar through MenuItemsSource, so every tab with sub tabs runs into it. A plain WinUI NavigationView with MenuItemsSource and a similar item template crashes the same way. Fixing up the selection state after the click only helps for the first click, other overflow bugs in WinUI show up after that (for example picking a sub tab from the overflow menu and closing the menu later crashes again). So now ShellItemHandler sets SelectsOnInvoked to false on overflow menu containers that have sub tabs, and clears it when the container leaves the overflow menu. MapMenuItems also updates the items that are already in the overflow menu, because a tab can get or lose sub tabs while it sits there. A click on such a tab just expands it, picking one of its sub tabs navigates like before and WinUI moves the tab into the bar. Tabs in the bar work like before. There are four device tests. The first one opens a tab with one ShellContent from the overflow menu, then clicks the tab with sub tabs, picks Sub B and checks the navigation. The second one adds and removes a sub tab of a tab that already sits in the open overflow menu and checks the item follows. The third one moves a tab with sub tabs from the overflow menu back into the bar and checks it gets selected there like before. The fourth one applies the NavigationView template again and checks the new overflow menu behaves the same. Without the fix the click makes WinUI kill the whole test app, so the tests check SelectsOnInvoked before clicking to fail in a normal way. ### Issues Fixed Fixes #37985 --------- Co-authored-by: Empiree <Empiree@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…bBar overflow menu (#39412) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change On Windows, clicking a Shell tab with more than one ShellContent in the overflow menu of the top tab bar (the ... button) crashed the app with E_BOUNDS (invalid vector subscript). The crash is inside WinUI NavigationView. From what I see in the WinUI code, in Top mode it cant find the container of a data bound item that sits in the overflow menu, so the clicked item never gets IsSelected, only IsChildSelected, and when it expands right after the click WinUI reads past the end of the selected index path. MAUI always fills the tab bar through MenuItemsSource, so every tab with sub tabs runs into it. A plain WinUI NavigationView with MenuItemsSource and a similar item template crashes the same way. Fixing up the selection state after the click only helps for the first click, other overflow bugs in WinUI show up after that (for example picking a sub tab from the overflow menu and closing the menu later crashes again). So now ShellItemHandler sets SelectsOnInvoked to false on overflow menu containers that have sub tabs, and clears it when the container leaves the overflow menu. MapMenuItems also updates the items that are already in the overflow menu, because a tab can get or lose sub tabs while it sits there. A click on such a tab just expands it, picking one of its sub tabs navigates like before and WinUI moves the tab into the bar. Tabs in the bar work like before. There are four device tests. The first one opens a tab with one ShellContent from the overflow menu, then clicks the tab with sub tabs, picks Sub B and checks the navigation. The second one adds and removes a sub tab of a tab that already sits in the open overflow menu and checks the item follows. The third one moves a tab with sub tabs from the overflow menu back into the bar and checks it gets selected there like before. The fourth one applies the NavigationView template again and checks the new overflow menu behaves the same. Without the fix the click makes WinUI kill the whole test app, so the tests check SelectsOnInvoked before clicking to fail in a normal way. ### Issues Fixed Fixes #37985 --------- Co-authored-by: Empiree <Empiree@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…l test reopens it (#40359) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). This is a test-only fix for the SR2 candidate validation in #40116, so it targets `candidate/11.0.1xx-sr2`, like the earlier candidate test fixes. ### Description of Change On candidate head `888db82bd5`, Windows device-test build 1686840 failed `ShellTests.TabWithSeveralShellContentsOpensFromTabBarOverflowMenu` (run 47076696, result 102198) at `ShellTabBarTests.Windows.cs:276` with `The overflow menu did not open again`. That test came in with #39412. **Root cause (test timing):** 1. The test clicks "Tab 7", and later "Sub B", in the tab bar overflow menu. Both tabs select on invoke, so the click hides the menu. 2. Hiding only closes the flyout's popup. WinUI keeps the `MenuFlyout` registered as open until its presenter unloads and raises `Closed`. Until then, `ShowAt` on the same flyout and target is ignored. 3. The test waits for navigation and then reopens the menu with `ShowAt`. Navigation is usually observed after the presenter has unloaded, but not always. When it's observed first, `ShowAt` is a no-op and `IsOpen` never becomes true. **Fix:** a new helper, `ClickOverflowMenuItemThatClosesMenu`, waits for `Flyout.Closed` after the two clicks that close the menu, before the menu is reopened. The diff is +21/−2 in `ShellTabBarTests.Windows.cs` only. Assertions, messages, deadlines and test cases are unchanged. No product code changes. **Causal evidence (Helix `Windows.11.Amd64.Client.Open`, Controls device tests, Shell category):** A temporary, uncommitted probe (`OverflowProbe*`, never committed) runs alongside the real tests: - **A (trigger):** clicks "Sub B" and calls `ShowAt` at once, as when navigation is observed before the presenter unloads. - **B (trigger + fix):** the same, but clicks with this PR's helper. - **C (real test):** `TabWithSeveralShellContentsOpensFromTabBarOverflowMenu`, 20 iterations. - **D (trigger removed):** the original order, which waits for navigation before reopening. | Leg | Helper wait present | A trigger | B trigger + helper | C real test | D no trigger | Real overflow tests | | --- | --- | --- | --- | --- | --- | --- | | fix | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | reverted (r1) | no | — | — | — | — | not run: the probe edit failed to build (CS0219) | | reverted (r2) | no | red 10/10 | **red 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r1) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r2) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | Each leg's payload records `variant.json` with `fixWaitPresent` and SHA-256s of the test and probe files. - Helix jobs: `509c2c0a-230d-4310-9524-199f5d1858e9` (r1) and `c16a74fd-9a5b-4979-b7a9-22d0519b5755` (r2). - r1's reverted leg failed to compile, so r2 repeated the matrix with a corrected revert. - A shows the trigger reproduces `did not open again` every time without the wait. - B flips red when only the helper's `Closed` wait is removed, and green again when it's restored. - C and D show the original race is rare. The real test passes in these legs, consistent with a single CI failure. I found no duplicate open or merged PR for this test or mechanism. ### Issues Fixed No issue filed. Found during SR2 candidate validation (#40116). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…l test reopens it (#40359) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). This is a test-only fix for the SR2 candidate validation in #40116, so it targets `candidate/11.0.1xx-sr2`, like the earlier candidate test fixes. ### Description of Change On candidate head `888db82bd5`, Windows device-test build 1686840 failed `ShellTests.TabWithSeveralShellContentsOpensFromTabBarOverflowMenu` (run 47076696, result 102198) at `ShellTabBarTests.Windows.cs:276` with `The overflow menu did not open again`. That test came in with #39412. **Root cause (test timing):** 1. The test clicks "Tab 7", and later "Sub B", in the tab bar overflow menu. Both tabs select on invoke, so the click hides the menu. 2. Hiding only closes the flyout's popup. WinUI keeps the `MenuFlyout` registered as open until its presenter unloads and raises `Closed`. Until then, `ShowAt` on the same flyout and target is ignored. 3. The test waits for navigation and then reopens the menu with `ShowAt`. Navigation is usually observed after the presenter has unloaded, but not always. When it's observed first, `ShowAt` is a no-op and `IsOpen` never becomes true. **Fix:** a new helper, `ClickOverflowMenuItemThatClosesMenu`, waits for `Flyout.Closed` after the two clicks that close the menu, before the menu is reopened. The diff is +21/−2 in `ShellTabBarTests.Windows.cs` only. Assertions, messages, deadlines and test cases are unchanged. No product code changes. **Causal evidence (Helix `Windows.11.Amd64.Client.Open`, Controls device tests, Shell category):** A temporary, uncommitted probe (`OverflowProbe*`, never committed) runs alongside the real tests: - **A (trigger):** clicks "Sub B" and calls `ShowAt` at once, as when navigation is observed before the presenter unloads. - **B (trigger + fix):** the same, but clicks with this PR's helper. - **C (real test):** `TabWithSeveralShellContentsOpensFromTabBarOverflowMenu`, 20 iterations. - **D (trigger removed):** the original order, which waits for navigation before reopening. | Leg | Helper wait present | A trigger | B trigger + helper | C real test | D no trigger | Real overflow tests | | --- | --- | --- | --- | --- | --- | --- | | fix | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | reverted (r1) | no | — | — | — | — | not run: the probe edit failed to build (CS0219) | | reverted (r2) | no | red 10/10 | **red 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r1) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r2) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | Each leg's payload records `variant.json` with `fixWaitPresent` and SHA-256s of the test and probe files. - Helix jobs: `509c2c0a-230d-4310-9524-199f5d1858e9` (r1) and `c16a74fd-9a5b-4979-b7a9-22d0519b5755` (r2). - r1's reverted leg failed to compile, so r2 repeated the matrix with a corrected revert. - A shows the trigger reproduces `did not open again` every time without the wait. - B flips red when only the helper's `Closed` wait is removed, and green again when it's restored. - C and D show the original race is rare. The real test passes in these legs, consistent with a single CI failure. I found no duplicate open or merged PR for this test or mechanism. ### Issues Fixed No issue filed. Found during SR2 candidate validation (#40116). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…l test reopens it (#40359) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). This is a test-only fix for the SR2 candidate validation in #40116, so it targets `candidate/11.0.1xx-sr2`, like the earlier candidate test fixes. ### Description of Change On candidate head `888db82bd5`, Windows device-test build 1686840 failed `ShellTests.TabWithSeveralShellContentsOpensFromTabBarOverflowMenu` (run 47076696, result 102198) at `ShellTabBarTests.Windows.cs:276` with `The overflow menu did not open again`. That test came in with #39412. **Root cause (test timing):** 1. The test clicks "Tab 7", and later "Sub B", in the tab bar overflow menu. Both tabs select on invoke, so the click hides the menu. 2. Hiding only closes the flyout's popup. WinUI keeps the `MenuFlyout` registered as open until its presenter unloads and raises `Closed`. Until then, `ShowAt` on the same flyout and target is ignored. 3. The test waits for navigation and then reopens the menu with `ShowAt`. Navigation is usually observed after the presenter has unloaded, but not always. When it's observed first, `ShowAt` is a no-op and `IsOpen` never becomes true. **Fix:** a new helper, `ClickOverflowMenuItemThatClosesMenu`, waits for `Flyout.Closed` after the two clicks that close the menu, before the menu is reopened. The diff is +21/−2 in `ShellTabBarTests.Windows.cs` only. Assertions, messages, deadlines and test cases are unchanged. No product code changes. **Causal evidence (Helix `Windows.11.Amd64.Client.Open`, Controls device tests, Shell category):** A temporary, uncommitted probe (`OverflowProbe*`, never committed) runs alongside the real tests: - **A (trigger):** clicks "Sub B" and calls `ShowAt` at once, as when navigation is observed before the presenter unloads. - **B (trigger + fix):** the same, but clicks with this PR's helper. - **C (real test):** `TabWithSeveralShellContentsOpensFromTabBarOverflowMenu`, 20 iterations. - **D (trigger removed):** the original order, which waits for navigation before reopening. | Leg | Helper wait present | A trigger | B trigger + helper | C real test | D no trigger | Real overflow tests | | --- | --- | --- | --- | --- | --- | --- | | fix | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | reverted (r1) | no | — | — | — | — | not run: the probe edit failed to build (CS0219) | | reverted (r2) | no | red 10/10 | **red 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r1) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r2) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | Each leg's payload records `variant.json` with `fixWaitPresent` and SHA-256s of the test and probe files. - Helix jobs: `509c2c0a-230d-4310-9524-199f5d1858e9` (r1) and `c16a74fd-9a5b-4979-b7a9-22d0519b5755` (r2). - r1's reverted leg failed to compile, so r2 repeated the matrix with a corrected revert. - A shows the trigger reproduces `did not open again` every time without the wait. - B flips red when only the helper's `Closed` wait is removed, and green again when it's restored. - C and D show the original race is rare. The real test passes in these legs, consistent with a single CI failure. I found no duplicate open or merged PR for this test or mechanism. ### Issues Fixed No issue filed. Found during SR2 candidate validation (#40116). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…l test reopens it (#40359) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). This is a test-only fix for the SR2 candidate validation in #40116, so it targets `candidate/11.0.1xx-sr2`, like the earlier candidate test fixes. ### Description of Change On candidate head `888db82bd5`, Windows device-test build 1686840 failed `ShellTests.TabWithSeveralShellContentsOpensFromTabBarOverflowMenu` (run 47076696, result 102198) at `ShellTabBarTests.Windows.cs:276` with `The overflow menu did not open again`. That test came in with #39412. **Root cause (test timing):** 1. The test clicks "Tab 7", and later "Sub B", in the tab bar overflow menu. Both tabs select on invoke, so the click hides the menu. 2. Hiding only closes the flyout's popup. WinUI keeps the `MenuFlyout` registered as open until its presenter unloads and raises `Closed`. Until then, `ShowAt` on the same flyout and target is ignored. 3. The test waits for navigation and then reopens the menu with `ShowAt`. Navigation is usually observed after the presenter has unloaded, but not always. When it's observed first, `ShowAt` is a no-op and `IsOpen` never becomes true. **Fix:** a new helper, `ClickOverflowMenuItemThatClosesMenu`, waits for `Flyout.Closed` after the two clicks that close the menu, before the menu is reopened. The diff is +21/−2 in `ShellTabBarTests.Windows.cs` only. Assertions, messages, deadlines and test cases are unchanged. No product code changes. **Causal evidence (Helix `Windows.11.Amd64.Client.Open`, Controls device tests, Shell category):** A temporary, uncommitted probe (`OverflowProbe*`, never committed) runs alongside the real tests: - **A (trigger):** clicks "Sub B" and calls `ShowAt` at once, as when navigation is observed before the presenter unloads. - **B (trigger + fix):** the same, but clicks with this PR's helper. - **C (real test):** `TabWithSeveralShellContentsOpensFromTabBarOverflowMenu`, 20 iterations. - **D (trigger removed):** the original order, which waits for navigation before reopening. | Leg | Helper wait present | A trigger | B trigger + helper | C real test | D no trigger | Real overflow tests | | --- | --- | --- | --- | --- | --- | --- | | fix | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | reverted (r1) | no | — | — | — | — | not run: the probe edit failed to build (CS0219) | | reverted (r2) | no | red 10/10 | **red 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r1) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r2) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | Each leg's payload records `variant.json` with `fixWaitPresent` and SHA-256s of the test and probe files. - Helix jobs: `509c2c0a-230d-4310-9524-199f5d1858e9` (r1) and `c16a74fd-9a5b-4979-b7a9-22d0519b5755` (r2). - r1's reverted leg failed to compile, so r2 repeated the matrix with a corrected revert. - A shows the trigger reproduces `did not open again` every time without the wait. - B flips red when only the helper's `Closed` wait is removed, and green again when it's restored. - C and D show the original race is rare. The real test passes in these legs, consistent with a single CI failure. I found no duplicate open or merged PR for this test or mechanism. ### Issues Fixed No issue filed. Found during SR2 candidate validation (#40116). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…l test reopens it (#40359) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). This is a test-only fix for the SR2 candidate validation in #40116, so it targets `candidate/11.0.1xx-sr2`, like the earlier candidate test fixes. ### Description of Change On candidate head `888db82bd5`, Windows device-test build 1686840 failed `ShellTests.TabWithSeveralShellContentsOpensFromTabBarOverflowMenu` (run 47076696, result 102198) at `ShellTabBarTests.Windows.cs:276` with `The overflow menu did not open again`. That test came in with #39412. **Root cause (test timing):** 1. The test clicks "Tab 7", and later "Sub B", in the tab bar overflow menu. Both tabs select on invoke, so the click hides the menu. 2. Hiding only closes the flyout's popup. WinUI keeps the `MenuFlyout` registered as open until its presenter unloads and raises `Closed`. Until then, `ShowAt` on the same flyout and target is ignored. 3. The test waits for navigation and then reopens the menu with `ShowAt`. Navigation is usually observed after the presenter has unloaded, but not always. When it's observed first, `ShowAt` is a no-op and `IsOpen` never becomes true. **Fix:** a new helper, `ClickOverflowMenuItemThatClosesMenu`, waits for `Flyout.Closed` after the two clicks that close the menu, before the menu is reopened. The diff is +21/−2 in `ShellTabBarTests.Windows.cs` only. Assertions, messages, deadlines and test cases are unchanged. No product code changes. **Causal evidence (Helix `Windows.11.Amd64.Client.Open`, Controls device tests, Shell category):** A temporary, uncommitted probe (`OverflowProbe*`, never committed) runs alongside the real tests: - **A (trigger):** clicks "Sub B" and calls `ShowAt` at once, as when navigation is observed before the presenter unloads. - **B (trigger + fix):** the same, but clicks with this PR's helper. - **C (real test):** `TabWithSeveralShellContentsOpensFromTabBarOverflowMenu`, 20 iterations. - **D (trigger removed):** the original order, which waits for navigation before reopening. | Leg | Helper wait present | A trigger | B trigger + helper | C real test | D no trigger | Real overflow tests | | --- | --- | --- | --- | --- | --- | --- | | fix | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | reverted (r1) | no | — | — | — | — | not run: the probe edit failed to build (CS0219) | | reverted (r2) | no | red 10/10 | **red 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r1) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | | restored (r2) | yes | red 10/10 | **green 10/10** | green 20/20 | green 10/10 | 4/4 pass | Each leg's payload records `variant.json` with `fixWaitPresent` and SHA-256s of the test and probe files. - Helix jobs: `509c2c0a-230d-4310-9524-199f5d1858e9` (r1) and `c16a74fd-9a5b-4979-b7a9-22d0519b5755` (r2). - r1's reverted leg failed to compile, so r2 repeated the matrix with a corrected revert. - A shows the trigger reproduces `did not open again` every time without the wait. - B flips red when only the helper's `Closed` wait is removed, and green again when it's restored. - C and D show the original race is rare. The real test passes in these legs, consistent with a single CI failure. I found no duplicate open or merged PR for this test or mechanism. ### Issues Fixed No issue filed. Found during SR2 candidate validation (#40116). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
On Windows, clicking a Shell tab with more than one ShellContent in the overflow menu of the top tab bar (the ... button) crashed the app with E_BOUNDS (invalid vector subscript).
The crash is inside WinUI NavigationView. From what I see in the WinUI code, in Top mode it cant find the container of a data bound item that sits in the overflow menu, so the clicked item never gets IsSelected, only IsChildSelected, and when it expands right after the click WinUI reads past the end of the selected index path. MAUI always fills the tab bar through MenuItemsSource, so every tab with sub tabs runs into it. A plain WinUI NavigationView with MenuItemsSource and a similar item template crashes the same way.
Fixing up the selection state after the click only helps for the first click, other overflow bugs in WinUI show up after that (for example picking a sub tab from the overflow menu and closing the menu later crashes again). So now ShellItemHandler sets SelectsOnInvoked to false on overflow menu containers that have sub tabs, and clears it when the container leaves the overflow menu. MapMenuItems also updates the items that are already in the overflow menu, because a tab can get or lose sub tabs while it sits there. A click on such a tab just expands it, picking one of its sub tabs navigates like before and WinUI moves the tab into the bar. Tabs in the bar work like before.
There are four device tests. The first one opens a tab with one ShellContent from the overflow menu, then clicks the tab with sub tabs, picks Sub B and checks the navigation. The second one adds and removes a sub tab of a tab that already sits in the open overflow menu and checks the item follows. The third one moves a tab with sub tabs from the overflow menu back into the bar and checks it gets selected there like before. The fourth one applies the NavigationView template again and checks the new overflow menu behaves the same. Without the fix the click makes WinUI kill the whole test app, so the tests check SelectsOnInvoked before clicking to fail in a normal way.
Issues Fixed
Fixes #37985