Back
Open Source

Blazor Virtualize: a restore scroll should not consume the next scroll

ASP.NET Core #70630 fixed a Virtualize scroll-source state bug that could leave the viewport on spacer after an anchor restore. Includes the E2E proof.

JB
Josué Barros
••2 min read

restoreAnchorForShift sets the scroll source to RestoreSnapshot. A later scripted scrollTop assignment or native scrollbar drag can be treated as ProgrammaticScroll, so the rendered window does not move and the viewport shows only spacer.

This is one of the pull requests behind Six merged PRs in 72 hours. The series looks at the failure, the fix and the review evidence, one merge at a time.

The change: +132 / -14 across 5 files. PR 70630.

The bug

That is a state-machine bug, not a layout bug. The DOM has the items, the virtualizer has a range, but the source of the scroll event is classified incorrectly, so the virtualizer ignores the correction that should bring the first rows back.

The reported case was a filtered 1,000-row list. Clearing the filter and clicking Back to top had to render the first rows, but the viewport could stay on empty space.

Why it mattered

Virtualization is a correctness feature: it decides which rows exist in the DOM. When the scroll source is wrong, the page can look blank even though the data is present. Users read that as data loss or a frozen UI.

The fix

Keep restore-related observer callbacks classified as RestoreSnapshot until a later scroll or input changes the source. Ignore a restore scroll only when the scroll position actually changes, so a no-op correction does not consume the next scroll. The count-growth jump described in #70540 stays outside this change.

The evidence

The PR adds VirtualizationFilterGrowth for the reported filtered list and an E2E test where clearing the filter and clicking Back to top must render the first rows. Validation covered JavaScript debug and production builds, a focused TypeScript check, unit tests and 44 targeted Chrome E2E cases across Server and WebAssembly.

What I would repeat

When a UI bug depends on event ordering, write the user action as the test. “Call the method” is not enough. The failing path here is a sequence: filter, clear, click Back to top, assert the first rows exist.

Sources

If this was useful, connect with me on LinkedIn; I write about the bugs behind merged pull requests and the evidence that gets them accepted.

FAQ

What was the Blazor Virtualize bug?
A restore scroll could be reclassified as a programmatic scroll, so the virtualizer ignored the correction and the viewport showed only spacer.
How was it fixed?
Restore-related callbacks stay classified as RestoreSnapshot until a later scroll or input changes the source; no-op corrections do not consume the next scroll.
How was it tested?
With an E2E case for the filtered 1,000-row list and Back to top, plus 44 targeted Chrome cases across Server and WebAssembly.
#aspnetcore#blazor#virtualization#ui#open-source

Join the Newsletter

Subscribe to get my latest content by email.

We won't send you spam. Unsubscribe at any time.