Skip to content

Fix Shell Flyout item ordering when CurrentItem is set in XAML - #39541

Merged
kubaflo merged 3 commits into
dotnet:inflight/candidatefrom
SubhikshaSf4851:Fix-29272
Oct 26, 2026
Merged

kubaflo merged 3 commits into
dotnet:inflight/candidatefrom
SubhikshaSf4851:Fix-29272

Conversation

@SubhikshaSf4851

Copy link
Copy Markdown
Contributor

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!

This pull request improves how the order of ShellItem elements is maintained in the collection, especially during XAML loading, and adds a test to ensure that setting the CurrentItem does not unintentionally affect the order of implicit shell contents.

Description of Change

Shell item order handling:

  • Added a new method RestoreDeclarationOrder in ShellElementCollection.cs to remove and re-add an item, ensuring its position reflects the original declaration order without triggering unwanted collection change events.
  • Updated ShellItemCollection.cs to use RestoreDeclarationOrder when setting the CurrentItem for implicit items during XAML loading, preserving the intended order.

Testing:

  • Added a unit test CurrentItemDoesNotChangeTheFlyoutOrderOfImplicitShellContents in ShellFlyoutItemGroupTests.cs to verify that setting the CurrentItem does not change the order of implicit shell contents in the flyout.

Issues Fixed

Fixes #29272

  • Windows
  • Android
  • iOS
  • Mac
Before Issue Fix After Issue Fix
BeforeFix29272 AfterFix29272

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39541

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39541"

@azure-pipelines

This comment has been minimized.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Oct 22, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Oct 22, 2026
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman added the area-controls-shell Shell Navigation, Routes, Tabs, Flyout label Oct 22, 2026
@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 22, 2026
@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

This comment has been minimized.

@SubhikshaSf4851 SubhikshaSf4851 changed the title [WIP]Fix Shell Flyout item ordering when CurrentItem is set in XAML Fix Shell Flyout item ordering when CurrentItem is set in XAML Oct 23, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review October 26, 2026 06:53
Copilot AI balanced review requested due to automatic review settings October 26, 2026 06:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The batched reorder leaves the cached flyout order unchanged in the reported two-item scenario, so the intended fix remains incomplete.

1 open issue
What changed in this PR

This PR addresses #29272 by restoring declaration order for implicit Shell items when CurrentItem is assigned during XAML loading.

Changes:

  • Adds a remove-and-reinsert helper that batches collection notifications.
  • Uses the helper when adding an implicit item already in the collection.
  • Adds a regression test checking item order and preservation of the selected content.
File Description
src/​Controls/​tests/​Core.UnitTests/​ShellFlyoutItemGroupTests.cs Tests implicit item ordering after assigning CurrentItem.
src/​Controls/​src/​Core/​Shell/​ShellItemCollection.cs Restores order when an implicit item is already present.
src/​Controls/​src/​Core/​Shell/​ShellElementCollection.cs Adds the batched reordering helper.

Review effort: Balanced

return;
}

PauseCollectionChanged();
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added s/agent-review-in-progress AI review is currently running for this PR and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 26, 2026
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Expert Review — 1 finding

Reviewed commit 5f5e676.

See inline comments for details.

return;
}

PauseCollectionChanged();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[major] Logic and Correctness Verification - The original two-content reproduction still leaves the displayed flyout in the wrong order. Set CurrentItem to the second ShellContent before adding the first and then the second content, as in the new test: adding the first content caches the flyout as [second, first]. Pausing the visible notifications means both replayed notifications observe the final [first, second] collection. ShellFlyoutItemsManager.UpdateFlyoutGroupings compares group sizes, but its element-comparison loop uses j > topLevelNew.Count, so it never detects this same-size reorder and never synchronizes FlyoutItems. Shell.Items is corrected while the displayed flyout remains [second, first]. Correct the flyout reorder detection alongside this batching and extend the regression test to assert the actual flyout order through shell.GenerateTestFlyoutItems(), not only Shell.Items and selection.

@MauiBot

MauiBot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@SubhikshaSf4851 — existing-test verification for commit 5f5e6760.

Result PASSED Platform Android Commit 5f5e6760


🧪 Gate analysis — click to expand

✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence.

🧪 Unit tests
Test group Without fix With fix
ShellFlyoutItemGroupTests ✅ Failed as expected (102s) ✅ Passed (87s)
Execution log excerpts

