havit / Havit.Blazor

Free Bootstrap 5 components for ASP.NET Blazor + optional enterprise-level stack for Blazor development (gRPC code-first, layered architecture, localization, auth, ...)
https://havit.blazor.eu
MIT License
519 stars 69 forks source link

[doc] PersistentComponentState while prerendering: There is already a persisted object under the same key 'ColorMode' #948

Closed hakenr closed 1 week ago

hakenr commented 1 week ago
fail: Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager[1000]
      There was an error executing a callback while pausing the application.
      System.ArgumentException: There is already a persisted object under the same key 'ColorMode'
         at Microsoft.AspNetCore.Components.PersistentComponentState.PersistAsJson[TValue](String key, TValue instance)
         at Havit.Blazor.Documentation.Shared.Components.DocColorMode.DocColorModeSwitcher.PersistMode() in E:\source\002.HFW-Havit.Blazor\Havit.Blazor.Documentation\Shared\Components\DocColorMode\DocColorModeSwitcher.razor.cs:line 40
         at Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.<PauseAsync>g__ExecuteCallback|11_0(Func`1 callback, ILogger`1 logger)
hakenr commented 1 week ago

The issue with the DocColorModeSwitcher component is that it was originally designed to appear only once on a page. Now that we've added the NavBar with a second instance, the two instances:

We have to create a scoped service which will handle the state for both instances (or possibly use existing IDocColorModeResolver).