Skip to content

fix(NavigationView): Don't root menu items from the SplitView - #25968

Merged
Xiaoy312 merged 4 commits into
masterfrom
dev/xygu/20261103/navview-splitview-leak
Nov 3, 2026
Merged

Xiaoy312 merged 4 commits into
masterfrom
dev/xygu/20261103/navview-splitview-leak

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25970

PR Type:

🐞 Bugfix

What changed? 🚀

A NavigationViewItem, NavigationViewItemHeader or NavigationViewItemSeparator removed from a NavigationView stayed in memory for as long as the NavigationView lived. Each item listens to the NavigationView's SplitView (IsPaneOpen, DisplayMode, and CompactPaneLength for items) through the public RegisterPropertyChangedCallback, which the SplitView holds strongly until it's unregistered. Items only unregister when their template is re-applied, and headers and separators never do. The retention path is NavigationView → SplitView → _propertyChangedTokens → callback → item.

These callbacks now go through the internal RegisterDisposablePropertyChangedCallback, which holds them weakly and ties them to the item's lifetime. WinUI's NavigationViewItem.cpp, NavigationViewItemHeader.cpp and NavigationViewItemSeparator.cpp register { this, &T::OnSplitViewPropertyChanged } handlers that don't own the item. This is the same fix as #25948 (AnimatedIcon), applied to the other control in Uno.UI that hit this pattern.

The /winui-port skill now maps C++ revokers accordingly:

  • revoke() becomes .Disposable = null, never .Dispose(). A disposed SerialDisposable disposes every later value as soon as it's assigned.
  • A RegisterPropertyChanged on an object that can outlive the control becomes RegisterDisposablePropertyChangedCallback, which is preferred over unsubscribing on Unloaded.

New runtime tests in Given_NavigationView:

  • When_MenuItem_Removed_Then_Not_Rooted_By_SplitView (Item, Header, Separator), Uno-only ([PlatformCondition(Exclude, NativeWinUI)]). The test also removes a second item: ItemsRepeater keeps the last cleared element in its cached ElementClearing args, as WinUI does.
  • When_SplitView_CompactPaneLength_Changes_Then_MenuItem_Follows: the weak subscription still delivers after a GC. It also runs on WinAppSDK.

Locally on Skia Win32 (SamplesApp net10.0-desktop):

  • Without the fix, the leak test fails for all 3 rows. A heap dump of the failure shows the removed item held through the SplitView's callback registrations.
  • With the fix, all 3 rows pass.
  • Given_NavigationView (both classes) and the MUX NavigationViewTests: 34 run, 0 failed (12 skipped by existing [Ignore]).

The WinAppSDK head was not run locally.

PR Checklist ✅

🤖 Generated with Claude Code

A NavigationViewItem, header or separator removed from MenuItems must
not stay alive through its subscription to the NavigationView's
SplitView while the NavigationView lives on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Xiaoy312 and others added 3 commits November 3, 2026 02:52
NavigationViewItem, NavigationViewItemHeader and
NavigationViewItemSeparator listen to the NavigationView's SplitView
through the public token API, which the SplitView holds strongly, so
an item removed from a long-lived NavigationView stayed alive with it
(the header and separator never revoke at all). WinUI's handlers don't
own the item; register weakly to match.

Fixes #25970

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A C++ revoke() maps to `.Disposable = null`: Dispose() on a reused
SerialDisposable revokes every later subscription on assignment. A
RegisterPropertyChanged on a source that can outlive the control maps
to RegisterDisposablePropertyChangedCallback, since the public token
API holds the callback strongly where the C++ handler doesn't own it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The weak SplitView subscription must keep delivering while the item is
alive, across a GC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261103/navview-splitview-leak branch from b8bf243 to 11d1330 Compare November 3, 2026 07:52
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243116 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AppBarToggleButtonTest.png
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowFeatures.png
    • AppXamlDefinedResources.png-dark
    • Attributed_text_Simple.png-dark
    • AuthenticationBroker_Demo.png-dark
    • AutoBorderStretchwithrightmargin.png-dark
    • AutomationProperties_Name.png-dark
    • AutomationProperties_Name.png
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • BadgeNotificationTests.png-dark
    • BadgeNotificationTests.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BezierSegment.png-dark
    • BezierSegment.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AppBarButtonTest.png-dark
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewMode.png-dark
    • Application_DispatcherShutdownMode.png
    • AppWindowTitleBar Properties.png-dark
    • ArcSegment.png
    • Attributed_text_Supserscript.png
    • AutoBorderStretchwithrightmargin.png
    • AutoBorderStretchwithtopmargin.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BackGesture.png-dark
    • BackGesture.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • BeginTime_MultipleAnimations.png-dark
    • BeginTime_MultipleAnimations.png
    • BitmapIcon_Generic.png-dark
    • BitmapIcon_Generic.png

@Xiaoy312
Xiaoy312 enabled auto-merge November 3, 2026 16:41
@Xiaoy312
Xiaoy312 merged commit 26bfce2 into master Nov 3, 2026
54 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20261103/navview-splitview-leak branch November 3, 2026 17:21
@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NavigationView: removed menu items are never collected while the NavigationView lives

4 participants