dotnet / dotnet/aspnetcore

Blazor: Component re-renders even when onmousemove is null

Open
#18,118 3 comments 3 reactions 0 assignees View on GitHub
affected-few area-blazor copilot-candidate enhancement feature-rendering Pillar: Technical Debt severity-major
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

Blazor components send a message to the server about mouse-move events even though the `@onmousemove` event callback has been set to null.

It would be useful if, when building the render tree, Blazor wouldn't include events that are null.

Take this example. Modify the SurveyPrompt in a default template.

```


...Omitted for brevity

@code {
..Omitted

private Action OnMouseMove { get; set; } = null;

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
System.Diagnostics.Debug.WriteLine("Rendered SurveyPrompt: " + (OnMouseMove == null));
}
}
```

Because OnMouseMove is null the component doesn't need to re-render every time the mouse moves over it.

This would be useful for components that implement events that the consumer can optionally set.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.