Skip to content

Virtualize tests with ItemProvider should always contain a delay - #67959

Merged
ilonatommy merged 13 commits into
dotnet:mainfrom
ilonatommy:harden-virtualize-tests
Jul 24, 2026
Merged

ilonatommy merged 13 commits into
dotnet:mainfrom
ilonatommy:harden-virtualize-tests

Conversation

@ilonatommy

@ilonatommy ilonatommy commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Real life ItemProvider always comes with some delay. Virtualize and QuickGrid virtualized tests do not make sense for providers which just await Task.Yield(). This PR makes sure all AnchorMode/ScrollToItem/InitialItemIndex tests added in net11 have consistent coverage of delayed case. The list of edited tests is below (expand). Only 3 tests show UX issues in the delayed version.

Edited tests - initial results before framework changes
Test method Cases (pass/total) Result Failing cases
AnchorMode_Bottom_PrependKeepsViewportStable 6/6 ✅ —
AnchorMode_DeleteAboveViewport_ViewportStaysStable 0/1 ⏭️ (1 skipped)
AnchorMode_DeleteAtViewportTop_FirstSurvivingItemJumpsToTheTop 6/6 ✅ —
AnchorMode_DeleteBelowViewport_ViewportStaysStable 6/6 ✅ —
AnchorMode_End_AppendAfterLeavingBottom_DoesNotReengage 4/4 ✅ —
AnchorMode_End_AppendAtBottom_ViewportFollows 4/4 ✅ —
AnchorMode_End_AppendAtMidList_DoesNotAutoScroll 2/2 ✅ —
AnchorMode_End_GrowingDataset_AppendFollowsToBottom 1/1 ✅ —
AnchorMode_End_HomeKeyFromBottom_JumpsToTop 0/2 ❌ (variableHeight: True)
(variableHeight: False)
AnchorMode_End_LargeAppendAtBottom_StillFollows 4/4 ✅ —
AnchorMode_End_MidList_ViewportStable 2/2 ✅ —
AnchorMode_End_PrependAtTop_ViewportStaysStable 4/4 ✅ —
AnchorMode_End_SmallDataset_AppendAfterScrollingUpAFewRows_DoesNotReengage 2/2 ✅ —
AnchorMode_End_SmallDataset_AppendFollowsToBottom 1/1 ✅ —
AnchorMode_EndKeyJumpsToBottom 6/6 ✅ —
AnchorMode_HomeKeyJumpsToTop 6/6 ✅ —
AnchorMode_MidList_AppendKeepsViewportStable 6/6 ✅ —
AnchorMode_NearTop_AppendKeepsViewportStable 6/6 ✅ —
AnchorMode_NearTop_PrependKeepsViewportStable 8/8 ✅ —
AnchorMode_None_AppendAtBottom_NoAutoScroll 2/2 ✅ —
AnchorMode_None_AsyncProvider_PrependKeepsViewportStable 1/1 ✅ —
AnchorMode_None_AsyncProvider_ScrollDoesNotFlash 1/1 ✅ —
AnchorMode_None_ItemExpansionAfterPrepend_NoGap 4/4 ✅ —
AnchorMode_None_LargeAppendAtBottom_DoesNotFollowToBottom 4/4 ✅ —
AnchorMode_None_MidList_ViewportStable 2/2 ✅ —
AnchorMode_None_PrependAtTop_ViewportStaysStable 4/4 ✅ —
AnchorMode_Start_AppendAtBottom_ViewportStable 2/2 ✅ —
AnchorMode_Start_LargeAppendAtBottom_DoesNotFollowToBottom 4/4 ✅ —
AnchorMode_Start_LargePrependAtTop_StillShowsNewItems 4/4 ✅ —
AnchorMode_Start_MidList_ViewportStable 2/2 ✅ —
AnchorMode_Start_PrependAfterLeavingTop_DoesNotReengage 4/4 ✅ —
AnchorMode_Start_PrependAtTop_NewItemsVisible 4/4 ✅ —
AnchorMode_Start_SmallAppendAtBottom_ViewportStable 2/2 ✅ —
AnchorMode_Start_SmallDataset_PrependAfterScrollingDownAFewRows_DoesNotReengage 2/2 ✅ —
AnchorMode_Top_AppendKeepsViewportStable 6/6 ✅ —
AnchorMode_VariableHeight_EndKeyFromTop_JumpsToBottom 0/2 ❌ (anchorMode "0"=None, "1"=Start)
AnchorMode_WindowScroll_End_AppendAtBottom_ViewportFollows 4/4 ✅ —
AnchorMode_WindowScroll_End_MidList_ViewportStable 2/2 ✅ —
AnchorMode_WindowScroll_End_PrependAtTop_ViewportStaysStable 4/4 ✅ —
AnchorMode_WindowScroll_EndKeyJumpsToBottom 3/3 ✅ —
AnchorMode_WindowScroll_HomeKeyJumpsToTop 3/3 ✅ —
AnchorMode_WindowScroll_None_LargeAppendAtBottom_DoesNotFollowToBottom 3/4 ❌ (variableHeight: False, useItemsProvider: True)
AnchorMode_WindowScroll_None_MidList_ViewportStable 2/2 ✅ —
AnchorMode_WindowScroll_None_PrependAtTop_ViewportStaysStable 4/4 ✅ —
AnchorMode_WindowScroll_Start_AppendAtBottom_ViewportStable 2/2 ✅ —
AnchorMode_WindowScroll_Start_MidList_ViewportStable 2/2 ✅ —
AnchorMode_WindowScroll_Start_PrependAtTop_NewItemsVisible 4/4 ✅ —
EndAnchoredAppend_IssuesExactlyTwoProviderCalls_AdvancingToTail 1/1 ✅ —
InitialIndex_BeyondCount_ClampsToEnd 1/1 ✅ —
InitialIndex_OpensAtTargetWithRealContent 6/6 ✅ —
QuickGrid_AnchorMode_Bottom_AppendKeepsViewportStable 4/4 ✅ —
QuickGrid_AnchorMode_Bottom_PrependKeepsViewportStable 5/5 ✅ —
QuickGrid_AnchorMode_DefaultComparer_Items_PrependKeepsViewportStable 1/1 ✅ —
QuickGrid_AnchorMode_End_AppendAfterLeavingBottom_DoesNotReengage 2/2 ✅ —
QuickGrid_AnchorMode_End_LargeAppendAtBottom_StillFollows 2/2 ✅ —
QuickGrid_AnchorMode_End_MidList_ViewportStable 1/1 ✅ —
QuickGrid_AnchorMode_End_PrependAtTop_ViewportStaysStable 1/1 ✅ —
QuickGrid_AnchorMode_EndKeyJumpsToBottom 5/5 ✅ —
QuickGrid_AnchorMode_HomeKeyJumpsToTop 6/6 ✅ —
QuickGrid_AnchorMode_MidList_AppendKeepsViewportStable 4/4 ✅ —
QuickGrid_AnchorMode_NearTop_AppendKeepsViewportStable 6/6 ✅ —
QuickGrid_AnchorMode_NearTop_PrependKeepsViewportStable 5/5 ✅ —
QuickGrid_AnchorMode_None_AsyncProvider_PrependKeepsViewportStable 1/1 ✅ —
QuickGrid_AnchorMode_None_AsyncProvider_ScrollDoesNotFlash 1/1 ✅ —
QuickGrid_AnchorMode_None_LargeAppendAtBottom_DoesNotFollowToBottom 2/2 ✅ —
QuickGrid_AnchorMode_None_MidList_ViewportStable 2/2 ✅ —
QuickGrid_AnchorMode_None_PrependAtTop_ViewportStaysStable 2/2 ✅ —
QuickGrid_AnchorMode_Start_LargeAppendAtBottom_DoesNotFollowToBottom 1/1 ✅ —
QuickGrid_AnchorMode_Start_MidList_ViewportStable 2/2 ✅ —
QuickGrid_AnchorMode_Start_PrependAfterLeavingTop_DoesNotReengage 2/2 ✅ —
QuickGrid_AnchorMode_Start_PrependAtTop_NewItemsVisible 2/2 ✅ —
QuickGrid_AnchorMode_Top_AppendKeepsViewportStable 5/5 ✅ —
QuickGrid_CanJumpToEndAndStart 1/1 ✅ —
ScrollToItem_AnchorStart_AtTop_LandsAtTarget 1/1 ✅ —
ScrollToItem_AsyncProvider_VariableHeight_WithDelay_ReachesTarget 2/2 ✅ —
ScrollToItem_ExternalCancellation_TaskCancels 1/1 ✅ —
ScrollToItem_FixedHeight_LandsAtTop 1/1 ✅ —
ScrollToItem_ForwardThenBackward 1/1 ✅ —
ScrollToItem_MaxIntIndex_ScrollsToLast 1/1 ✅ —
ScrollToItem_NegativeIndex_ScrollsToTop 1/1 ✅ —
ScrollToItem_RapidCalls_OnlyLastTargetReached 1/1 ✅ —
ScrollToItem_UserScrollDuringProviderFetch_UserScrollWins 1/1 ✅ —
ScrollToItem_VariableHeight_LandsAtTop 1/1 ✅ —
ScrollToItem_WithProviderDelay_NoPlaceholderAtTarget 1/1 ✅ —
WindowScroll_ScrollToItem_LandsAtTarget 1/1 ✅ —

