MouseEvent causes re-render on every click?
See original GitHub issueDescribe the bug
Clicking on a component causes a re-render of that component.
Example, if I click anywhere within a component on a page, my debug log begins with this:
[15:47:36 0HLS5HMITRJSV:00000001 DBG] <Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher> Received hub invocation: InvocationMessage { InvocationId: "", Target: "DispatchBrowserEvent", Arguments: [ {"browserRendererId":0,"eventHandlerId":12,"eventArgsType":"mouse","eventFieldInfo":null}, {"type":"click","detail":1,"screenX":2343,"screenY":281,"clientX":423,"clientY":178,"button":0,"buttons":0,"ctrlKey":false,"shiftKey":false,"altKey":false,"metaKey":false} ], StreamIds: [ ] }.
[15:47:36 0HLS5HMITRJSV:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Handling event {"Id": 5, "Name": "HandlingEvent"} of type 'MouseEventArgs'
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 16 of type GridBlazor.Pages.GridComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 17 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 29 of type GridBlazor.Pages.GridExtSortHeaderComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 18 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 30 of type GridBlazor.Pages.GridHeaderComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 19 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 31 of type GridBlazor.Pages.GridHeaderComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 20 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 32 of type GridBlazor.Pages.GridHeaderComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 21 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 33 of type GridBlazor.Pages.GridHeaderComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 22 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 34 of type GridBlazor.Pages.GridHeaderComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 23 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 35 of type GridBlazor.Pages.GridHeaderComponent`1[Model.EventNotification]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 24 of type Microsoft.AspNetCore.Components.CascadingValue`1[GridBlazor.Pages.GridComponent`1[Model.EventNotification]]
[15:50:50 0HLS5HOV76P1D:00000001 DBG] <Microsoft.AspNetCore.Components.RenderTree.Renderer> Rendering component 36 of type GridBlazor.Pages.GridHeaderComponent`1[Model.EventNotification]
...
And then after that it re-renders that component. For small components this isnt a problem, but for others that are for example, grids, it becomes a performance issue where simply clicking within the grid or any part of it will cause a complete re-render of the entire grid.
Is this intended?
Edit:
I realize I can override ShouldRender, but right now ShouldRender doesn’t contain any information as to where the call came from or how the request to render was raised. It would be handy, for example, if ShouldRender had some sort of parameter that would say "Hey, I am asking if I should render because of a MouseClickEvent or a DragEvent etc. Is this out-of-scope for what the team is envisioning for core and should the developer instead implement this on their own end?
Further technical details
- ASP.NET Core version : 3.1
- Include the output of
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.100\
Host (useful for support):
Version: 3.1.0
Commit: 65f04fb6db
.NET Core SDKs installed:
2.1.700 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
- Visual Studio 2019 16.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)

Top Related StackOverflow Question
The
@onclickshould be on the thing you click to filter, not on the grid. If you make that filter UI a component too, the re-render should be on the component clicked + all components inside of it, not parent components. So just the filter, and not the grid.Your scenario sounds very bad though. What is your real scenario?
@mrpmorris your suggestion definitely helps and I have reduced the redundant re-renders but a bunch. Thank you so much.