Without fix ShellFlyoutItemGroupTests

     at Microsoft.Maui.Controls.Core.UnitTests.ShellFlyoutItemGroupTests.CurrentItemDoesNotChangeTheFlyoutOrderOfImplicitShellContents() in /_/src/Controls/tests/Core.UnitTests/ShellFlyoutItemGroupTests.cs:line 316
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

With fix ShellFlyoutItemGroupTests

Passed MenuItemGeneratesForShellSection [120 ms]
  Passed FlyoutItemsBasicSyncTest [10 ms]
  Passed FlyoutItemVisibleWorksForMenuItemsAddedAsShellItem [4 ms]
  Passed FlyoutCreatesCorrectNumberOfGroupsForAsMultipleItems [3 ms]
  Passed FlyoutCreatesCorrectNumberOfGroupsForNestedAsMultipleItems [< 1 ms]
  Passed CurrentItemDoesNotChangeTheFlyoutOrderOfImplicitShellContents [5 ms]
  Passed MenuItemGeneratesForShellContent [< 1 ms]
  Passed FlyoutItemsGroupTestWithRemove [8 ms]
  Passed FlyoutItemsGroupTest [1 ms]
[xUnit.net 00:00:01.79]   Finished:    Microsoft.Maui.Controls.Core.UnitTests
  Passed FlyoutItemVisibleWorksForMenuItemsAddedAsShellContent [1 ms]
  Passed FlyoutItemVisibleWorksForMenuItemsTabAsMultipleItems [1 ms]
  Passed FlyoutItemVisibleWorksForMenuItemsAddedAsTab [1 ms]
  Passed FlyoutCreatesCorrectNumberOfGroupsForAsSingleItem [1 ms]
  Passed FlyoutItemNotVisibleWhenShellContentSetToNotVisible [1 ms]
  Passed FlyoutItemsGroupTestMoveGroup [2 ms]
  Passed FlyoutItemVisibleWorksForMenuItemsFlyoutItemAsMultipleItems [1 ms]
  Passed ReturnTheSameGroupingInstanceIfStructureHasntChanged [1 ms]
Test Run Successful.
Total tests: 17
     Passed: 17
 Total time: 2.2953 Seconds

PR head: 5f5e6760.

Without-fix baseline: ab49b07d.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@SubhikshaSf4851 — test-failure analysis for commit 5f5e676.

Scope CI failures Commit 5f5e676


🧪 CI Analysis — click to expand
📊 maui-pr

No failures found.


🧪 maui-pr-devicetests

🧪 maui-pr-uitests

🧭 Follow-up — actions and refresh

Next action: Inspect Android crash/retention diagnostics and MacCatalyst timeout; confirm Entry baseline runtime and restore canceled Layout coverage.

Maintainers: comment /review tests to refresh this report.

@kubaflo
kubaflo changed the base branch from main to inflight/candidate October 26, 2026 21:55
@kubaflo
kubaflo merged commit 13382d2 into dotnet:inflight/candidate Oct 26, 2026
194 of 214 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR13 milestone Oct 26, 2026
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
<!-- 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!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->
This pull request improves how the order of `ShellItem` elements is
maintained in the collection, especially during XAML loading, and adds a
test to ensure that setting the `CurrentItem` does not unintentionally
affect the order of implicit shell contents.
### Description of Change
Shell item order handling:

* Added a new method `RestoreDeclarationOrder` in
`ShellElementCollection.cs` to remove and re-add an item, ensuring its
position reflects the original declaration order without triggering
unwanted collection change events.
* Updated `ShellItemCollection.cs` to use `RestoreDeclarationOrder` when
setting the `CurrentItem` for implicit items during XAML loading,
preserving the intended order.

Testing:

* Added a unit test
`CurrentItemDoesNotChangeTheFlyoutOrderOfImplicitShellContents` in
`ShellFlyoutItemGroupTests.cs` to verify that setting the `CurrentItem`
does not change the order of implicit shell contents in the flyout.


<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #29272 

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="441" height="920" alt="BeforeFix29272"
src="https://github.com/user-attachments/assets/aab4fc64-ab21-4826-a7bf-6543f80ec1b1"
/> | <img width="443" height="923" alt="AfterFix29272"
src="https://github.com/user-attachments/assets/0cc628cc-5cdd-46e3-9379-a13123e246e3"
/> |
<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 5f5e6760 Deployed Oct 22, 2026 by SubhikshaSf4851 via conclusion #2445
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-shell Shell Navigation, Routes, Tabs, Flyout community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting Shell.CurrentItem reorders items in flyout menu

5 participants