Skip to content

Theme service throws an exception when running in Blazor Server mode #2

Description

@cornelha

Describe the bug
When running in Blazor Server Rendering mode the Theme Service throws the following exception:

RR.Blazor.Services.BlazorThemeService: Warning: Failed to load theme from storage, clearing and using default

System.InvalidOperationException: JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.BeginInvokeJS(Int64 asyncHandle, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](String identifier, CancellationToken cancellationToken, Object[] args)
   at Blazored.LocalStorage.BrowserStorageProvider.GetItemAsync(String key, CancellationToken cancellationToken)
   at Blazored.LocalStorage.LocalStorageService.GetItemAsync[T](String key, CancellationToken cancellationToken)
   at RR.Blazor.Services.BlazorThemeService.LoadThemeFromStorageAsync() in D:\TestProjects\RRBlazingDemo\RR.Blazor\Services\BlazorThemeService.cs:line 260
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
RR.Blazor.Services.BlazorThemeService: Error: Failed to apply theme

To Reproduce
Steps to reproduce the behavior:
I have provided an example with a public repo found here :

https://github.com/cornelha/RRBlazingDemo

Expected behavior
The application should load the components and display the UI as seen in the examples and screenshots

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome
  • Version: 139.0.7258.67

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions