Skip to content

test: Add runtime tests for ItemsRepeater fast-scroll and scroll-to-top with high-variance item heights #23041

Closed

Description

@MartinZikmund

Current behavior

The existing runtime test suite for ItemsRepeater in src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater.cs covers a handful of virtualization scenarios (When_ItemSignificantlyTaller_Then_VirtualizeProperly, When_NestedIRSlowlyChangeViewport_Then_MaterializedNeededItems, etc.), but does not cover the class of problems that are visible to users when ItemsRepeater hosts items with very high size variance and the user scrolls quickly:

  1. Fast-scroll jumps with variable-height items: when the user rapidly navigates (e.g. ChangeView to far-apart offsets) through a list where a few items are significantly taller than the running average, newly realized items can end up visually overlapping, appearing above the viewport, or positioned at the wrong ActualOffset.Y. This is a direct consequence of StackLayout.GetAnchorForRealizationRect / GetExtent using average-size estimation and the (Uno-specific) clamp of the extent origin to 0 blocking the correction pass. See fix: StackLayout.GetExtent clamps extent origin to 0, breaking ItemsRepeater's negative-offset correction #23042 (fix: StackLayout.GetExtent clamps extent origin to 0).

  2. Scroll-to-top after variable-height realization: after scrolling down through a list with tall items and scrolling back up, users can observe that the first item is not flush at offset 0 — some content is inaccessible. ScrollableHeight / ExtentHeight end up inconsistent with the real positions because the clamp and the missing anchor provider on ScrollViewer combine to lose track of the true layout extent.

  3. Anchor maintenance across a measure pass that expands items in place: when a realized item grows (e.g. late-loading content replaces a short placeholder), ItemsRepeater / ScrollViewer should keep the currently-visible items visually stable. Today nothing pins them — the visible content jumps.

We do not have targeted regression tests for any of the three scenarios above, so regressions in virtualization can ship undetected.

Expected behavior

Runtime tests under Uno.UI.RuntimeTests exercise and assert the following invariants on Skia Desktop and WebAssembly (and ideally on WinUI for parity):

Test A — When_FastScrollWithHighVarianceItems_Then_NoOverlap

  • Sources: 200 items, heights drawn from { 40, 40, 40, 1200, 40, 40, 40, ... } (every 10th item is ~30× taller).
  • Container: ScrollViewer (classic) hosting ItemsRepeater + StackLayout (Orientation=Vertical). Viewport height = 600.
  • Sequence: ChangeView(null, 5000, null, disableAnimation: true) → WaitForIdle → ChangeView(null, 0, ...) → WaitForIdle → ChangeView(null, 12000, ...) → WaitForIdle → ChangeView(null, 300, ...) → WaitForIdle.
  • Assertions (for each final state):
    • No two materialized repeater children have overlapping ActualOffset.Y..ActualOffset.Y+ActualHeight ranges.
    • Every materialized child's ActualOffset.Y is >= 0 OR (if the extent origin legitimately shifted negative) its TransformToVisual(repeater).Y is consistent with realizedBounds.
    • The child with DataContext == Source[expectedIndexAtOffset] is materialized and roughly centered in the viewport.
    • Screenshot assertion on a couple of known-color items to confirm visual placement.

Test B — When_ScrollToTop_AfterVariableScrolling_Then_FirstItemFlushAtZero

  • Same SUT as Test A.
  • Sequence: scroll to the end (Scroller.ScrollableHeight), then scroll back to 0, WaitForIdle.
  • Assertions:
    • Source[0] is materialized.
    • The repeater child bound to Source[0] has TransformToVisual(ScrollViewer).Y == 0 (within 0.5px tolerance).
    • Scroller.VerticalOffset == 0.
    • Screenshot of the top-left pixel corresponds to Source[0]'s background color.

Test C — When_RealizedItemGrows_Then_VisibleAnchorStable

  • 50 items, all 60px tall initially. Container: ScrollViewer + ItemsRepeater + StackLayout. Viewport = 400px.
  • Scroll to VerticalOffset = 1200, WaitForIdle. Capture the visible top item's DataContext and its TransformToVisual(ScrollViewer).Y.
  • Programmatically replace an off-screen earlier item's height (index 5, well above the viewport) with 1500px. Invalidate measure, WaitForIdle.
  • Assertions:
    • The previously-visible top item's DataContext is still visible.
    • Its TransformToVisual(ScrollViewer).Y has changed by less than 2px.
    • Scroller.VerticalOffset has shifted by approximately the grown delta to compensate.
  • This test validates the IScrollAnchorProvider contract end-to-end on classic ScrollViewer (currently broken — see feat: Implement IScrollAnchorProvider on classic ScrollViewer (CurrentAnchor, RegisterAnchorCandidate, anchor-tracking across layout) #23043 feat: Implement IScrollAnchorProvider on classic ScrollViewer).

Test D — Extension of existing When_ItemSignificantlyTaller_Then_VirtualizeProperly

  • After the existing sequence, scroll back to VerticalOffset == 0 and assert:
    • Source[0]'s realized element has TransformToVisual(ScrollViewer).Y == 0.
    • Source[0] visually occupies the top pixels (screenshot color check).
    • ExtentHeight is greater than or equal to the sum of heights of all known items.

Implementation notes

  • Place under src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_FastScroll.cs (new file) or extend Given_ItemsRepeater.cs. The existing SUT helper in that file (used by When_ItemSignificantlyTaller_Then_VirtualizeProperly at line ~413) is reusable.
  • Use TestServices.WindowHelper.WaitForIdle() and TestServices.WindowHelper.WaitForLoaded(...) consistently.
  • Guard the tests with #if !__SKIA__ [Ignore("Fails due to async native scrolling.")] matching the existing convention while native-platform scroll determinism remains an open item.
  • For the screenshot assertions, use UITestHelper.ScreenShot + ImageAssert.HasColorAt as elsewhere in the file.

Why this matters

Real-world chat/feed UIs — conversations, timeline feeds, dashboards with KPI + markdown cards — trivially produce the high-variance height profile (short status lines interleaved with tall code blocks / media). The current test suite passes while such UIs visibly break. These tests must land before or alongside the fixes tracked in #23042 (fix: StackLayout...) and #23043 (feat: Implement IScrollAnchorProvider...) so the fixes are verifiable and regression-protected.

References

  • src/Uno.UI/UI/Xaml/Controls/Repeater/StackLayout.cs:125-211 — GetAnchorForRealizationRect and GetExtent.
  • src/Uno.UI/UI/Xaml/Controls/Repeater/ViewportManagerWithPlatformFeatures.cs:213-260 — SetLayoutExtent, m_expectedViewportShift / m_unshiftableShift.
  • WinUI reference for parity: src/controls/dev/Repeater/StackLayout.cpp::GetExtent and ViewportManagerWithPlatformFeatures.cpp::SetLayoutExtent/OnLayoutUpdated.

Activity

  1. added 2 commits that reference this issue on May 11, 2026
    8939f8b
    797ca0d
  2. added a commit that references this issue on May 14, 2026
    385b614
  3. added a commit that references this issue on May 28, 2026
    ab92f75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions