Allow configuring virtualization spacer element type #42449
Labels
api-approved
API was approved in API review, it can be implemented
area-blazor
Includes: Blazor, Razor Components
feature-prerendering
Issues related to prerendering blazor components
Milestone
Background and Motivation
Blazor's
<Virtualize>
component produces a DOM structure like this:The top and bottom elements there are called "spacers" and their job is to:
The problem is that it's currently hardcoded to use
div
elements for these spacers. While pretty general-purpose, there are some cases wherediv
is not technically allowed, such as directly inside atbody
.In the past we decided it works well enough anyway, since the browser doesn't really care if you put a
div
inside atbody
via JavaScript. However this does cause a problem if you do it in the initial HTML page, such as when prerendering. The browser's HTML parser will think hey that's not right, let me fix that for you and gives you a DOM structure like this:... i.e., it moves the spacers outside the table. This doesn't cause much of a problem because as soon as Blazor starts up interactively, it rebuilds the DOM anyway and puts things in the right places. But during the time between prerendering and interactivity, you may see a flash of malformed content.
Proposed API
Usage Examples
Alternative Designs
We could avoid having this be configurable, and instead JS logic that looks at the actual parent element at runtime and decides whether to use adiv
, atr
, or whatever. That's nice but the main problem is it would be a breaking change. I know some people already are using CSS to target the spacer element to do particular things with it like set a background color in case it becomes visible during fast scrolling.Update: No, that alternative is total nonsense, even ignoring the breaking change aspect. I just realised it wouldn't work in prerendering (as there's no JS running) and the whole point of this fix is to work with prerendering. It has to be done in .NET code. I'm not aware of a sensible alternative design.
Risks
Nothing significant. If people do something nonsensical such as entering an illegal tag name value (e.g., an empty string), the browser will already give them a sensible message at runtime when Blazor tries to use it when constructing an element.
The text was updated successfully, but these errors were encountered: