Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor ApplicationState.RegisterOnPersisting callback is never called

$
0
0

I have a blazor app which I have updated to .net 8The app is an Interactive Server application with prerendering enabled.

I am trying to avoid loading data twice (see https://learn.microsoft.com/en-us/aspnet/core/blazor/components/prerender?view=aspnetcore-8.0#persist-prerendered-state)

  [Inject]  protected PersistentComponentState ApplicationState { get; set; }  private PersistingComponentStateSubscription _subscription;  protected override async Task OnInitializedAsync()  {      await base.OnInitializedAsync();      _subscription = ApplicationState.RegisterOnPersisting(() =>      {          ApplicationState.PersistAsJson("TenantData", TenantViewModel);          ApplicationState.PersistAsJson("TenantGroupData", TenantGroupViewModel);          ApplicationState.PersistAsJson("FirstLoadTenantViewModel", FirstLoadTenantViewModel);          return Task.CompletedTask;      }, RenderMode.InteractiveServer);      if (Guid.TryParse(Id, out var parsedTenantId))      {          tenantId = parsedTenantId;          if (ApplicationState.TryTakeFromJson("TenantData", out TenantViewModel cachedTenantData) &&              ApplicationState.TryTakeFromJson("TenantGroupData", out TenantGroupViewModel cachedTenantGroupData) &&              ApplicationState.TryTakeFromJson("FirstLoadTenantViewModel", out TenantViewModel cachedFirstLoadTenantData))          {              TenantViewModel = cachedTenantData;              TenantGroupViewModel = cachedTenantGroupData;              FirstLoadTenantViewModel = cachedFirstLoadTenantData;          }          else          {              await LoadTenantData(tenantId.Value);              // Create a deep copy              FirstLoadTenantViewModel = CloneObject(TenantViewModel);          }  }

My RegisterOnPersisting lambda function never executes even though OnInitializedAsync is called twice.

I suspect that there may be an issue in my "upgrading" between .net versions.

Has anybody else experienced this?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>