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?