Fix

  1. AnchorMode_VariableHeight_EndKeyFromTop_JumpsToBottom (anchorMode 0=None, 1=Start)
    Bug: convergence mechanism worked for placeholders only, end jump lands at the bottom only when placeholders are loaded, when real items load it bumps back up. The re-pinning mechanism designed for this situations was enabled only for End anchor mode.
    Fix: All modes use re-pinning mechanism when placeholder->items transition turnes out to grow scrollHeight (so the real items were bigger than placeholders). 7b24733

  2. AnchorMode_End_HomeKeyFromBottom_JumpsToTop (variableHeight True/False)
    Bug: In End mode with provider with delay, at the bottom of the list user wants to jump Home but after a brief jump up, the convergence mechanism pulls the scroll back down to the end of the list. It's because bottomTracking.reached variable was sticky-true, never flipped back.
    Fix: disable auto-follow mechanism for all modes on Home jump. 5c9ca3f

  3. AnchorMode_End_PrependAtTop_ViewportStaysStable(variableHeight: False, useItemsProvider: True) started failing after we merged this PR with main taht had changes from Fix Virtualize scroll jump from native/JS anchoring double-compensation #67934. It revealed a blind spot of native anchoring: when at scrollTop=0 (so topmost), the anchoring won't get triggered by prepend - it's supressed by design. That's why we need 83bac7a to apply manual anchoring for that case.

