Skip to content

fix(reactive): keep the ListView selection of a ListFeed.Selection across refresh and paging - #3259

Merged
kazo0 merged 4 commits into
mainfrom
dev/sb/mvux-selection-refresh
Oct 23, 2026
Merged

kazo0 merged 4 commits into
mainfrom
dev/sb/mvux-selection-refresh

Conversation

@kazo0

@kazo0 kazo0 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #3258

PR Type

  • Bugfix

What is the current behavior?

With ListFeed.PaginatedAsync(...).Selection(state) shown in a FeedView with a ListView, a row selected in the ListView loses its selection when the feed refreshes (FeedView.Refresh), while the selection state keeps the item. It is the same ListView instance, and the item is in the reloaded page. Loading the next page loses it the same way, refresh or not.

There are two causes:

  1. ListFeedSelection re-applies a stale value. A selection made in the ListView is a transient update of the list state, which StateImpl drops 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.
  2. SelectionFacet writes the ListView's reset into the state. On a collection Reset, Selector.ResetIndexIfNeeded() sets SelectedIndex = -1, and SelectionFacet pushed that to the state as a user deselection. On main it 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), the ListView writes None into the state while pages load.

What is the new behavior?

The ListView keeps the selection of an item that is still in the list, after a refresh and after paging, and the state is never set to None by the reset. A list without .Selection() behaves as on main: 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: an IsRaisingReset flag while a Reset is raised.
  • SelectionService / BindableListFeed: when the source drops the selection (the selection is unset, and not by an operator such as ListFeedSelection while the list is edited), BindableListFeed flags the service as IsLostBySource. 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 (an Add) keeps the row selected.
  • SelectionFacet: while a reset is raised and the source still holds the selection, the ListView'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 on main. Whether a data change ends up as a reset is decided by DataLayerTracker (threshold of changes), which is why the decision is made in the facet.
  • MessageAxis: SelectionSource is now shared, so the binding can tell a selection unset by an operator from a lost one.

specs/019-mvux-selection-refresh/progress.md has the details, the review round, and what isn't covered.

PR Checklist

  • Tested code with current supported SDKs: Skia desktop (Win32); Uno.Extensions.Reactive.WinUI.csproj Release build (MSBuild, all TFMs), 0 warnings.
  • Docs have been added/updated: not applicable, no API change.
  • Unit Tests and/or UI Tests for the changes have been added:
    • Given_ListFeedSelection: When_SelectedFromList_And_SourceRefreshed_Then_SelectionKept and When_SelectedFromList_And_NextPageLoaded_Then_SelectionKept. Both fail on main and pass with the fix, and also assert that no None is written into the state.

    • New runtime tests Given_FeedView_Selection (FeedView + ListView from XAML, selection made with SelectedIndex / SelectedItems):

      • refresh, then next page (the issue's scenario);
      • next page alone;
      • the selected item moved by a refresh (an item inserted on top);
      • multiple selection across a refresh;
      • guards: a ListFeed without .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.

  • Wasm UI Tests: not run.
  • Contains NO breaking changes.
  • Updated the Release Notes: not maintained in this repo.
  • Associated with an issue: [MVUX] FeedView.Refresh clears the ListView selection of a ListFeed.Selection while the state keeps the item #3258.

Other information

Test results:

  • Given_ListFeedSelection: 41/41.
  • Reactive unit tests: 1492 passed, 0 failed, 19 skipped.
  • Given_FeedView_Selection: 7/7, four runs.
  • Reactive runtime slice (Uno.Extensions.Reactive.WinUI.Tests & !HotReload): 21 of 26 pass. The 5 failures also fail with main's product code on the same machine: the 3 ComboBox selection tests, When_PreselectedItem_SelectedItems_ListView (flaky), and When_SelectSingleFromView_ListView (its pointer setup finds fewer than 2 realized items; not in the first run's list, but it fails on main too).

The issue's repro app, run with this branch's Uno.Extensions.Reactive.dll and Uno.Extensions.Reactive.UI.dll (first round), printed ListView.SelectedItem=Item 7; model Selected=Item 7 after the refresh and after the next page, in 5 runs out of 5.

