Repository navigation
fix(ItemsRepeater): Refresh the effective viewport when a cached page re-enters the tree - #25156
Conversation
… 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]>
…ed page Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Claude finished @MartinZikmund's task in 18s —— View job Review of #25156Verdict: ship. No blocking issues. I found nothing to post inline.
Minor, non-blocking notes:
|
|
The build 238593 found UI Test snapshots differences: Details
|
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
Frame.Navigate crashes the WinUI test host with 0xC0000005 (#23477). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FB3tfbMqXEE648tbGEmcgV
|
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
Other checks
Counts: 0 blocking, 2 should-fix (items 2 and 3), 2 minor (items 1 and 4). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25156/wasm-skia-net9/index.html |
|
The build 238750 found UI Test snapshots differences: Details
|
|
|
Problem
An
ItemsRepeaterinside aScrollVieweron 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,
ItemsRepeatersubscribes toEffectiveViewportChangedduring its first measure (ViewportManagerWithPlatformFeatures.EnsureScroller). At that point the page,ScrollViewerandScrollContentPresenterhaven't been arranged yet, so their layout slots are still0,0,0,0. The initial effective viewport therefore comes out as a zero-size rect (0,-72,0,0in 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()fromUIElement.ArrangeVisual, which doesn't compare againstm_finalRect. It compares against its own_lastFinalRectcache, whichShutdownnever cleared. So it decided nothing changed, skippedOnViewportUpdated(), 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 callsInvalidateViewport(), andFinalRectis the layout storage thatShutdownreset. ThenCLayoutManagerruns the effective-viewport walk after arrange.Why it regressed from 6.7
The stale
_lastFinalRectand the zero-size initial viewport were already in 6.7. The 6.7ViewportManagerhid them because it kept its cache buffer across unload/load. The WinUI sync ofItemsRepeater/ViewportManagerWithPlatformFeatures(#23406) brought in WinUI'sResetLayoutRealizationWindowCacheBuffer()onUnloaded/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.DoArrangenow callsOnViewportUpdated()afterArrangeCorewhenever the arrange isn't bypassed. That's the same condition WinUI uses (IsArrangeDirty || finalRect != m_finalRect) to callInvalidateViewport()inCUIElement::ArrangeInternal. Uno propagates the viewport eagerly instead of in a deferredCLayoutManagerwalk, so the call goes afterArrangeCore, once the new layout slot is set.UIElement.ArrangeVisualno longer callsOnViewportUpdated(). Its_lastFinalRectcache now only decides whether the composition visual needs updating.ResetLayoutInformation()is untouched (1:1 with WinUI). It already clearsm_finalRecton leave, so the first arrange after re-entering the tree is dirty and refreshes the effective viewport.ArrangeVisualis only reached throughArrangeCore→DoArrange, so every change it used to detect still runs through the new call site. Translation and flow-direction changes go throughInvalidateArrange.Tests
Given_ItemsRepeater.When_CachedPage_NavigatedBack_Then_RealizedItemsFillViewport: aFramewith a cached page containingScrollViewer>StackPanel>ItemsRepeater(StackLayout Spacing=12). It navigates away and back, then asserts the realized items still cover the viewport.0, expected ≥464).Frame.Navigateruntime test. On the WinAppSDK head,Frame.Navigatecrashes the test host with0xC0000005(Frame.Navigate fatal 0xC0000005 in theming runtime test on native WinUI #23477), which aborted the whole WinUI run before it wrote a results file.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 (_lastFinalRectreset). They're all display-scale rounding (for example225.2vs225).Given_ItemsRepeater: 38/38 passed (2 skipped by existing[Ignore]).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 exampleTestVariousArrangedPositionreporting4.000030517578125instead of4), 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.dllfor 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.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