Skip to content

Fix QuickGrid None-mode async-provider prepend viewport drift - #67931

Merged
ilonatommy merged 1 commit into
dotnet:mainfrom
ilonatommy:fix-quick-grid-anchoring-tests
Jul 21, 2026
Merged

ilonatommy merged 1 commit into
dotnet:mainfrom
ilonatommy:fix-quick-grid-anchoring-tests

Conversation

@ilonatommy

@ilonatommy ilonatommy commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Contributes to #67865.

QuickGrid renders a <table>, so Virtualize uses the manual (non-native) scroll-anchoring path because native one wouldn't work reliably in a table layout. On a prepend with an async ItemsProvider, the viewport drifted (top row jumped, e.g. 90->80) instead of staying stable.

Two things contributed to the problem:

  1. Captured the anchor before the data arrived. While the provider was still fetching, the grid briefly showed a placeholder gap at the top. Virtualize captured that gap as its "keep this row in place" reference, so the follow-up scroll correction was computed against the wrong row.
  2. Premature scroll callback undid the shift. On Server the scroll correction happens over an async round-trip. In that gap, a scroll observer fired and recalculated the window from a stale position, reverting the prepend before the correction landed.

Fixes, both scoped to AnchorMode.None:

  • Ignore those mid-load snapshots and keep the last stable one.
  • Hold the "restore in progress" flag across the round-trip so the stray callback is skipped.
New QuickGrid AnchorMode test coverage summary, updated after #67783
Op · Position · Source None Start End
⬆️ · Exact top · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬆️ · Exact top · Prov V ✅ · QG ✅ 0/5 (fixed) V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ❌ 1/5
⬆️ · Exact top · Prov+delay V n/a · QG ✅ 0/5 (fixed) V n/a · QG 🆕 ✅ 0/5 V n/a · QG 🆕 ❌ 4/5
⬆️ · Near-top ~200px · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬆️ · Near-top ~200px · Prov V ✅ · QG ✅ 0/5 (fixed) V ✅ · QG 🆕 ❌ 2/5 V ✅ · QG 🆕 ❌ 1/5
⬆️ · Near-top ~200px · Prov+delay V n/a · QG ✅ 0/5 (fixed) V n/a · QG 🆕 ❌ 3/5 V n/a · QG 🆕 ❌ 4/5
⬆️ · Mid-list · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬆️ · Mid-list · Prov V ✅ · QG ✅ 0/5 (fixed) V ✅ · QG 🆕 ❌ 2/5 V ✅ · QG 🆕 ❌ 4/5
⬆️ · Mid-list · Prov+delay V ✅ · QG ✅ 0/5 (fixed, None_AsyncProvider [Fact]) — —
⬆️ · Bottom · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬆️ · Bottom · Prov V ✅ · QG ✅ 0/5 (fixed) V ✅ · QG 🆕 ❌ 4/5 V ✅ · QG 🆕 ❌ 1/5
⬆️ · After leaving top · Items — V ✅ · QG 🆕 ✅ 0/5 —
⬆️ · After leaving top · Prov — V ✅ · QG 🆕 ✅ 0/5 —
⬇️ · Near-top · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬇️ · Near-top · Prov V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬇️ · Top · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬇️ · Top · Prov V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ❌ 1/6
⬇️ · Mid-list · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬇️ · Mid-list · Prov V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬇️ · Bottom · Items V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬇️ · Bottom · Prov V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⬇️ · After leaving bottom · Items — — V ✅ · QG 🆕 ✅ 0/5
⬇️ · After leaving bottom · Prov — — V ✅ · QG 🆕 ✅ 0/5
⬇️ LARGE (100) · Bottom · Items — V ✅ · QG 🆕 ❌ WASM V ✅ · QG 🆕 ✅ 0/5
⬇️ LARGE (100) · Bottom · Prov — V ✅ · QG 🆕 ✅ 0/5 V ✅ · QG 🆕 ✅ 0/5
⌨️ Home key → top · Items/Prov — · QG 🆕 ✅ 0/5 — · QG 🆕 ✅ 0/5 — · QG 🆕 ✅ 0/5
⌨️ End key → bottom · Items/Prov — · QG 🆕 ✅ 0/5 — · QG 🆕 ✅ 0/5 — · QG 🆕 ❌ 1/6 (CI/Mono)

@ilonatommy ilonatommy added this to the 11.0-preview7 milestone Jul 21, 2026
@ilonatommy ilonatommy self-assigned this Jul 21, 2026
Copilot AI review requested due to automatic review settings July 21, 2026 08:02
@ilonatommy
ilonatommy requested a review from a team as a code owner July 21, 2026 08:02
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components feature-blazor-virtualization This issue is related to the Blazor Virtualize component feature-blazor-quickgrid labels Jul 21, 2026

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

Fixes a QuickGrid + Virtualize regression in AnchorMode.None when using an async ItemsProvider, where prepends could cause viewport drift due to (1) capturing an anchor snapshot during an in-flight placeholder gap and (2) a spacer callback firing during the server-side restore round-trip.

Changes:

  • Keep _pendingAnchorRestore set during RestoreAnchorAsync() for AnchorMode.None so spacer callbacks are suppressed across the async restore.
  • In the JS manual-anchoring path for AnchorMode.None, ignore “mid-load gap” anchor snapshots and keep the last stable snapshot instead.
  • Re-enable previously disabled/quarantined QuickGrid E2E coverage for the async-provider prepend scenarios in AnchorMode.None.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Components/Web/src/Virtualization/Virtualize.cs Defers clearing _pendingAnchorRestore during restore for AnchorMode.None to prevent stray callbacks from undoing the correction.
src/Components/Web.JS/src/Virtualize.ts Skips overwriting an existing anchor snapshot in manual anchoring when a large transient gap is detected during async loads in None mode.
src/Components/test/E2ETest/Tests/VirtualizationTest.cs Un-quarantines / re-enables None-mode async-provider prepend stability test coverage for QuickGrid.

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-quickgrid 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