aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Server-side Blazor 0.5.1 doesn't update active class on NavLink element

Open Andrzej-W opened this issue 8 years ago • 7 comments

I have just published "default" server side application to Azure. I have made only one change in WeatherForecastService.cs

return Task.FromResult(Enumerable.Range(1, 500).Select(index => new WeatherForecast

As you can see service now returns 500 instead of 5 forecasts.

We can click on Home and Counter menu links and everything works as expected. Try to click on Fetch data. At first everything works, but active class on NavLink (strictly speaking on <a> element) is not removed from Home or Counter and not added to Fetch data.

http://blazorserwer.azurewebsites.net/

Andrzej-W avatar Jul 28 '18 20:07 Andrzej-W

@Andrzej-W I think you are seeing the same issue that I referenced in aspnet/Blazor#1211; I was OK with adding the JS required by Bootstrap to my project but apparently some of the Bootstrap components will interfere with Blazor.

The suggest route was to consider BlazorStrap.

I am trying to port BlazorStrap from 0.3.0 to 0.5.1 and am having a couple of issues. When I resolve them I'll put out a PR for BlazorStrap.

MarkStega avatar Jul 30 '18 14:07 MarkStega

@MarkStega it is not related to aspnet/Blazor#1211 at all. This is standard project created by VS. It doesn't require any JavaScript.

Problem is visible when I try to return 500 forecasts. When I return 5 or 50 forecasts it works correctly. Probably there is subtle bug somewhere in async code on the server or on the client.

Andrzej-W avatar Jul 30 '18 23:07 Andrzej-W

Seeing this as well... It's not limited to just the navlink. Other simple bindings can fail to update as well, and it's fairly easy to reproduce.

Seems to be some kind of timing issue or race condition.

The problem goes away if you add any kind of delay to the back end:

        public async Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
        {
            await Task.Delay(1); // this line fixes the issue
            var rng = new Random();
            return Enumerable.Range(1, 500).Select(index => new WeatherForecast
            {
                Date = startDate.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            }).ToArray();
        }

Removing the delay causes the problem to re-appear.

srowan avatar Sep 22 '18 02:09 srowan

This problem still exists in 0.6.0

Andrzej-W avatar Oct 02 '18 23:10 Andrzej-W

Any Error message in the console?

vertonghenb avatar Oct 17 '18 17:10 vertonghenb

@vertonghenb I don't see any errors in web browser console.

Andrzej-W avatar Oct 20 '18 14:10 Andrzej-W

@Andrzej-W, did you try to place the NavLink for FetchData between the NavLink for Home and that of the Counter, and see if the issue remains ?

enetstudio avatar Nov 03 '18 18:11 enetstudio