Skip to content

Blazor is calling properties get on every user interaction #9863

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

Closed
alexandrereyes opened this issue Apr 30, 2019 · 3 comments
Closed

Blazor is calling properties get on every user interaction #9863

alexandrereyes opened this issue Apr 30, 2019 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design.

Comments

@alexandrereyes
Copy link

Why Blazor calls property get every time a user interact with some component?
For example:

@FullName

<button onclick="@(() => Console.Write(""))">button</button>

@functions{


    public string GivenNames { get; set; }
    public string FamilyName { get; set; }
    public string FullName => $"{GivenNames} {FamilyName}";

}

When I hit the button, FullName is recalculated again, why does this happen? The button above doesn't interact with anything.

This can lead to a huge performance problem.

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 30, 2019
@enetstudio
Copy link

I think it is because the StateHasChanged method is called automatically after the click event to re-render the component. In other words, this is an inherent limitation you should live with.

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components and removed area-blazor Includes: Blazor, Razor Components labels May 1, 2019
@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@arivera12
Copy link

Every time a blazor event is fired StateHasChanged gets called. I know this is not the way like angular or vuejs does. Angular and Vuejs watch properties to change to then call the re render process, but blazor doesn't seem to work that way.

@rynowak
Copy link
Member

rynowak commented May 26, 2019

This is the expected behavior. Handling an event will trigger a re-render which will evaluate all of your markup. If you want to customize when a component re-renders you can override ShouldRender()

@rynowak rynowak closed this as completed May 26, 2019
@rynowak rynowak added the ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. label May 26, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 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 ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design.
Projects
None yet
Development

No branches or pull requests

6 participants