Repository navigation
Conversation
morning4coffe-dev
left a comment
There was a problem hiding this comment.
The ancestor-identity approach addresses the stale-index-path problem, but the new early ancestor refresh creates a reentrancy boundary that the outer selection callback does not protect.
I exercised the exact selected methods with minimal container/selection-model stand-ins. When clearing the model selection resets an old ancestor's IsChildSelected, a synchronous property callback can select a fallback item. UpdateIsChildSelected notices the model change and returns, but OnSelectionModelSelectionChanged then continues with its previously captured null selectedItem and clears that fallback. The trace is ancestor callback selects Fallback -> SelectedItem=Fallback -> SelectedItem=null. A diagnostic post-refresh selection guard preserves the fallback.
The concrete SelectionModel raises SelectionChanged synchronously, and IsChildSelected is a public dependency property, so this is a reachable callback boundary rather than only a list-enumerator concern. Please protect the caller against the superseding selection and add a runtime case covering that fallback/reselection path.
WinUI source note: the pinned Microsoft implementation (d0c6705ec46d, controls/dev/NavigationView/NavigationView.cpp) still uses the previous-index-path approach and has no new ancestor refresh before this callback's ignore/selection checks. This is an intentional Uno-specific algorithm change, not a literal port; native behavioral parity should remain explicitly pending as the PR already states.
Evidence scope: exact-method execution with stand-ins and source tracing, not a full XAML/native WinUI runtime reproduction.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Re-reviewed 415d7c743ccc999cc62cd2cfc9b8eab090340d9d against my previous e8f70b7 review and the complete three-file feature delta. Revalidating the captured item after the synchronous ancestor callbacks fixes the reported ownership boundary: the outer callback no longer applies its stale selection over the replacement, and the selected index is read after that revalidation.
I independently built the source SamplesApp in Release/net11.0-desktop and ran all six ancestor-selection cases twice on the real Skia Win32 control tree; all passed without skips or retries. A reviewer-only copy removing just the five-line outer guard made both root/nested fallback rows fail at the retained-selection assertion. Recompiling the original reviewed source restored all six passes. The provider-presence assertion and explicit compact-pane reopening were also reviewed; this does not claim coverage of detached-child selection while the pane remains closed.
Local builds used UnoFastDevBuild, not strict analyzer coverage; initial project evaluation still emitted the existing MSB4011 duplicate-import warnings. Native WinUI behavioral parity and the full upstream matrix remain pending. I requested the missing ordinary CI, and build 233542 is now running with this exact head verified as a merge parent. This is not a claim that CI has passed.
My reported reentrancy issue is fixed in this head. Approving the revision; normal independent-review and CI merge gates still apply.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24509/wasm-skia-net9/index.html |
|
The build 233542 found UI Test snapshots differences: Details
|
|
Tick the box to add this pull request to the merge queue (same as
|
|
CI follow-up for The initial iOS shard's only listed failure was The screenshot notice also needs its comparison scope kept clear: the comparer log used builds 211834 (May 10) and 212586 (May 14) as baselines, not the PR's exact base. Its 2,310 Windows differences therefore are not an isolated PR-versus-base regression count; this does not establish pixel parity either. Update: build 233542 has now completed successfully for this exact head, and the required checks are passing. Keeping the source approval unchanged; independent approval is still required before merging. No check or queue bypass has been applied. |
|
@YoungSx This control is fully ported from WinUI, so Uno-specific changes should only be done in case there is an upstream bug in the WinUI control itself (and it should then also be reported on WinUI repository). Can you please check whether this issue is also happening on WinAppSDK? If not, then we must have some other issue in our ported sources. |
|
@MartinZikmund @YoungSx I checked this against native Windows App SDK 2.4.0/.NET 10, with no Uno control implementation loaded. The original stale-ancestor problem does reproduce upstream. I compiled the unchanged six-case fixture from
That is four repeatable original-bug scenarios after their initial selection/ancestor positive controls. The separately inspected upstream source at 439bda9 still resolves cleanup through the previous index path; I am not claiming that checkout is the exact source commit of the packaged runtime. This provides native repro evidence for an upstream report. Please file/link that report as requested before settling the Uno-specific implementation. It is not a claim of complete algorithm parity or mobile coverage, and I have not opened an upstream issue or bypassed the remaining merge gates. |
|
@MartinZikmund @morning4coffe-dev Thanks for investigating and verifying this against native Windows App SDK! As requested, I have filed the upstream issue in the WinUI repository with the repro details: Given that this is confirmed to be an upstream WinUI defect and the Uno-specific fix plus regression tests in this PR have been verified and approved, could you please advise if any further steps are needed, or proceed with the independent review for merging? Thank you! |
|
@MartinZikmund @morning4coffe-dev Friendly follow-up. Since we have now confirmed the stale-ancestor defect reproduces on native Windows App SDK 2.4.0 and filed the upstream WinUI issue (microsoft/microsoft-ui-xaml#11927), would you be open to merging this Uno-side fix as an interim workaround, gated so it can be cleanly reverted once WinUI ships the upstream fix? The change is scoped to refreshing NavigationView ancestor selection and is covered by the new root-level and nested fallback regression tests (the two added cases fail when the fix is removed). It has been APPROVED and the six-case Skia/X11 fixture passed two consecutive rounds with no retries or skips. Happy to add a code comment linking #11927 with a removal condition, or adjust the gating if that helps. Thanks for your time! |
|
@YoungSx one last change please - it is our convention that when a part of the code is uno specific (in this case it is, at least until upstream also makes this change), we wrap it in #if HAS_UNO ... #endif and include a comment explaining what it relates to and ideally also link to the issue. Once this is in, we will merge the PR 👍 |
|
@MartinZikmund Done! I have wrapped all Uno-specific changes in |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24509/wasm-skia-net9/index.html |
|
The build 239265 found UI Test snapshots differences: Details
|
|
|
Track selected ancestor containers across collection mutation instead of resolving the obsolete selected index path. Restore ancestor state when containers are prepared and clear it when they are recycled or selection is removed. Add runtime coverage for reparenting, collapsed destinations, three-level index changes and pane-mode rebinding. The equivalent patch builds on the 6.7.103 source and passes a Skia X11 development navigation gate; master runtime CI remains required.
Wait for the destination repeater to realize the moved row before selecting it. Preserve the selected-container assertion and add the runtime-test namespace imports and issue trace metadata. An isolated Skia X11 fixture passed the same reparenting sequence with expanded and collapsed destinations, three-level index changes, pane-mode rebind, null selection and synchronous selection callbacks.
Stop the outer selection callback when ancestor dependency-property callbacks supersede its captured selection. Cover root and nested fallback selection with real runtime tests. Restore the compact pane visible hierarchy before testing nested ancestor flags, preserving native leaf auto-close behavior. Assert the expansion provider before invoking it. Validation: full source-built SamplesApp, six Skia X11 runtime cases passed twice without retries; both fallback cases fail when the guard is removed. Existing MSB4011 duplicate-import warnings remain.
88a702d to
3b91fd8
Compare
|
Rebased onto latest master and aligned the runtime test with the new MUX test structure ( |
|
/azp run |
|
Commenter does not have sufficient privileges for PR 24509 in repo unoplatform/uno |
MartinZikmund
left a comment
There was a problem hiding this comment.
@YoungSx thanks for the #if HAS_UNO wrapping, and for filing microsoft/microsoft-ui-xaml#11927. The structure is what we wanted. Sorry to come back once more, but while going through the final diff I found one regression I can't merge as-is:
- Value-type menu items stop selecting on click. The new reentrancy guards compare items by reference (
selectedItem != selectionModel.SelectedItem).SelectionModel.SelectedItemre-reads the item throughItemsSourceView.GetAton every call, so for value-type items (e.g.MenuItemsSource = Enum.GetValues<Page>()or anObservableCollection<int>) every read returns a freshly boxed object and the comparison is always true. See the inline comment for the exact path. A barereturnthere means a click never updatesSelectedItemand never raisesSelectionChanged.
Optional, not blocking:
- The selected top-level item now always reports
IsChildSelected == false. WinUI sets it totruefor a size-2 path inUpdateIsChildSelectedForIndexPath(and the existing test assertstopLevel.IsChildSelected == false). That matches the intent of WinUI's own comment ("with the exception of the actual container"), so I'm fine keeping it. A short note in theHAS_UNOcomment would help, so the next WinUI sync doesn't treat it as accidental drift. UpdateIsChildSelectedForContainerruns on everyElementPreparedand walks the visual tree inGetIndexPathForContainer(and allocates) even when nothing is selected. An early out whenselectedPath is null || selectedPath.GetSize() <= 2(just clear the flag if set) avoids that cost on the common path.
Also, CI hasn't run on the rebased head yet. I'll kick it off once the fix is in.
| // An index-only change preserves ancestor identities and may precede repeater index updates. | ||
| UpdateIsChildSelected(selectionModel.SelectedIndex); | ||
| // Ancestor property callbacks may supersede this selection synchronously. | ||
| if (selectedItem != selectionModel.SelectedItem) |
There was a problem hiding this comment.
This (and the same check in UpdateIsChildSelected / UpdateIsChildSelectedForIndexPath) uses reference equality. SelectionModel.SelectedItem goes through SelectedItems[0], which calls ItemsSourceView.GetAt -> ListAdapter.GenericList<object> -> IList.this[], so for value-type items each read is a new box.
Click path for a flat enum/int menu: OnNavigationViewItemIsSelectedPropertyChanged -> UpdateSelectionModelSelection -> SelectAt -> here. selectedItem != SelectedItem is true (nothing selected yet), we refresh ancestors (a no-op for a top-level item), then this check compares two different boxes and returns. SetSelectedItemAndExpectItemInvokeWhenSelectionChangedIfNotInvokedFromAPI is never reached, so SelectedItem stays unchanged and SelectionChanged doesn't fire. On master this works, because the existing selectedItem == SelectedItem check only skips the ignore, it never bails out.
Using object.Equals(...) in the three guards would fix this. A more robust option is a small selection counter: increment it at the top of OnSelectionModelSelectionChanged, capture it, and bail out if it changed after the ancestor refresh. Then the guard detects "a nested selection happened" without depending on item identity. Could you also add a runtime case with value-type items (e.g. MenuItemsSource = new ObservableCollection<int> { 1, 2 }, select via the container / automation peer, assert SelectedItem and that SelectionChanged fired)?
| private void UpdateIsChildSelectedForContainer(NavigationViewItem container) | ||
| { | ||
| var selectedPath = m_selectionModel.SelectedIndex; | ||
| var containerPath = GetIndexPathForContainer(container); |
There was a problem hiding this comment.
Optional: this runs for every prepared container. GetIndexPathForContainer walks the visual tree and allocates a List<int> + IndexPath even when there is no selection or the selection is top-level (where no container can be an ancestor). Bailing out early when m_selectionModel.SelectedIndex is null or has size <= 2 (clearing IsChildSelected if it's set) keeps the virtualization path cheap.
GitHub Issue: closes #24508
PR Type:
🐞 Bugfix
What changed? 🚀
Moving a selected child between ObservableCollection groups can leave its former ancestors marked IsChildSelected. Collapsing an unrelated former parent then takes the selection indicator even though SelectedItem still identifies the moved leaf.
This Uno-specific correction tracks actual ancestor containers instead of resolving a stale previous index path after collection changes. It clears state on recycling/deselection, projects it for prepared containers, preserves ancestor identity on index-only changes, and excludes the selected leaf itself. Ancestor entries are removed before invoking dependency-property callbacks so synchronous changes cannot invalidate enumeration.
Follow-up 415d7c7 addresses the requested changes: after refreshing ancestors, the outer selection callback stops if a synchronous property callback superseded its captured selection. Real runtime coverage includes both a root fallback and a nested fallback chosen by that callback.
Validation
Code review: reviewed ownership, reentrancy, API contracts, security, performance, operability and test quality through the repository's eight-lens panel. The current guard uses final selected-item identity, matching the helper's contract; this is not a claim of generation-level intent tracking.
Compile: full source SamplesApp Release/net10.0-desktop built on Linux ARM64 with .NET SDK 10.0.400. Local analyzers were disabled using UnoFastDevBuild. The final build succeeded; existing MSB4011 duplicate-import warnings appear during initial project evaluation even though the build summary reports zero warnings. The previous nullable automation-provider conversion in this PR's runtime test was fixed with a provider-presence assertion.
Runtime: four methods / six parameterized executions from NavigationViewTests.AncestorSelection.cs passed twice on the real Skia X11 control tree, with zero failures, skips or retries. Coverage: data-bound reparenting; a collapsed destination; three-level index shifts with/without a pane-mode transition; clearing selection; synchronous ancestor-callback reselection to root and nested fallback items.
The compact-mode fixture respects native leaf auto-close: it reopens the pane before reselecting an explicit nested item and before checking its realized ancestor containers. Selected identity and the top-level ancestor are checked before that second reopening. All original ancestor assertions remain. This is not coverage of selecting a detached descendant with the pane kept closed.
Negative control: removing the five-line outer callback guard makes both new fallback rows fail at the retained-selection assertion. Restoring it makes both pass. Earlier development comparisons at Uno 6.7.103 also reproduced the original application indicator defect with the published assembly and passed with the equivalent source fix; those comparisons are not published-package validation.
Reproduction:
Evidence on the validation host: /tmp/pr24509-final3/results.xml, /tmp/pr24509-repeat/results.xml, /tmp/pr24509-negative/results.xml, /tmp/pr24509-final3-build.log. The build process alone used a 3 GiB GC heap cap, workstation GC and GCConserveMemory=9 to limit host pressure; these settings did not change source or the test app's runtime configuration.
Pending: maintainer re-review, official upstream runtime/strict CI, and native WinUI behavioral parity. The MUX tests are excluded by the Windows runtime project, so its ordinary job must not be counted as execution of these cases. The Microsoft implementation still uses the old index-path algorithm: this change is intentionally Uno-specific, not a literal port.
Consumers must wait for a published package containing the fix. The downstream application PR salmonloop/salmon-egg#214 remains Draft and must not substitute a development DLL or disable its failing GUI gate to appear green.
PR Checklist ✅