Known side effects (not changed):

  • The restored selection raises SelectionChanged, so Navigation.Request on the ListView navigates again after a refresh. Nothing is pushed on the back stack: a Frame rebuilds the current view model with the refreshed item, a ContentControl recreates the details view, a visibility region keeps its child.
  • Switch is 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 queued MoveCurrentToPosition fixes it.

Not verified:

  • The Windows path where the ListView reads selection through ISelectionInfo (SelectRange / ReplaceRange / DeselectRange are not guarded during a reset; the multiple-selection test passes on Skia without it).
  • Grouped lists.
  • A source that publishes a new list before the 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.
  • [ListState] Command bound (Multi) Selection doesn't get applyed in the UI Layer at all #2946 was not investigated.

🤖 Generated with Claude Code

https://claude.ai/code/session_01S2dNq2o9fQzKWoDCTkAbpn

kazo0 and others added 3 commits October 22, 2026 17:58
…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
…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
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

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.

@kazo0

kazo0 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

End-to-end check in an agent session: a skill-ab catalog run, session 1 of 2. Claude Opus builds a Parts Catalog app from a brief: a FeedView over ListFeed.PaginatedAsync(...) of 1,000 parts, with refresh. It verifies the app through the App MCP on Skia desktop.

Setup: the Extensions packages came from this PR's CI build (241068, 8.0.0-dev.123.g197a110a49, the head f67aae3d merged onto main). They were installed under the Sdk's pin. Everything else was the same as the baseline run: studio plugin ba56d3d, Uno.Sdk 7.0.0-dev.81 (Uno 7.0.0-dev.2347). The session also ran the App MCP fix from unoplatform/uno.app-mcp#224.

Result: the agent wrote ListFeed.PaginatedAsync(...).Selection(SelectedPart) and ran the scenario from #3258:

  • It selected P-0007, clicked Refresh, and checked again. In its words: "After the refresh, items shows 20 with the selection preserved". Its final report says "P-0007 stayed selected after a refresh".
  • It selected P-1000, which isn't on the reloaded first page, and refreshed. The part was deselected and the detail pane went back to "Select a part", which is the expected behavior.
  • Selection also survived window resizes and a Hot Reload.
  • The app never writes SelectedItem; its one SelectionChanged handler only reads it, for layout.

Session 2: the agent also wrote .Selection(SelectedPart) and checked refresh twice:

  • With index 6 selected, it refreshed. In its words: "The refresh reloads the list from the start, dropping from 61 items to 20, with no loading state shown and the selection (index 6) preserved throughout".
  • It selected P-0045, which is beyond the first page, and refreshed. The detail pane kept P-0045, and the agent then scrolled down to check that the row was selected again once its page loaded. Its report says "The selected part stays selected after a refresh, including one beyond the first page, which is highlighted again once its page loads". That covers the paging half of the fix.

Baseline: the two baseline sessions ran the same plugin and Sdk without this PR.

  • In one, the agent saw the bug: "the list lost its selectedIndex right after refresh" while the detail still showed the part. It then wrote a RestoreListSelection workaround in code-behind.
  • The other dropped .Selection(...) from its model.

Neither session with this PR needed a workaround. Both kept .Selection(...), and neither writes SelectedItem.

Cost: $6.37 and $7.74 (baseline $6.67 and $15.57). The baseline's $15.57 session was largely spent fighting the selection.

@kazo0
kazo0 merged commit 4597d2e into main Oct 23, 2026
26 of 27 checks passed
@kazo0
kazo0 deleted the dev/sb/mvux-selection-refresh branch October 23, 2026 18:10
agneszitte added a commit that referenced this pull request Nov 3, 2026
…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]>
agneszitte added a commit that referenced this pull request Nov 3, 2026
…6.7-sr3

fix: get servicing/7.4 ready for 6.7 SR3 (backport #3228, #3231, #3235, #3249, #3254, #3259; Uno floor 6.7.65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MVUX] FeedView.Refresh clears the ListView selection of a ListFeed.Selection while the state keeps the item

2 participants