ligershark / CoreTemplatePack

A collection of .NET Core project templates
Other
82 stars 17 forks source link

ASP.NET Core Angular 2 template: Web API method (e.g. WeatherForecasts) called twice on F5 #17

Open TarasBanakh opened 7 years ago

TarasBanakh commented 7 years ago

Installed product versions

Description

In ASP.NET Core Angular 2 template the Web API server method WeatherForecasts called twice on browser refresh (F5) of 'http://localhost:5000/fetch-data' page.

Steps to recreate

  1. Add System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10)); in the beginning of Web API method WeatherForecasts. (Or just set a breakpoint in WeatherForecasts and debug it).
  2. Try to refresh (F5) the 'http://localhost:5000/fetch-data' page.

Current behavior

You will notice that WeatherForecasts is called twice: once on the server during server-side prerendering and once from the browser's javascript after the page has being loaded.

Expected behavior

It should be only called once during server-side prerendering.

SteveSandersonMS commented 7 years ago

This is expected. Unlike the Redux template, the Angular app doesn't have an automatic way to transfer state from server to client.

freddy01288 commented 7 years ago

any help for this? I get initial data twice, does anyone know if this happens only in development and not in production ?, it's a serious problem :(