Repository navigation
fix(NavigationView): Don't root menu items from the SplitView - #25968
Merged
Merged
Conversation
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]>
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
force-pushed
the
dev/xygu/20261103/navview-splitview-leak
branch
from
November 3, 2026 07:52
b8bf243 to
11d1330
Compare
Contributor
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-25968/docs/index.html |
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Contributor
|
The build 243116 found UI Test snapshots differences: Details
|
ramezgerges
approved these changes
Nov 3, 2026
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. |
This was referenced Nov 3, 2026
4 of 5 tasks
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.
GitHub Issue: closes #25970
PR Type:
🐞 Bugfix
What changed? 🚀
A
NavigationViewItem,NavigationViewItemHeaderorNavigationViewItemSeparatorremoved from a NavigationView stayed in memory for as long as the NavigationView lived. Each item listens to the NavigationView'sSplitView(IsPaneOpen,DisplayMode, andCompactPaneLengthfor items) through the publicRegisterPropertyChangedCallback, 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 isNavigationView → 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'sNavigationViewItem.cpp,NavigationViewItemHeader.cppandNavigationViewItemSeparator.cppregister{ 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-portskill now maps C++ revokers accordingly:revoke()becomes.Disposable = null, never.Dispose(). A disposedSerialDisposabledisposes every later value as soon as it's assigned.RegisterPropertyChangedon an object that can outlive the control becomesRegisterDisposablePropertyChangedCallback, which is preferred over unsubscribing onUnloaded.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:ItemsRepeaterkeeps the last cleared element in its cachedElementClearingargs, 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 (
SamplesAppnet10.0-desktop):Given_NavigationView(both classes) and the MUXNavigationViewTests: 34 run, 0 failed (12 skipped by existing[Ignore]).The WinAppSDK head was not run locally.
PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code