Skip to content

chore: Resync ItemsRepeater / StackLayout / FlowLayoutAlgorithm / ViewportManagerWithPlatformFeatures from WinUI #23044

Open

Description

@MartinZikmund

Summary

The ItemsRepeater / StackLayout / FlowLayoutAlgorithm / ViewportManagerWithPlatformFeatures sources under src/Uno.UI/UI/Xaml/Controls/Repeater/ are drifting from WinUI. The header of ViewportManagerWithPlatformFeatures.cs records the port as being from WinUI commit 1cf9f1c. The upstream microsoft-ui-xaml tree has since had at least three syncs touching these files (67723ef, 69097129a, 256bdcd0c) and numerous bug fixes / refactors.

During the investigation for the companion issues (fast-scroll rendering regressions and anchor-provider gaps) several Uno-local "workarounds" were found that either:

  • Solve a symptom by breaking the upstream correction mechanism (for example the Math.Max(0, firstRealizedMajor) clamp in StackLayout.cs:186-189, tracked separately in fix: StackLayout.GetExtent clamps extent origin to 0, breaking ItemsRepeater's negative-offset correction #23042).
  • Duplicate logic that already matches upstream but are marked with misleading // Uno workaround [BEGIN/END] comments (for example the anchorIndex clamp in StackLayout.cs:150-154 — the code is functionally identical to WinUI's StackLayout.cpp:160-161, the "workaround" label is spurious).

A clean resync will close these gaps, reduce long-term maintenance load, and let the upstream comments speak for themselves rather than being diluted by workaround markers that no longer reflect reality.

Scope

Refresh the following files to WinUI HEAD of the microsoft-ui-xaml tree (or latest upstream at time of execution):

  • StackLayout.cs — from StackLayout.cpp + StackLayout.h + StackLayoutState.cpp/.h.
  • FlowLayout.cs — from FlowLayout.cpp + FlowLayout.h.
  • FlowLayoutAlgorithm.cs — from FlowLayoutAlgorithm.cpp + FlowLayoutAlgorithm.h.
  • FlowLayoutState.cs — from FlowLayoutState.cpp/.h.
  • ViewportManagerWithPlatformFeatures.cs — from ViewportManagerWithPlatformFeatures.cpp/.h.
  • ItemsRepeater.cs (partial set) — from ItemsRepeater.cpp/.h and ItemsRepeater.common.cpp/.h.
  • ItemsRepeaterScrollHost.cs — from ItemsRepeaterScrollHost.cpp/.h.
  • ViewManager.cs — from ViewManager.cpp/.h.
  • ElementManager.cs — from ElementManager.cpp/.h.
  • VirtualizingLayoutContext.cs / LayoutContext.cs / LayoutContextAdapter.cs — from matching .cpp/.h.
  • UniformGridLayout.cs — from UniformGridLayout.cpp/.h.

Exclude for now (separate evaluation / larger effort):

  • LinedFlowLayout.* — not currently present in Uno; new WinUI feature, may land as its own issue.
  • SelectionModel* / IndexPath* — if present in Uno, out of scope for this pass.

Approach

  1. Capture baseline — run the full Repeater runtime test suite (Given_ItemsRepeater, Given_StackLayout, etc.) on Skia Desktop and WebAssembly, record the green list. Merge the runtime tests from test: Add runtime tests for ItemsRepeater fast-scroll and scroll-to-top with high-variance item heights #23041 first so they are part of the baseline.
  2. Use the /winui-port skill per file. Preserve only legitimately Uno-specific paths:
    • #if !UNO_HAS_ENHANCED_LIFECYCLE perf guards.
    • Platform-specific dispatcher hooks (m_cacheBuildAction via DispatcherQueue).
    • EffectiveViewportChanged subscription guard on empty ItemsSourceView.
  3. Drop misleading "Uno workaround" comments where the code matches WinUI. Verify by diff.
  4. Drop the Math.Max(0, firstRealizedMajor) clamp (already tracked by fix: StackLayout.GetExtent clamps extent origin to 0, breaking ItemsRepeater's negative-offset correction #23042; this issue simply shouldn't reintroduce it during the resync).
  5. Port companion fixes from upstream — notably any fixes to:
    • Anchor tracking during BringIntoView.
    • Cache buffer inflation timing.
    • SetPendingViewportShift / SetExpectedViewportShift helper extraction (WinUI now uses helper methods; Uno inlines).
    • ResetLayoutExtent / ResetVisibleWindow / ResetLastLayoutRealizationWindow — these exist in current WinUI and are cleaner than the inline resets in Uno.
  6. Keep the Uno LayoutId() indirection and tracing helpers compatible. The C++ tracing macros expand to no-ops in most Uno builds; preserve the call shape so log lines stay consistent if someone wires verbose tracing locally.
  7. Update the port header comments at the top of each file to reference the new upstream commit(s) consumed.

Acceptance criteria

  • All runtime tests that were green before the resync remain green on Skia Desktop and WebAssembly.
  • Runtime tests added by test: Add runtime tests for ItemsRepeater fast-scroll and scroll-to-top with high-variance item heights #23041 pass.
  • No Uno-local // Uno workaround [BEGIN/END] block survives unless it has a live justification (document each one with a comment pointing to a specific Uno bug or platform limitation that still applies).
  • Each ported file's port-header comment is updated to the new upstream commit.
  • git diff master..this-branch shows removal (not addition) of custom logic in GetAnchorForRealizationRect and GetExtent relative to upstream parity.
  • Manual verification of a representative sample page (variable-height ItemsRepeater inside ScrollViewer) matches WinUI visual behavior.

Non-goals

Risk / rollback

A bad resync can regress subtle behaviors (nested repeaters, BringIntoView animation, cache-building timing). Mitigations:

  • Land as a single reviewable PR, not squashed with other fixes.
  • Baseline the runtime-test matrix before and after.
  • Capture before/after screenshots on the SamplesApp ItemsRepeater pages (ItemsRepeaterSample, ItemsRepeaterIndexPath, etc.).
  • If a regression lands and can't be root-caused in review, revert the whole file to the pre-resync version and split the port into smaller chunks.

Related

References

  • Uno files live under src/Uno.UI/UI/Xaml/Controls/Repeater/.
  • Port header sample: src/Uno.UI/UI/Xaml/Controls/Repeater/ViewportManagerWithPlatformFeatures.cs:3 — // ItemsRepeater.h, ItemsRepeater.cpp, commit 1cf9f1c.
  • Port tooling: /winui-port Claude Code skill.

Activity

  1. github-actions commented on Aug 13, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  2. added
    stale
    on Aug 13, 2026
  3. github-actions commented on Aug 24, 2026

    @github-actions
    Contributor

    This issue was closed because it had no activity for 10 days after being marked as stale. If you believe this is still relevant, feel free to reopen it or open a new issue with updated context.

  4. removed
    stale
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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