Repository navigation
fix(reactive): keep the ListView selection of a ListFeed.Selection across refresh and paging - #3259
Conversation
…ction on refresh and paging A selection made on the list (e.g. by the ListView) is only a volatile update of the list state, dropped on the next message of the source. The selection was then re-applied from the stale value the selection state had before, as the state-to-list sync ignored the changes pushed by the list itself, so the list lost its selection on refresh or when a new page was loaded while the selection state kept the item. Track the value pushed by the list in the selection update, so the selection is re-applied by key on the new list. Fixes #3258 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018sEtgJtks9nQfLQgLZsRzU
… collection reset On a reset of the collection, the ListView clears its selection, which was pushed to the source as a deselection made by the user, writing null into the selection state. Ignore the selection changes made by the view while a reset is being raised and restore the selection from the selection service once reset. As the service is now the reference on reset, a selection unset on the source (e.g. the volatile selection of a list state lost on refresh) is also pushed to it as an empty selection, unless it has been unset by an operator, like the ListFeedSelection while the list is being edited (the selection state still holds the item). Fixes #3258 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018sEtgJtks9nQfLQgLZsRzU
…paging (#3258) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018sEtgJtks9nQfLQgLZsRzU
…ed without Selection - Revert the unset-as-empty push in BindableListFeed: it deselected the row on every page of a paginated ListFeed without .Selection() - Flag the SelectionService as IsLostBySource when the source drops the selection (set before the Switch) - SelectionFacet: on reset, restore from the service and suppress the ListView's clear only when the source still holds the selection - ListFeedSelection: lock a private gate instead of this - Runtime tests: selected item moved by refresh, list feed without Selection (refresh clears, next page keeps), multiple selection across refresh - Address review of #3259 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S2dNq2o9fQzKWoDCTkAbpn
|
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. |
|
End-to-end check in an agent session: a skill-ab Setup: the Extensions packages came from this PR's CI build (241068, Result: the agent wrote
Session 2: the agent also wrote
Baseline: the two baseline sessions ran the same plugin and Sdk without this PR.
Neither session with this PR needed a workaround. Both kept Cost: $6.37 and $7.74 (baseline $6.67 and $15.57). The baseline's $15.57 session was largely spent fighting the selection. |
…ross refresh and paging (backport #3259) - Backport of #3259 to servicing/7.4 - specs/lessons.md: keeps 7.4's lessons and adds the one #3259 adds after them - specs/019-mvux-selection-refresh/progress.md: without the trailing blank line, as main's fd9e9e6 fixed it (markdownlint MD012) Co-Authored-By: Claude Opus 5.5 <[email protected]>
GitHub Issue (If applicable): closes #3258
PR Type
What is the current behavior?
With
ListFeed.PaginatedAsync(...).Selection(state)shown in aFeedViewwith aListView, a row selected in theListViewloses its selection when the feed refreshes (FeedView.Refresh), while the selection state keeps the item. It is the sameListViewinstance, and the item is in the reloaded page. Loading the next page loses it the same way, refresh or not.There are two causes:
ListFeedSelectionre-applies a stale value. A selection made in theListViewis a transient update of the list state, whichStateImpldrops on the next source message. The operator's own update then re-applies the selection state's earlier value (None): the state-to-list sync skips changes that came from the list (ListFeedSelection.cs:133), so that update was never told about the new selection.SelectionFacetwrites theListView's reset into the state. On a collectionReset,Selector.ResetIndexIfNeeded()setsSelectedIndex = -1, andSelectionFacetpushed that to the state as a user deselection. Onmainit was hidden by cause 1. Once something keeps the selection across a reset (a fix for cause 1 alone, or an app re-selecting the row after reloads), theListViewwritesNoneinto the state while pages load.What is the new behavior?
The
ListViewkeeps the selection of an item that is still in the list, after a refresh and after paging, and the state is never set toNoneby the reset. A list without.Selection()behaves as onmain: the selection is cleared by a refresh and kept by the next page.ListFeedSelection: a state change that came from the list updates the operator's selection value without re-applying it. The next source message re-applies the item by key, and no extra message is emitted.CollectionChangedFacet: anIsRaisingResetflag while aResetis raised.SelectionService/BindableListFeed: when the source drops the selection (the selection is unset, and not by an operator such asListFeedSelectionwhile the list is edited),BindableListFeedflags the service asIsLostBySource. The flag is set before the collection is switched, so it's already set when the view handles the reset. It's cleared by the next selection from the source or from the view. The view's selection isn't changed by the flag, so a next page (anAdd) keeps the row selected.SelectionFacet: while a reset is raised and the source still holds the selection, theListView's clear isn't pushed to the state, and the view's selection is restored from the selection service after the reset. If the source lost the selection, the clear is pushed as onmain. Whether a data change ends up as a reset is decided byDataLayerTracker(threshold of changes), which is why the decision is made in the facet.MessageAxis:SelectionSourceis now shared, so the binding can tell a selection unset by an operator from a lost one.specs/019-mvux-selection-refresh/progress.mdhas the details, the review round, and what isn't covered.PR Checklist
Uno.Extensions.Reactive.WinUI.csprojRelease build (MSBuild, all TFMs), 0 warnings.Given_ListFeedSelection:When_SelectedFromList_And_SourceRefreshed_Then_SelectionKeptandWhen_SelectedFromList_And_NextPageLoaded_Then_SelectionKept. Both fail onmainand pass with the fix, and also assert that noNoneis written into the state.New runtime tests
Given_FeedView_Selection(FeedView+ListViewfrom XAML, selection made withSelectedIndex/SelectedItems):ListFeedwithout.Selection()refreshed (selection cleared) and paged (selection kept), and an item added to a.Selection()list state.The 4 scenario tests fail on
main(e.g.ListView.SelectedItem=<none>, state=I-007); the 3 guards pass before and after.Other information
Test results:
Given_ListFeedSelection: 41/41.Given_FeedView_Selection: 7/7, four runs.Uno.Extensions.Reactive.WinUI.Tests & !HotReload): 21 of 26 pass. The 5 failures also fail withmain's product code on the same machine: the 3 ComboBox selection tests,When_PreselectedItem_SelectedItems_ListView(flaky), andWhen_SelectSingleFromView_ListView(its pointer setup finds fewer than 2 realized items; not in the first run's list, but it fails onmaintoo).The issue's repro app, run with this branch's
Uno.Extensions.Reactive.dllandUno.Extensions.Reactive.UI.dll(first round), printedListView.SelectedItem=Item 7; model Selected=Item 7after the refresh and after the next page, in 5 runs out of 5.Known side effects (not changed):
SelectionChanged, soNavigation.Requeston theListViewnavigates again after a refresh. Nothing is pushed on the back stack: aFramerebuilds the current view model with the refreshed item, aContentControlrecreates the details view, a visibility region keeps its child.Switchis enqueued on the UI thread and the selection service is updated from the feed thread right after. If the UI thread handles the reset first and the refresh moved the selected item, the previous index is selected until the queuedMoveCurrentToPositionfixes it.Not verified:
ListViewreads selection throughISelectionInfo(SelectRange/ReplaceRange/DeselectRangeare not guarded during a reset; the multiple-selection test passes on Skia without it).ListView's selection has reached the state; the selection is pushed asynchronously, so the previous value can be re-applied once, or the selection restored by index on a reset.🤖 Generated with Claude Code
https://claude.ai/code/session_01S2dNq2o9fQzKWoDCTkAbpn