Skip to content

fix(ItemsRepeater): Refresh the effective viewport when a cached page re-enters the tree - #25156

Merged
MartinZikmund merged 4 commits into
masterfrom
dev/mazi/repeater-reenter-viewport
Oct 10, 2026
Merged

MartinZikmund merged 4 commits into
masterfrom
dev/mazi/repeater-reenter-viewport

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Problem

An ItemsRepeater inside a ScrollViewer on a cached page (NavigationCacheMode="Required") realizes too few items after you navigate away and back. On Skia desktop the viewport shows the first card or two and stays half-empty until the user scrolls. Uno 6.7 doesn't do this, and neither does WinUI.

Found in a real app (Daily Plants, Uno.Sdk 7.0.0-dev.54 / Uno.WinUI 7.0.0-dev.1656, net10.0-desktop): Resources page → Podcast tab → Diary → back to Resources.

Root cause

When an element leaves the tree, UIElement.Shutdown() → ResetLayoutInformation() clears its layout storage (m_finalRect = LayoutInformation.GetLayoutSlot), the same way WinUI does.

On the way back in, ItemsRepeater subscribes to EffectiveViewportChanged during its first measure (ViewportManagerWithPlatformFeatures.EnsureScroller). At that point the page, ScrollViewer and ScrollContentPresenter haven't been arranged yet, so their layout slots are still 0,0,0,0. The initial effective viewport therefore comes out as a zero-size rect (0,-72,0,0 in the test). The repeater shrinks its visible window to match.

The next arrange then gives each element exactly the rect it had before it left. Uno raised OnViewportUpdated() from UIElement.ArrangeVisual, which doesn't compare against m_finalRect. It compares against its own _lastFinalRect cache, which Shutdown never cleared. So it decided nothing changed, skipped OnViewportUpdated(), and never propagated the correct effective viewport. The repeater keeps the zero-size window until something else (a scroll) updates the viewport.

WinUI handles this case. CUIElement::ArrangeInternal (dxaml/xcp/core/core/elements/uielement.cpp) bypasses only when !GetIsArrangeDirty() && IsSameRect(finalRect, FinalRect). Otherwise it calls InvalidateViewport(), and FinalRect is the layout storage that Shutdown reset. Then CLayoutManager runs the effective-viewport walk after arrange.

Why it regressed from 6.7

