Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves WebAssembly scrollbar thumb-drag responsiveness by deferring ScrollViewer content scrolling during ThumbTrack so expensive layout work doesn’t run synchronously in the pointer-move path, and adds a Wasm-only runtime test to validate the deferred behavior.
Changes:
- Defer scrollbar
ThumbTrackscroll offset application to the dispatcher on browser-hosted targets (Wasm). - Flush queued thumb-track offsets via a dispatcher callback.
- Add a Wasm runtime regression test asserting thumb-track scrolling is deferred (not applied synchronously).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs | Adds dispatcher-queued deferral for scrollbar thumb tracking and flush logic. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_FastScroll.cs | Adds a Wasm-only runtime test for deferred thumb-track scrolling behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days. |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23581/wasm-skia-net9/index.html |
morning4coffe-dev
left a comment
There was a problem hiding this comment.
The browser-only deferral preserves the latest request per axis, coalesces pending work, flushes it at EndScroll, and leaves desktop behavior unchanged. ScrollBar's completion path actually raises EndScroll, so the terminal flush is connected rather than theoretical. This intentionally changes browser event timing, not the final public scroll target; it should not be described as identical synchronous WinUI dispatch. Additional rapid-track and EndScroll cases would strengthen the existing deferred-offset case but are non-blocking.
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
Port of unoplatform#23581 (f373381 and ceba7d8), for unoplatform#22495. In the browser, a scrollbar thumb drag scrolled the content synchronously inside each pointer move, so a long virtualized list laid itself out on every move: the content lagged behind the thumb and jumped. Thumb track offsets are now kept and applied once per dispatcher pass, and the last one is applied when the drag ends. Only browser-hosted ScrollViewers and thumb dragging are affected. - Test: Given_ItemsRepeater_FastScroll (WebAssembly).
Defer browser-hosted scrollbar ThumbTrack content scrolling so virtualized layout work does not block pointermove dispatch during thumb drag.\n\nAdds WASM runtime coverage for the deferred ScrollViewer path.\n\nFixes unoplatform#22495.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
ceba7d8 to
b9493d5
Compare
|
Tick the box to add this pull request to the merge queue (same as
|
1 similar comment
|
Tick the box to add this pull request to the merge queue (same as
|
MartinZikmund
left a comment
There was a problem hiding this comment.
@KRRT7 thanks for digging into this one, the scrollbar drag on WASM is a real pain point (issue #22495). I'd like to take it in a different direction though, because I don't think the deferral fixes the root cause, and it moves us away from WinUI. Here's my reasoning:
- No measured gain. The PR doesn't include any numbers, and the work isn't removed, just moved. WASM is single-threaded, so the same
ChangeViewCore→OnPresenterScrolled→ViewChangedcost still runs on the main thread, onesetImmediatehop later, before the next frame. The only real saving is coalescing when severalpointermoves land between dispatcher drains, and Chrome already rAF-alignspointermove. Could you share a before/after trace (frame times, or Chrome perf profile) on the repro from the issue? - Why the wheel is smooth and the thumb isn't. The wheel and touch go through
ScrollContentPresenter.Set(..., IsIntermediate: true). For intermediate updates,ScrollViewer.OnPresenterScrolledcoalescesVerticalOffset/ViewChangedviaRequestUpdate()(theAsynchronousIdleupdates mode) and skipsInvalidateArrange. The thumb path callsChangeViewCore, which is non-intermediate, so every move raises a finalViewChanged. For aListViewthat runsVirtualizingPanelLayout.OnScrollChangedsynchronously, and itsUpdateLayout/materialization loop is the expensive bit in the issue's repro. - WinUI semantics.
dxaml/xcp/dxaml/lib/ScrollViewer_Partial.cpp: ScrollViewer::HandleVerticalScrollappliesThumbTracksynchronously (spScrollInfo->SetVerticalOffset(newOffset)), but first callsEnterIntermediateViewChangedMode().EndScrollthen callsLeaveIntermediateViewChangedMode(TRUE /*raiseFinalViewChanged*/). The only deferral WinUI does during a thumb drag is opt-in, throughIsDeferredScrollingEnabled(m_verticalOffsetCached+SynchronizeScrollOffsetsAfterThumbDeferringonDragCompleted). This PR instead forces deferral on browser only, and still reports every flushed step as a non-intermediateViewChanged.
The suggested direction: keep ThumbTrack synchronous, but route it as intermediate (plumb isIntermediate: true through ChangeViewCore/ChangeViewNative to ScrollContentPresenter.Set). On EndScroll, raise the final non-intermediate ViewChanged (note that Set won't call Updated if the offset didn't change, so EndScroll needs to force it). That reuses the coalescing that already makes the wheel smooth, and it works the same on every Skia target, not only the browser. It also keeps the content visual (AnchorPoint) moving in the same handler as the thumb, so there's no question of the thumb and content rendering on different frames. With the current deferral, the thumb's layout tick is queued before the flush, so a render can slip in between them.
Smaller points are inline. Happy to help if anything's unclear!
| // internal so runtime tests can drive the scrollbar-drag path directly. | ||
| internal void OnVerticalScrollBarScrolled(object sender, ScrollEventArgs e) | ||
| { | ||
| if (e.ScrollEventType == ScrollEventType.ThumbTrack && TryDeferScrollbarThumbTrack(isVertical: true, e.NewValue)) |
There was a problem hiding this comment.
See the summary: WinUI applies ThumbTrack synchronously here, inside intermediate-ViewChanged mode (ScrollViewer::HandleVerticalScroll → EnterIntermediateViewChangedMode). I'd rather mark this as an intermediate update than defer it to the dispatcher.
| shouldSnap: true); | ||
| } | ||
|
|
||
| #if __WASM__ || __SKIA__ |
There was a problem hiding this comment.
Uno.UI only builds for Skia now, so __WASM__ is never defined here, and the #else stubs are dead code. If this code stays, the #if can go.
|
|
||
| if (verticalOffset is { } vertical) | ||
| { | ||
| _verticalOffsetIntent = vertical; |
There was a problem hiding this comment.
The synchronous path arms the intent with ValidateVerticalOffsetIntent(offset) (same for horizontal). The flush stores the raw value, so if the extent shrinks between queue and flush, the intent ends up past the range and keeps chasing it as the extent grows. This is the case the ValidateOffsetIntent comment warns about.
| NewValue = target, | ||
| }); | ||
|
|
||
| sut.Scroller.VerticalOffset.Should().BeApproximately(initialOffset, OffsetTolerance, |
There was a problem hiding this comment.
This asserts the implementation detail (the offset is not applied synchronously), and that is the opposite of WinUI, where the offset is applied synchronously during ThumbTrack. It also uses ItemsRepeater, which reacts to the effective viewport during layout, not to ViewChanged, so it doesn't cover the ListView path from the issue. With the intermediate approach, a better test would check that ViewChanged reports IsIntermediate == true during ThumbTrack, that a final IsIntermediate == false arrives on EndScroll, and that the offset ends at the target.
|
Tick the box to add this pull request to the merge queue (same as
|
GitHub Issue: closes #22495
PR Type:
🐞 Bugfix
What changed? 🚀
Defers browser-hosted
ScrollViewerscrollbarThumbTrackcontent scrolling so expensive virtualized layout work no longer runs synchronously inside the pointer move handler during thumb dragging.This keeps the scrollbar thumb drag path responsive on Wasm Skia while preserving final offset application through the dispatcher. A WASM runtime regression test covers the deferred scrollbar thumb-track path.
Validation performed locally:
git diff --checkdotnet build src/Uno.UI/Uno.UI.Skia.csproj --no-restore -p:UnoTargetFrameworkOverride=net10.0 -p:UnoFastDevBuild=truedotnet build src/Uno.UI/Uno.UI.Wasm.csproj --no-restore -p:UnoTargetFrameworkOverride=net10.0 -p:UnoFastDevBuild=truedotnet build src/Uno.UI.RuntimeTests/Uno.UI.RuntimeTests.Skia.csproj --no-restore -p:UnoTargetFrameworkOverride=net10.0 -p:UnoFastDevBuild=trueNote:
Uno.UI.RuntimeTests.Wasm.csprojrestore succeeds, but its build currently fails in existing unrelatedWasmSemanticDomHelper.csusage ofUIElement.Visual.PR Checklist ✅
Screenshots Compare Test Runresults.