@ilonatommy ilonatommy self-assigned this Jul 22, 2026
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components feature-blazor-virtualization This issue is related to the Blazor Virtualize component labels Jul 22, 2026
…om deterministic - wait for the placeholders to transform to real items, only then scroll down and check if the initial landing was at the bottom or bumped up.
…-render

In End anchor mode, bottomTracking.reached is sticky-true so the bottom
re-pin (scrollTop = scrollHeight) re-fires on every render. After the user
pressed Home, an async ItemsProvider re-render would re-engage that re-pin
and pull the viewport back to the bottom, so item 0 never became visible
(one Home press should reach the top). The Home handler only cleared the
follow state for non-End modes, leaving End mode's sticky state intact.
…ollowToBottom

The test clicked "Append 100 items" and immediately measured the gap between
the viewport and the bottom.  With an async ItemsProvider, list only grows inside the provider callback
(Task.Yield + 500ms delay), so the assertion ran before scrollHeight had
grown. The gap was ~0, falsely looking like None mode had followed to the
bottom. Wait for scrollHeight to grow by the appended items before asserting the
viewport stayed in place.
@ilonatommy ilonatommy added this to the 11.0-rc1 milestone Jul 23, 2026
@ilonatommy
ilonatommy marked this pull request as ready for review July 24, 2026 08:44
@ilonatommy
ilonatommy requested a review from a team as a code owner July 24, 2026 08:44
Copilot AI review requested due to automatic review settings July 24, 2026 08:44

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.

