Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor server side onmousemove causes component rerender #17169

Closed
rborosak opened this issue Nov 16, 2019 · 1 comment
Closed

Blazor server side onmousemove causes component rerender #17169

rborosak opened this issue Nov 16, 2019 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@rborosak
Copy link

I have added onmousemove to a div. It is bound to a method that does some calculation if the mouse is pressed but I have noticed that the component rerenders even when the metod is empty.

<div @onmousemove="@OnMouseMove">I'm a div content</div>

@code{
    public void OnMouseMove(MouseEventArgs e){
        //empty method but it causes a rerender
    }

    protected override void OnAfterRender(bool firstRender){
        Debug.WriteLine("Rendered!")
    }
}

I have tried to change onmousemove="@OnMouseMove" to onmousemove="@((e)=>OnMouseMove(e))" but I still get the same result.
Every time a mouse enters a div, "Rendered" is written to console meaning that the component has rerendered.

Why is this happening? Is there any workaround?

I'm using Blazor server side with ASP.NET Core version 3.0 and VisualStudio 2019.

@rborosak rborosak changed the title onmousemove causes component rerender Blazor server side onmousemove causes component rerender Nov 16, 2019
@blowdart blowdart added the area-blazor Includes: Blazor, Razor Components label Nov 18, 2019
@javiercn
Copy link
Member

@rborosak thanks for contacting us.

Blazor triggers an automatic re-render of a component as part of dispatching an event to it. If you want to alter this behavior you can override the ShouldRender method on ComponentBase to selectively choose when to re-render the component.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

3 participants