fix(navigationview): reconcile menu items in place to preserve expansion#454
Merged
codemonkeychris merged 2 commits intoMay 29, 2026
Merged
Conversation
NavigationView cleared and rebuilt every menu item whenever the MenuItems array reference changed — which is effectively every render, since consumers build a fresh array each Render(). Per-item expansion lives only on the live NavigationViewItem (NavigationViewItemData has no IsExpanded), so each re-render snapped expanded hierarchical categories shut, and selecting a child collapsed its parent. Reconcile menu items in place instead: match NavigationViewItems by Tag, update only changed Content/Icon, recurse into children, and reuse the container so IsExpanded survives the re-render. A fast path skips all detaching when the structure is unchanged. Mirrored into the V1 NavigationViewDescriptor so V1 ON behaves identically to V1 OFF, and mount-time selection now recurses so a child tag selects correctly. Adds a NavigationView E2E guard (NavigationView_Hierarchical fixture + NavigationViewInteractionTests) that fails on the pre-fix build and passes after, plus a TreeView E2E guard exercising the Gallery's basic text-tree path. Compact (icon-only) pane interaction is deferred to a follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes hierarchical NavigationView updates so menu item containers are reconciled in place instead of being cleared and recreated, preserving runtime expansion and selection state across re-renders.
Changes:
- Adds in-place
NavigationViewmenu reconciliation in both legacy and V1 descriptor paths. - Updates mount-time selection to find nested items by tag.
- Adds E2E fixtures/tests for hierarchical
NavigationViewand TreeView interaction regression coverage.
Show a summary per file
| File | Description |
|---|---|
src/Reactor/Core/Reconciler.Update.cs |
Replaces clear-and-rebuild menu updates with Tag-based in-place reconciliation. |
src/Reactor/Core/Reconciler.Mount.cs |
Recursively resolves initial SelectedTag for nested NavigationView items. |
src/Reactor/Core/V1Protocol/Descriptor/Descriptors/NavigationViewDescriptor.cs |
Mirrors in-place menu reconciliation for V1 NavigationView behavior. |
tests/Reactor.AppTests/Tests/NavigationViewInteractionTests.cs |
Adds E2E coverage for preserving hierarchical NavigationView expansion after selection re-renders. |
tests/Reactor.AppTests/Tests/TreeViewInteractionTests.cs |
Adds TreeView interaction regression tests. |
tests/Reactor.AppTests.Host/Fixtures/NavigationViewE2EFixtures.cs |
Adds the hierarchical NavigationView host fixture. |
tests/Reactor.AppTests.Host/Fixtures/TreeViewE2EFixtures.cs |
Adds the basic text TreeView host fixture. |
tests/Reactor.AppTests.Host/FixtureRegistry.cs |
Registers the new E2E fixtures. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 8/8 changed files
- Comments generated: 2
Comment on lines
+1875
to
+1878
| var reusable = new global::System.Collections.Generic.Dictionary<string, WinUI.NavigationViewItem>(); | ||
| foreach (var item in live) | ||
| if (item is WinUI.NavigationViewItem nvi && nvi.Tag is string tag) | ||
| reusable[tag] = nvi; |
Comment on lines
+177
to
+180
| var reusable = new global::System.Collections.Generic.Dictionary<string, WinUI.NavigationViewItem>(); | ||
| foreach (var item in live) | ||
| if (item is WinUI.NavigationViewItem nvi && nvi.Tag is string tag) | ||
| reusable[tag] = nvi; |
…ack) Address PR #454 review: - Slow-path rebuild now consumes the reuse map entry (Dictionary.Remove) when a container is reused, so duplicate sibling keys (duplicate Tags, or duplicate Content when no Tag is set) fall through to a freshly created container instead of adding the same WinUI item to the collection twice. - Make the snapshot loops' filtering explicit with .Where()/.OfType(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Addressed the review feedback in dd7ce54:
Verified: NavigationView self-tests (incl. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NavigationViewwith hierarchical menu items mis-behaved on every interaction:Root cause
UpdateNavigationView(and the V1NavigationViewDescriptor) didMenuItems.Clear()+ full rebuild whenever theMenuItemsarray referencechanged. Consumers typically build a fresh
MenuItemsarray eachRender()(e.g. via LINQ), so the
ReferenceEqualsguard never held and the rebuildfired on essentially every re-render.
Per-item expansion lives only on the live
NavigationViewItem— there is noIsExpandedonNavigationViewItemData— so recreating the containers resetexpansion to
falseevery time. Because selecting an item triggers are-render, the just-expanded category (or a child's parent) snapped shut on the
same click.
Fix
Reconcile menu items in place instead of clear-and-rebuild:
NavigationViewItems byTag;Content/Icon;IsExpanded(and selection) survive there-render.
A fast path skips all detaching when the item structure is unchanged (the
common case). Mirrored into the V1
NavigationViewDescriptorso V1 ON behavesidentically to V1 OFF. Mount-time selection now recurses so a child tag selects
correctly.
Tests
NavigationView_Hierarchicalhost fixture +NavigationViewInteractionTests. Verified to fail on the pre-fix build(expanded category collapses after the selection re-render) and pass after.
Desc_NavigationView_MountUpdatecoverage, pass (0 failures).Out of scope
Compact (icon-only) pane interaction is deferred to a follow-up.