Aspnetcore: Blazor @ref not updating component

Created on 3 Oct 2019  路  2Comments  路  Source: dotnet/aspnetcore

Describe the bug

When calling a referenced component's functions, the UI isn't being updated.

To Reproduce

  • Using latest ASP .NET Core

Steps to reproduce the behavior:

  1. Reference a component using @ref
  2. Call component member function which modifies the DOM

I made a fiddle that can be used to view this issue https://blazorfiddle.com/s/zkmpjypw
Clicking 'Show from component scope' button works just fine but clicking 'Show using ref' doesn't make the alert show.

If running in the debugger, you'll see that the component's function is called and the variables change but the DOM element is unchanged.

Expected behavior

DOM should reflect changes from @ref'd calls

area-blazor question

Most helpful comment

It is intentional that we don't do this by default. If you call a method on a .NET object, Blazor isn't involved, that's entirely inside your code.

Even if we could intercept that, it's not obvious that we should trigger rerendering - we don't know if the method you called impacts the UI in any way.

All 2 comments

Figured out that StateHasChanged must be called to get the DOM to register these changes, is there any way this could happen automatically?

It is intentional that we don't do this by default. If you call a method on a .NET object, Blazor isn't involved, that's entirely inside your code.

Even if we could intercept that, it's not obvious that we should trigger rerendering - we don't know if the method you called impacts the UI in any way.

Was this page helpful?
0 / 5 - 0 ratings