Repository navigation
fix(scrollviewer): Clamp offset intent to the request-time extent - #23719
MartinZikmund wants to merge 3 commits into
Conversation
|
Claude finished @MartinZikmund's task in 8m 22s —— View job PR Review — fix(scrollviewer): Clamp offset intent to the request-time extentTodo List
SummaryVerdict: Ship (1 nit, no blocking issues) Root cause & fix — correctThe fix is sound.
The "extent shrinks then grows back" invariant from #23041 is preserved because Call-site coverage — completeAll four arm sites now route through the clamping setters:
Internal paths ( NaN guard — justified
Test coverage — thoroughFive tests covering:
The One inline finding
Minor observations (not blocking)
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a ScrollViewer regression where ChangeView(...) requests beyond the current extent could “chase” a growing virtualized extent (e.g., incremental-loading ItemsRepeater), diverging from native WinUI and causing repeated over-fetch. The fix clamps the stored offset intent to the request-time scrollable extent so later extent growth cannot pull the viewport further.
Changes:
- Clamp stored vertical/horizontal offset intent at request time via
SetVerticalOffsetIntent/SetHorizontalOffsetIntent(with NaN-guarding). - Route scrollbar-driven intent arming through the new clamping setters (and use them from
ChangeViewintent capture). - Add runtime tests covering beyond-extent
ChangeViewbehavior, pre-first-layout clamping, extent shrink→grow restoration, and an end-to-end incremental-loading repeater scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs |
Stores offset intent clamped to request-time scrollable extent (and avoids NaN intent), preventing intent from chasing later extent growth. |
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/ScrollViewerTests/Given_ScrollViewer_OffsetIntent.cs |
Adds regression tests validating WinUI-parity clamping semantics and bounding incremental-loading behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23719/wasm-skia-net9/index.html |
|
|
3ae15a6 to
f1081f9
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23719/wasm-skia-net9/index.html |
|
Claude finished @MartinZikmund's task in 5m 37s —— View job PR Review — fix(scrollviewer): Clamp offset intent to the request-time extentTodo List
SummaryVerdict: Fix-first (2 issues blocking CI, 0 blocking logic)
|
|
|
|
Claude finished @MartinZikmund's task in 4m 25s —— View job PR Review — fix(scrollviewer): Clamp offset intent to the request-time extentTodo List
SummaryVerdict: Ship (1 nit, no blocking issues) Previously flagged issues — both resolved in
|
Review comments addressedPushed commit Fixed (4)
Notes on the second fix: the two suggested variants differed — one added a separate Changes were reviewed by inspection only; I did not build or run anything. Azure Pipelines CI will verify. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23719/wasm-skia-net9/index.html |
|
Claude finished @MartinZikmund's task in 2m 35s —— View job PR Review — fix(scrollviewer): Clamp offset intent to the request-time extentTodo List
SummaryVerdict: Ship — no new findings. All three previously flagged issues resolved
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23719/wasm-skia-net9/index.html |
6343fcb to
715885f
Compare
| batches.Should().BeLessThan(6, | ||
| $"a single beyond-extent ChangeView must clamp to the live extent and stop triggering incremental loads. " | ||
| + $"Loaded {batches} batches ({source.Count} items); VerticalOffset={sut.VerticalOffset:F2}, " | ||
| + $"ExtentHeight={sut.ExtentHeight:F2}."); |
|
Claude finished @MartinZikmund's task in 2m 17s —— View job PR Review — fix(scrollviewer): Clamp offset intent to the request-time extentTodo List
SummaryVerdict: Ship — no new findings. All previously flagged issues are resolved. All prior findings resolved
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23719/wasm-skia-net9/index.html |
715885f to
fb0d1d6
Compare
|
Claude finished @MartinZikmund's task in 2m 46s —— View job PR Review — fix(scrollviewer): Clamp offset intent to the request-time extentTodo List
SummaryVerdict: Ship (1 nit, same as prior Copilot finding — still unaddressed) All previously flagged issues remain resolved
|
| } | ||
| } | ||
|
|
||
| batches.Should().BeLessThan(6, |
There was a problem hiding this comment.
Nit: missing lower-bound guard — test can silently pass without exercising the trigger.
batches < 6 is an upper bound only. If ViewChanged never fires (e.g. the scroll is a no-op, or the DispatcherQueue.TryEnqueue dispatch is lost), batches stays at 1 and 1 < 6 passes without the incremental-load path ever running.
With the fix in place the expected flow is: initial load (1 batch) → ChangeView scrolls to the clamped extent → ViewChanged fires because VerticalOffset == ScrollableHeight → one more batch (2 total) → new ScrollableHeight exceeds the clamped intent so the trigger no longer fires → stable. So a lower bound of 2 is both correct and tight.
| batches.Should().BeLessThan(6, | |
| batches.Should().BeGreaterThan(1, | |
| $"the ChangeView must have scrolled to the live extent and triggered at least one incremental load. " | |
| + $"Loaded {batches} batches ({source.Count} items); VerticalOffset={sut.VerticalOffset:F2}, " | |
| + $"ExtentHeight={sut.ExtentHeight:F2}."); | |
| batches.Should().BeLessThan(6, |
(The suggestion replaces line 241 — add the BeGreaterThan assertion above the existing BeLessThan line.)
|
The build 229491 found UI Test snapshots differences: Details
|
|
|
#23695) ChangeView stored the caller's requested offset unclamped, and the post-layout recompute re-applied it as clamp(intent, 0, ScrollableHeight) on every arrange. A beyond-extent request therefore chased the extent as virtualized content realized: the viewport stayed pinned to the moving bottom edge, so incremental-loading consumers kept firing and over-fetched (15 batches / 375 items where WinUI and Uno 6.5/6.6 load 3). WinUI bounds the request when it is made: ScrollViewer::AdjustTargetVerticalOffset clamps against ComputePixelExtentHeight with no intervening layout pass, and ScrollContentPresenter::SetOffsetsWithExtents stores only the ValidateInputOffset-clamped value. Later extent growth can never carry the offset past what the caller could reach at request time. Clamp in SetVerticalOffsetIntent/SetHorizontalOffsetIntent and route every arm site through them (ChangeView, both scrollbar handlers, and the ScrollContentPresenter ISCP setters, which previously assigned the fields directly). Also skip arming on a NaN offset or NaN bound, which WinUI's ValidateInputOffset rejects outright and which would otherwise freeze the recompute or store the request unbounded. The intent still survives a transient shrink, so the #23041 fix this regressed out of is preserved. Validated at runtime on Skia Desktop (fail-before/pass-after; the end-to-end repeater test reproduces the reported 15 batches / 375 items / VerticalOffset=10000 pre-fix) and against native WinUI, where the beyond-extent and pre-first-layout tests pass unmodified. Regression sweep over ScrollViewer/Repeater/ListViewBase/ScrollContentPresenter/ItemsStackPanel shows an identical failure set before and after. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XbEqMr6QpVhzH9acLwTgnP
Remove five unused usings (CS8019 build-break under TreatWarningsAsErrors) and replace the #if/[Ignore] native skip with a merged [PlatformCondition] so the skip reason and platforms are visible in test metadata. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GKBgQoAmRmaFoXXZr93iLB
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
fb0d1d6 to
fdbbeee
Compare
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23719/wasm-skia-net9/index.html |
|
The build 230988 found UI Test snapshots differences: Details
|
|
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23719/wasm-skia-net9/index.html |
|
The build 231695 found UI Test snapshots differences: Details
|
|
|
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Request-time bounding is the right direction, but the new clamp misses WinUI's target-zoom behavior for a combined ChangeView request. Also, retain the explicit compatibility note already in the test: restoring the old intent after an extent shrinks and regrows is an intentional Uno-specific behavior, not native WinUI parity.
| // realization shrink that a virtualized StackLayout's extent estimate produces (#23041). | ||
| internal void SetVerticalOffsetIntent(double offset) | ||
| { | ||
| if (TryClampOffsetIntent(offset, ScrollableHeight, out var clamped)) |
There was a problem hiding this comment.
[P2] Clamp combined ChangeView requests using the target zoom
ChangeView arms this intent before applying its zoomFactor, so ScrollableHeight/Width still describe the old zoom. With unzoomed extent 400, viewport 200, current zoom 1, ChangeView(null, 400, 2, true) stores an intent of 200 even though 400 is valid in the target zoom's 600-pixel scrollable range. RecomputeOffsetsFromIntent can subsequently pull the offset back to 200.
WinUI's AdjustTargetVerticalOffset explicitly computes unzoomed extent * targetZoomFactor before clamping (and the horizontal path does likewise): https://github.com/microsoft/microsoft-ui-xaml/blob/439bda90582f7892ca595a193f55dbfc6ae2010c/dxaml/xcp/dxaml/lib/ScrollViewer_Partial.cpp#L12230-L12264 . Thread the effective target zoom into intent capture, and add combined zoom/offset regression coverage.
GitHub Issue: closes #23695
PR Type:
🐞 Bugfix
What changed? 🚀
ScrollViewer.ChangeView(...)to an offset beyond the current extent chased the virtualized extent as it grew, instead of clamping to the live extent the way native WinUI (and Uno 6.5/6.6) do. With content that grows during the scroll — anItemsRepeaterwith incremental loading — the viewport stayed pinned to the moving bottom edge, so every "load more when the viewport reaches the end" consumer kept re-firing and over-fetched: 15 batches / 375 items where WinUI loads 3.Root cause.
385b6146a9introduced an offset "intent" to preserve aChangeViewtarget across the extent fluctuations that a virtualizedStackLayoutproduces while realizing (#23041). The intent was stored raw, andRecomputeOffsetsFromIntentre-applied it asclamp(intent, 0, ScrollableHeight)on every arrange. AsScrollableHeightgrew, the clamp grew with it, so a request for10_000kept pulling the offset down until the content actually reached10_000.WinUI bounds the request when it is made:
ScrollViewer::AdjustTargetVerticalOffsetclamps againstComputePixelExtentHeight()with no intervening layout pass, andScrollContentPresenter::SetOffsetsWithExtentsstores only theValidateInputOffset-clamped value. Later extent growth can never carry the offset past what the caller could reach at request time.The fix. Clamp in
SetVerticalOffsetIntent/SetHorizontalOffsetIntent, and route every arm site through them — publicChangeView, both scrollbar handlers, and theScrollContentPresenterIScrollInfosetters, which previously assigned the fields directly. Also skip arming on aNaNoffset orNaNbound: WinUI'sValidateInputOffsetrejects those outright, and either one would otherwise freeze the recompute or store the request unbounded.The intent still survives a transient shrink, so the #23041 behavior this regressed out of is preserved. Only requests that exceed the request-time maximum change behavior.
Validation
Runtime — Skia Desktop. The new tests fail before and pass after. The end-to-end repeater test reproduces the issue's exact reported numbers pre-fix (15 batches, 375 items,
VerticalOffset=10000).Runtime — native WinUI (WinAppSDK).
When_ChangeView_BeyondExtent_*andWhen_ChangeView_BeforeFirstLayout_*pass unmodified against native WinUI, confirming the clamped semantics are parity rather than a guess.Worth calling out:
When_ExtentShrinksThenGrowsBack_Then_RequestedOffset_Is_Restoredis[PlatformCondition(Exclude, NativeWinUI)]because native WinUI was measured to not restore the offset (it lands at 100, not 200) — its DirectManipulation pipeline drops the request permanently. Uno's restore is a deliberate divergence covering the non-monotonic extent estimate of the virtualizedStackLayout. The test documents that.Regression sweep — Skia Desktop.
Given_ScrollViewer+ScrollViewerTests+Repeater(92 tests) andGiven_ListViewBase+Given_ScrollContentPresenter+Given_ItemsStackPanel+ListViewTests(152 tests). Failure sets with the fix stashed and applied are identical — zero new failures. (The 4 pre-existing failures on my machine are 150%-DPI rounding artifacts.)PR Checklist ✅
Screenshots Compare Test Runresults.The regressing commit is on
masteronly and was never backported torelease/stable/6.6, so no released version is affected.🤖 Generated with Claude Code
https://claude.ai/code/session_01XbEqMr6QpVhzH9acLwTgnP