The stale _lastFinalRect and the zero-size initial viewport were already in 6.7. The 6.7 ViewportManager hid them because it kept its cache buffer across unload/load. The WinUI sync of ItemsRepeater / ViewportManagerWithPlatformFeatures (#23406) brought in WinUI's ResetLayoutRealizationWindowCacheBuffer() on Unloaded/Loaded, and that sync is correct. Cache growth is also bounded by the visible window size. So with a zero-size visible window, the realization window now stays around 80px and only the first item or two are realized.

Fix

Follows WinUI's mechanism rather than patching Uno's visual-rect cache:

  • UIElement.DoArrange now calls OnViewportUpdated() after ArrangeCore whenever the arrange isn't bypassed. That's the same condition WinUI uses (IsArrangeDirty || finalRect != m_finalRect) to call InvalidateViewport() in CUIElement::ArrangeInternal. Uno propagates the viewport eagerly instead of in a deferred CLayoutManager walk, so the call goes after ArrangeCore, once the new layout slot is set.
  • UIElement.ArrangeVisual no longer calls OnViewportUpdated(). Its _lastFinalRect cache now only decides whether the composition visual needs updating.
  • ResetLayoutInformation() is untouched (1:1 with WinUI). It already clears m_finalRect on leave, so the first arrange after re-entering the tree is dirty and refreshes the effective viewport.

ArrangeVisual is only reached through ArrangeCore → DoArrange, so every change it used to detect still runs through the new call site. Translation and flow-direction changes go through InvalidateArrange.

Tests

  • New runtime test Given_ItemsRepeater.When_CachedPage_NavigatedBack_Then_RealizedItemsFillViewport: a Frame with a cached page containing ScrollViewer > StackPanel > ItemsRepeater (StackLayout Spacing=12). It navigates away and back, then asserts the realized items still cover the viewport.
  • Skia desktop (Win32), WinUI-aligned fix: Given_ItemsRepeater + Given_FrameworkElement_EffectiveViewport + Given_ScrollViewer: 167 tests, 159 passed, 8 failed, 5 skipped. The 8 failures are the same set with the original fix (_lastFinalRect reset). They're all display-scale rounding (for example 225.2 vs 225).
  • Skia desktop (Win32), earlier runs with the original fix:
    • Given_ItemsRepeater: 38/38 passed (2 skipped by existing [Ignore]).
    • Broader set (all Repeater MUX tests, Given_ItemsRepeater*, EffectiveViewport, Given_Frame, Given_ScrollViewer, Given_UIElement, Given_FrameworkElement, Given_Page, Given_NavigationView, Given_ItemsView, Given_ListViewBase, Given_StackPanel, Given_Grid, Given_Border, FrameIntegrationTests): 1422 tests, 1384 passed, 34 failed, 73 skipped. The 34 failures are the same set, with the same counts, when I run master without this fix on this machine. They are pixel/rounding asserts that fail because the display scale is 250% (for example TestVariousArrangedPosition reporting 4.000030517578125 instead of 4), so they're unrelated to this change.

Real app before/after

Same Daily Plants build and the same steps (Resources → Podcast → Diary → Resources). For "after", I swapped only Uno.UI.dll for this branch's build (original fix). That dll also carries the 9 master commits that landed after dev.1656, so the runtime test above is the clean A/B.

Before (7.0.0-dev.1656) After (this branch)
Only 2 cards realized after returning to Resources, rest of viewport empty Viewport full of cards

WinUI reference: the native WinUI build of the same app (Store install) also keeps a full list of Podcast cards after re-entering Resources, same as Uno 6.7 and this fix.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FB3tfbMqXEE648tbGEmcgV

MartinZikmund and others added 2 commits October 9, 2026 18:16
… re-enters the tree

Shutdown clears an element's layout storage when it leaves the tree, but
ArrangeVisual compared against its own _lastFinalRect cache, which kept the
pre-removal rect. On re-entry the first arrange restored the same rect, so
it was treated as unchanged and OnViewportUpdated never ran. Listeners such
as ItemsRepeater kept the zero-size effective viewport computed while the
ancestors were still unarranged, and realized only one or two items until
the user scrolled.

Reset the ArrangeVisual baseline together with the layout storage, matching
WinUI's CUIElement::ArrangeInternal, which compares against FinalRect and
invalidates the viewport otherwise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 16:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 18s —— View job


Review of #25156

Verdict: ship. No blocking issues. I found nothing to post inline.

  • Root cause: the fix targets the actual invariant, not a guard. ArrangeVisual (UIElement.cs:1865) compares against _lastFinalRect and _lastClippedFrame. Shutdown → ResetLayoutInformation() cleared m_finalRect but not these two. Resetting them in LayoutStorage.cs puts the skip check on the same baseline as WinUI's FinalRect. This is a root-cause fix.
  • Test: the new runtime test is red before the fix and green after, per the PR description. It covers the scenario that regressed (a cached page navigated away and back). It adds no [Ignore], and it's in Uno.UI.RuntimeTests.
  • Style: the comment is short and explains why. Tabs and braces are fine.
  • Evidence: I verified by inspection only. I did not build or run anything. The runtime results quoted are the author's.

Minor, non-blocking notes:

  1. ResetLayoutInformation is [Conditional("UNO_REFERENCE_API")]. I couldn't confirm which targets define that symbol. The call site at UIElement.mux.cs:1396 and the Skia runtime test passing suggest it's defined where it matters. It's worth a quick check on WASM, which the test doesn't cover here.
  2. Resetting to default means a first arrange with rect 0,0,0,0, a null clip and no translation is still seen as "unchanged". That was already true for a freshly created element and Visual.IsArrangePending handles the paint side, so it's acceptable. Zero-size ancestors can't produce a meaningful viewport anyway.

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238593 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1161

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • DropDownButtonPage.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • CalendarView_Theming.png-dark
    • Buttons.png
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • Examples.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
  • skia-windows-screenshots: 1161 changed over 2474

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • Attributed_text_Simple.png-dark
    • AutoBorderStretchwithrightmargin.png
    • AutomationProperties_Relations.png-dark
    • AutomationProperties_Relations.png
    • AutoSuggestBox_Keyboard.png-dark
    • AutoSuggestBox_Keyboard.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • Border_LinearGradientBrush.png-dark
    • Border_LinearGradientBrush.png
    • Brushes_ImplicitConvert.png-dark
    • Brushes_ImplicitConvert.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Capture with overlap.png-dark
    • Capture with overlap.png
    • ComboBox_IsSelected.png-dark

MartinZikmund and others added 2 commits October 10, 2026 09:33
Move the effective viewport refresh from ArrangeVisual's visual-rect cache
into DoArrange, keyed on the same dirty/m_finalRect check WinUI's
CUIElement::ArrangeInternal uses for InvalidateViewport(). ResetLayoutInformation
already clears m_finalRect on leave, so the Uno-specific reset is dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FB3tfbMqXEE648tbGEmcgV
Copilot AI balanced review requested due to automatic review settings October 10, 2026 07:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 29s —— View job


Review of #25156 (re-review after synchronize)

Verdict: fix-first (minor). The root-cause direction is sound, but the PR no longer matches its description and the new behavior needs evidence.

Findings

  1. The description is stale. It says the fix resets _lastFinalRect and _lastClippedFrame in ResetLayoutInformation(). The branch no longer does that. Commit 5b756d7b instead removes OnViewportUpdated() from UIElement.ArrangeVisual (UIElement.cs:1895) and calls it unconditionally after ArrangeCore in DoArrange (UIElement.Layout.crossruntime.cs:454). Please update the description, and drop the "ResetLayoutInformation" explanation and the earlier review's note on it, which no longer apply.

  2. Perf and behavior change on a hot path. OnViewportUpdated() used to run only when the rect, clip, translation or flow-direction transform changed. It now runs on every isDirty arrange of every element, including arranges with an identical rect after InvalidateArrange.

    • That matches WinUI's InvalidateViewport in ArrangeInternal.
    • But Uno propagates eagerly, not in a post-layout walk. Each call runs PropagateEffectiveViewportChange (FrameworkElement.EffectiveViewport.cs:300), which computes GetParentViewport() and GetEffectiveViewport() unless IsEffectiveViewportEnabled is false.
    • Please confirm the early-out cost is negligible. A scroll or layout perf sample before and after would show it.
  3. Possible cause of the screenshot diffs. The CI reports 118 changed screenshots on Linux and 1161 on Windows, across many unrelated samples such as Buttons, AnimatedIcon and AutoSuggestBox. The change affects arrange for every element, so check this before merge.

    • Rule out base-image drift against master first.
    • If the diffs are real, look at which elements now propagate viewports and what that triggers (for example, deferred image or lazy-loading work).
  4. Test coverage. The new runtime test covers the cached-page scenario. There is no test for the new contract: a same-rect re-arrange should still raise EffectiveViewportChanged, and a re-entered element should get the correct viewport. A small Given_EffectiveViewport-style test would pin the new behavior independently of ItemsRepeater.

  5. Comment style, nit. The comment at UIElement.Layout.crossruntime.cs:452 is two lines and explains why, which is fine. It says "Uno propagates eagerly", so check that wording matches the other effective-viewport comments.

Other checks

  • Only the shared crossruntime path is touched, so Skia and WASM both get the change. I found no other ArrangeVisual callers that depended on the removed call.
  • No new [Ignore], no event Action, and no generated files were edited.
  • Evidence is by inspection only. I did not build or run anything, and the runtime results quoted are the author's.

Counts: 0 blocking, 2 should-fix (items 2 and 3), 2 minor (items 1 and 4).

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238750 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1160

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • DropDownButtonPage.png-dark
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • DynamicFont.png-dark
    • DisplayInformation.png-dark
    • DynamicFont.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 1160 changed over 2474

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • AppWindowFeatures.png-dark
    • AutoBorderStretchwithrightmargin.png-dark
    • AutomationProperties_Relations.png-dark
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Icons.png-dark
    • AutoSuggestBox_Icons.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BorderLeftwithmargins.png-dark
    • BorderLeftwithmargins.png
    • BorderVersusPanelClipping.png-dark
    • BorderVersusPanelClipping.png
    • Border_LinearGradientBrush.png-dark
    • Border_LinearGradientBrush.png
    • Border_Simple.png-dark
    • Border_Simple.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 238750 has failed on Uno.UI - CI.

@MartinZikmund
MartinZikmund merged commit 6ce118e into master Oct 10, 2026
51 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/repeater-reenter-viewport branch October 10, 2026 19:34
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.

4 participants