Pull request overview

This PR updates the Blazor Virtualize/QuickGrid E2E test matrix to consistently exercise ItemsProvider behavior under realistic latency, and fixes a few latency-revealed scroll/anchoring behaviors in the JS Virtualize implementation.

Changes:

  • Updated Virtualize.ts bottom-follow and anchor snapshot behavior to handle delayed provider scenarios and Home/End jump interactions more reliably.
  • Added/extended test asset toggles (delay controls) to simulate provider latency for Virtualize and QuickGrid scenarios.
  • Refactored E2E tests to enable provider delay for ItemsProvider paths by default, and added targeted regression tests for delayed Home/End behaviors.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Components/Web.JS/src/Virtualize.ts Adjusts follow/pinning and anchor snapshot logic to fix delayed-provider scroll/anchoring issues.
src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Virtualization/VirtualizeAppendRepro.razor Adds query-configurable provider delay for server-rendering append repro coverage.
src/Components/test/testassets/BasicTestApp/VirtualizationAnchorModeWindowScroll.razor Adds UI toggle to simulate provider delay in window-scroll anchor mode test asset.
src/Components/test/testassets/BasicTestApp/QuickGridTest/QuickGridVariableHeightComponent.razor Adds UI toggle to simulate provider delay in QuickGrid variable-height test asset.
src/Components/test/E2ETest/Tests/VirtualizationTest.cs Enables delay for ItemsProvider-based tests, refactors mounting helpers, and adds new delayed Home/End regression tests.
src/Components/test/E2ETest/ServerRenderingTests/VirtualizationRenderModesTest.cs Adds provider delay to the server-rendering append test navigation URL.

Comment thread src/Components/Web.JS/src/Virtualize.ts Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@ilonatommy
ilonatommy requested a review from dariatiurina July 24, 2026 13:58

@dariatiurina dariatiurina 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.

Great refactoring! Virtualize.ts is now a joy to look at. Thank you so much!

@ilonatommy
ilonatommy enabled auto-merge (squash) July 24, 2026 15:10
@ilonatommy
ilonatommy merged commit 0b5f8d8 into dotnet:main Jul 24, 2026
26 checks passed
@ilonatommy

Copy link
Copy Markdown
Member Author

/backport to release/11.0-preview7

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0-preview7 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@ilonatommy backporting to release/11.0-preview7 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: All ItemProvider tests should use delay to reproduce real life scenario.
Using index info to reconstruct a base tree...
M	src/Components/test/E2ETest/Tests/VirtualizationTest.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Components/test/E2ETest/Tests/VirtualizationTest.cs
CONFLICT (content): Merge conflict in src/Components/test/E2ETest/Tests/VirtualizationTest.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 All ItemProvider tests should use delay to reproduce real life scenario.
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

akoeplinger pushed a commit that referenced this pull request Jul 27, 2026
…67959) (#68036)

* All ItemProvider tests should use delay to reproduce real life scenario.

* Make failures of `AnchorMode_VariableHeight_EndKeyFromTop_JumpsToBottom deterministic - wait for the placeholders to transform to real items, only then scroll down and check if the initial landing was at the bottom or bumped up.

* Fix Virtualize End-key not converging to true bottom in None/Start anchor modes.

* Fix Virtualize End-mode Home key not converging to top after async re-render

* Fix race in AnchorMode_WindowScroll_None_LargeAppendAtBottom_DoesNotFollowToBottom

* Native anchoring has one blind spot: topmost scroll position (https://www.w3.org/TR/css-scroll-anchoring-1/). We have to use manual anchoring then.

* When we don't have container (document/window scroll scenarios) then native scroll works fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components feature-blazor-virtualization This issue is related to the Blazor Virtualize component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants