Skip to content

Fix Virtualize AnchorMode=End re-engaging bottom after user scrolls up. - #67555

Merged
ilonatommy merged 5 commits into
mainfrom
fix-end-mode
Jul 3, 2026
Merged

ilonatommy merged 5 commits into
mainfrom
fix-end-mode

Conversation

@ilonatommy

@ilonatommy ilonatommy commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

The Aspire dashboard "Console logs" view (a line-numbered LogViewer using <Virtualize AnchorMode="End">) would snap the viewport back to the bottom whenever new lines arrived, even after the user had scrolled up to read earlier output. It was intermittent and only happened "on first visit" because it stopped once the log grew past a threshold.

Reason for the failure

It happens when nothing is virtualized away, easy to achieve with high OverscanCount value. On append, the runtime (Virtualize.cs ShouldScrollToBottomForAppend) asks the JS side to pin to the bottom while the total item count is still <= the visible item capacity. scrollToBottom() in Virtualize.ts honored that request unconditionally: it had no check whether the user was actually "following" the bottom, so an append re-engaged End-follow and moved the viewport down even when the user had deliberately scrolled up. Once the log exceeded the visible capacity, appends no longer requested a pin, which is why the bug only showed up early ("first visit / few lines").

Fix

Track an followingBottom flag that reflects whether the End-mode viewport is currently pinned at the bottom:

  • initialized true when AnchorMode includes End,
  • updated ONLY on user scrolls (handleScroll): true if the viewport is at the bottom, so scrolling up clears it,
  • reset when the anchor mode changes (setAnchorMode).
    scrollToBottom() now pins to the bottom only when followingBottom is true, so an append re-engages the bottom only if the user was still there; otherwise their scroll position is preserved.

Before

EndAnchorModeVirtualize_before.mp4

After

EndAnchorModeVirtualize.1.mp4

Copilot AI review requested due to automatic review settings July 2, 2026 07:53
@ilonatommy
ilonatommy requested a review from a team as a code owner July 2, 2026 07:54
@ilonatommy ilonatommy self-assigned this Jul 2, 2026
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components feature-blazor-virtualization This issue is related to the Blazor Virtualize component labels Jul 2, 2026
@ilonatommy ilonatommy added this to the 11.0-preview7 milestone Jul 2, 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

This pull request fixes an intermittent Blazor Virtualize behavior when using AnchorMode="End": after a user scrolls up, appends should no longer “snap” the viewport back to the bottom in the small-dataset / large-overscan regime (as observed in Aspire Dashboard console logs).

Changes:

  • Track an End-follow state on the JS side and gate scrollToBottom() so appends only pin to bottom when the user is actively following the end.
  • Extend the BasicTestApp anchor-mode playground with a “console scenario” (overscan + small dataset) for easier reproduction.
  • Add an E2E regression test covering “small dataset + scroll up a few rows + append does not re-engage”.

Reviewed changes

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

Show a summary per file
File Description
src/Components/Web.JS/src/Virtualize.ts Adds endFollowActive tracking and conditions scrollToBottom() on that follow state.
src/Components/test/testassets/BasicTestApp/VirtualizationAnchorMode.razor Adds overscan configurability and a console-like scenario setup button for repro.
src/Components/test/testassets/BasicTestApp/Index.razor Adds a navigation option to a console-logs-style viewer component.
src/Components/test/testassets/BasicTestApp/ConsoleLogsViewer.razor Adds a console-like streaming log viewer to manually observe End anchoring behavior.
src/Components/test/E2ETest/Tests/VirtualizationTest.cs Adds an E2E regression test for the small-dataset End anchoring append behavior.

Comment thread src/Components/Web.JS/src/Virtualize.ts Resolved

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

Looks great!

@ilonatommy
ilonatommy enabled auto-merge (squash) July 2, 2026 12:48
@ilonatommy

Copy link
Copy Markdown
Member Author

/ba-g template tests failures cannot be related

@ilonatommy
ilonatommy merged commit f90c4cb into main Jul 3, 2026
24 of 25 checks passed
@ilonatommy
ilonatommy deleted the fix-end-mode branch July 3, 2026 10:55
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