Skip to content

Virtualize: reduce JS-to-.NET surface and extract E2E test helpers#65913

Merged
ilonatommy merged 11 commits intodotnet:mainfrom
ilonatommy:follow-up-64964
Mar 24, 2026
Merged

Virtualize: reduce JS-to-.NET surface and extract E2E test helpers#65913
ilonatommy merged 11 commits intodotnet:mainfrom
ilonatommy:follow-up-64964

Conversation

@ilonatommy
Copy link
Copy Markdown
Member

@ilonatommy ilonatommy commented Mar 23, 2026

Follow up for feedback in #64964.

Description

1. Reduce JS→.NET communication surface

Instead of measuring individual item heights via comment-based DOM scanning in JS, derive the average item height server-side from spacerSeparation (already reported by IntersectionObserver).

What changed:

  • Removed measureRenderedItems() and comment-based DOM scanning from Virtualize.ts
  • Simplified IO callback from 5 params to 3: (spacerSize, spacerSeparation, containerSize)
  • Virtualize.cs now computes item height averages using spacerSeparation - (placeholderCount × itemSize) and _lastRenderedItemCount
  • Updated IVirtualizeJsCallbacks, VirtualizeJsInterop, and all unit tests accordingly

2. Extract inline E2E test scripts into helpers

Per review feedback, extracted 3 large inline JavaScript test scripts into reusable private helper methods in VirtualizationTest.cs:

  • ExecuteDetectFlashingScript()
  • ExecuteRapidScrollReversalScript()
  • ExecuteScrollStabilityScript()

3. Align DynamicContent_ExpandingOffScreenItem code with the name

Test's name indicates that it's checking expansion of elements out of DOM while it's not. The list had 30 items and new default for OverscanCount = 15 so all the items were in DOM. This PR extends the list to be sure test is checking what it should. For items in DOM we have DynamicContent_ItemHeightChangesUpdateLayout.

@ilonatommy ilonatommy added this to the 11.0-preview4 milestone Mar 23, 2026
@ilonatommy ilonatommy self-assigned this Mar 23, 2026
@ilonatommy ilonatommy requested a review from a team as a code owner March 23, 2026 10:11
Copilot AI review requested due to automatic review settings March 23, 2026 10:11
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Mar 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors Blazor Virtualize to reduce the JS→.NET interop surface by removing per-item height measurement in JS, and instead deriving measurements in .NET from spacerSeparation plus server-side render state. It also extracts large inline E2E JavaScript snippets into reusable helpers.

Changes:

  • Removes comment-delimited DOM scanning and measureRenderedItems() from Virtualize.ts, shrinking the JS callback payload to 3 parameters.
  • Updates Virtualize interop contracts (IVirtualizeJsCallbacks, VirtualizeJsInterop, Virtualize.cs) and adjusts how running averages are computed.
  • Refactors E2E virtualization tests to use extracted JavaScript helper methods.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Components/test/E2ETest/Tests/VirtualizationTest.cs Extracts inline E2E JS snippets into private helper methods.
src/Components/Web/test/Virtualization/VirtualizeTest.cs Updates unit tests for the new 3-parameter interop callbacks and adjusts measurement-related assertions/comments.
src/Components/Web/src/Virtualization/VirtualizeJsInterop.cs Updates JS-invokable callbacks to accept 3 parameters and forwards to owner.
src/Components/Web/src/Virtualization/Virtualize.cs Removes comment delimiters, computes measurements from spacerSeparation, and updates callback handling.
src/Components/Web/src/Virtualization/IVirtualizeJsCallbacks.cs Updates the callback interface signatures to 3 parameters.
src/Components/Web.JS/test/Virtualize.test.ts Removes tests for deleted measureRenderedItems() and replaces with export-surface checks.
src/Components/Web.JS/src/Virtualize.ts Removes measureRenderedItems() and reduces invokeMethodAsync args to 3.

Comment thread src/Components/Web/test/Virtualization/VirtualizeTest.cs Outdated
Comment thread src/Components/Web/test/Virtualization/VirtualizeTest.cs
Comment thread src/Components/Web/test/Virtualization/VirtualizeTest.cs
Comment thread src/Components/Web/test/Virtualization/VirtualizeTest.cs
Comment thread src/Components/Web/src/Virtualization/Virtualize.cs
Comment thread src/Components/Web/test/Virtualization/VirtualizeTest.cs Outdated
@ilonatommy ilonatommy requested a review from javiercn March 24, 2026 09:09
ilonatommy and others added 3 commits March 24, 2026 11:41
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Scrolling to a fixed offset (2000px) left most items in the 'after'
spacer region, so itemsBefore was only 1 and item 2 remained in the
rendered window. Scrolling to the very bottom ensures itemsBefore is
large enough that item 2 is virtualized out of the DOM.

Also removes temporary CI diagnostic code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great simplification!

I believe the interop APIs that we have in previous versions remain the same, is that correct? (we already had all the information we needed to do this server side?)

@ilonatommy
Copy link
Copy Markdown
Member Author

I believe the interop APIs that we have in previous versions remain the same, is that correct? (we already had all the information we needed to do this server side?)

Yes, the API is same as before we merged #64964 so this PR removes all the extensions the previous PR added.

@ilonatommy ilonatommy enabled auto-merge (squash) March 24, 2026 15:31
@ilonatommy ilonatommy merged commit 002e2fd into dotnet:main Mar 24, 2026
25 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants