Repository navigation
Avoid false positive prepend detection that causes backward scroll jumps - #69362
Conversation
…ved perf and uses only one call.
Prefetch adjusted provider windows and defer anchor restoration until the matching spacer mutation, preventing visible viewport shifts during continuous prepends.
reuse the list for comparison, slicing, and rendering. Add coverage for single-pass provider results and tighten the rapid scroll regression to reject any backward scroll movement.
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Five unresolved review comments remain, including four moderate issues affecting anchoring and test reliability.
Review effort: Lite
Findings: None
What changed in this PR
Fixes virtualization prepend detection, scroll anchoring, and duplicate provider requests for async lists.
Changes:
- Compares items at stable global indexes.
- Adds bounded tail prefetching and deferred anchor restoration.
- Adds top-follow tracking and regression coverage.
| File | Summary |
|---|---|
src/Components/Web/test/Virtualization/VirtualizeTest.cs |
Tests single-pass provider enumeration. |
src/Components/Web/src/Virtualization/VirtualizeJsInterop.cs |
Adds top-following and deferred-restore interop. |
src/Components/Web/src/Virtualization/Virtualize.cs |
Updates detection, prefetching, and anchoring. Moderate findings: deferred restoration may be canceled prematurely (1 vote); update comparer documentation (nit, 1 vote). |
src/Components/Web.JS/src/Virtualize.ts |
Tracks top-following and mutation-based restoration. Moderate finding: user input may be bypassed during top convergence (1 vote). |
src/Components/test/testassets/BasicTestApp/VirtualizationTableScrollWithAppend.razor |
Adds the async table scenario. Moderate finding: fixed timing makes tests scheduling-sensitive (1 vote). |
src/Components/test/testassets/BasicTestApp/Index.razor |
Registers the test scenario. |
src/Components/test/E2ETest/Tests/VirtualizationTest.cs |
Adds scrolling and anchoring tests. Moderate finding: the sentinel can accept an empty frame (1 vote). |
src/Components/test/E2ETest/ServerRenderingTests/VirtualizationRenderModesTest.cs |
Verifies tail prefetch reuse. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Canceled refreshes can publish stale state, and several timing-based E2E probes are nondeterministic.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 2
… when scrolling moves past the previously rendered first item. Add prepend and append unit coverage to verify that shifted windows preserve the requested item without reintroducing false prepend detection.
dariatiurina
left a comment
There was a problem hiding this comment.
Looks great! My question is about order of operations and cancellation. I remember we spoke of something similar before, so disregard if it's a duplicate
|
The failures look related. I have to investigate before merging. |
…aths such as tables. For native anchoring the update is no-op.
…cates that external data may have changed.
|
/backport to release/11.0 |
|
Started backporting to |
…mps (#69362) Co-authored-by: Copilot <[email protected]>
…mps (#69362) (#69466) Co-authored-by: Copilot <[email protected]>


appends.drag.the.view.down.mp4
Reported by Aspire. The viewport (and scroll) jumps down even if user scrolls only up with the mouse wheel. In the video it's most visible after the user reaches the top: the viewport starts escaping downward without further user action. Setup:
ItemProviderwith ongoing prepends.Description
The issue is a false positive in
Virtualizeprepend detection. The check is activated when live updates increase the list count (countDelta > 0). The prepend detection keeps the previously rendered first item and compares it with the first item returned for the latest provider window. While the user scrolls, the requested provider window changes, so those items naturraly differ even though data was appended rather than prepended.To avoid this false positive,
Virtualizenow stores the first rendered item's global index and compares the item at that same index in the new provider result. This distinguishes a real prepend from an ordinary provider-window change caused by scrolling.Continuous tail-validation also showed that advancing an End-anchored window required a second provider request and exposed a partially updated window state. End-tail requests now include a bounded look-ahead, reuse prefetched rows for normal appends and publish the shifted window only after its rows are available. That improved perf is reflected in updated test
EndAnchoredAppend_IssuesExactlyTwoProviderCalls_AdvancingToTail->EndAnchoredAppend_ReusesPrefetchedTailWithOneProviderCall.For Start anchoring, JavaScript now tracks if the viewport is still following the top with
IsFollowingTopAsync(same mechanism as we already had for the tail of the list withIsFollowingBottomAsync). New rows remain visible while following the top. After the user scrolls away,Virtualizeloads the rows for the shifted window before changing the rendered range and prepares anchor restoration before rendering. For tables and other manual-anchoring cases,RestoreAnchorAsynccan now defer restoration until the matching spacer change. This lets JavaScript restore the saved row before the shifted rendered frame becomes visible.For test reviewers:
Table_EndAnchor_AsyncProvider_AppendDuringRapidUserScroll_DoesNotReverseScrollDirectionis regression test for the reported issue.Table_EndAnchor_AsyncProvider_ContinuousAppend_MaterializesNewTailBeforeUpdatesStopverifies that appended items are materialized while updates continue, visible indexes remain monotonic, intermediate indexes are not skipped, and the viewport remains pinned to the tail.Table_StartAnchor_AsyncProvider_ContinuousPrepend_MaterializesNewHeadWithoutIndexReversalverifies that Start-following remains pinned and displays each prepended item (symmetric to the end-append). It failed before the top-following change because head updates either did not materialize or moved visible indexes backward.Table_StartAnchor_AsyncProvider_ContinuousPrependAfterLeavingHead_KeepsViewportStablecovers QuickGrid Start anchoring does not preserve viewport after prepending rows in Server-rendered modes #69380 by requiring the same visible item to remain at the same viewport-relative offset during prepends.EndAnchoredAppend_ReusesPrefetchedTailWithOneProviderCallverifies that a normal End-anchored append reuses the bounded prefetch instead of issuing a second provider request. Covers the behavior reported in QuickGrid issues duplicate ItemsProvider requests during prepend and append refreshes #69381.Virtualize_ItemsProvider_PrependedSinglePassEnumerable_IsNotEnumeratedMoreThanOnceverifies that prepend detection and prefetch reuse do not repeatedly enumerate a provider-supplied sequence.Fixes #69381
Fixes #69380