diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Todo/TodoPage.razor.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Todo/TodoPage.razor.cs index 72769a9eac..5928e7ad37 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Todo/TodoPage.razor.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/Todo/TodoPage.razor.cs @@ -17,7 +17,7 @@ public partial class TodoPage private string? underEditTodoItemTitle; private string newTodoTitle = string.Empty; private ConfirmMessageBox confirmMessageBox = default!; - private IList allTodoItems = default!; + private IList allTodoItems = []; private IList viewTodoItems = default!; private List> sortItems = []; private BitSearchBox searchBox = default!; diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/AppRenderMode.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/AppRenderMode.cs index 829624d6f8..a30f825a69 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/AppRenderMode.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/AppRenderMode.cs @@ -1,5 +1,5 @@ //-:cnd:noEmit -using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web; namespace Boilerplate.Client.Core.Services; @@ -7,13 +7,15 @@ public static class AppRenderMode { public static readonly bool PrerenderEnabled = false; - private static IComponentRenderMode Auto { get; } = new InteractiveAutoRenderMode(PrerenderEnabled); - private static IComponentRenderMode BlazorWebAssembly { get; } = new InteractiveWebAssemblyRenderMode(PrerenderEnabled); - private static IComponentRenderMode BlazorServer { get; } = new InteractiveServerRenderMode(PrerenderEnabled); + // https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes#render-modes + public static IComponentRenderMode Auto { get; } = new InteractiveAutoRenderMode(PrerenderEnabled); + public static IComponentRenderMode BlazorWebAssembly { get; } = new InteractiveWebAssemblyRenderMode(PrerenderEnabled); + public static IComponentRenderMode BlazorServer { get; } = new InteractiveServerRenderMode(PrerenderEnabled); + public static IComponentRenderMode? StaticSsr { get; } = null /*Pre-rendering without interactivity*/; public static IComponentRenderMode NoPrerenderBlazorWebAssembly => new InteractiveWebAssemblyRenderMode(prerender: false); - public static IComponentRenderMode Current => - AppEnvironment.IsDev() + public static IComponentRenderMode? Current => + AppEnvironment.IsDev() ? BlazorServer // For better development experience. : Auto; // For better production experience. diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/PrerenderStateService.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/PrerenderStateService.cs index 0c43c8e43c..80168494ed 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/PrerenderStateService.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Services/PrerenderStateService.cs @@ -13,8 +13,13 @@ public class PrerenderStateService : IPrerenderStateService, IAsyncDisposable private readonly PersistentComponentState? persistentComponentState; private readonly ConcurrentDictionary values = new(); + private static bool noPersistant = AppRenderMode.Current == AppRenderMode.StaticSsr || + AppRenderMode.PrerenderEnabled is false || + AppPlatform.IsBlazorHybrid; + public PrerenderStateService(PersistentComponentState? persistentComponentState = null) { + if (noPersistant) return; subscription = persistentComponentState?.RegisterOnPersisting(PersistAsJson, AppRenderMode.Current); this.persistentComponentState = persistentComponentState; } @@ -24,8 +29,7 @@ public PrerenderStateService(PersistentComponentState? persistentComponentState [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "") { - if (AppRenderMode.PrerenderEnabled is false || AppPlatform.IsBlazorHybrid) - return await factory(); + if (noPersistant) return await factory(); string key = $"{filePath.Split('\\').LastOrDefault()} {memberName} {lineNumber}"; @@ -34,8 +38,7 @@ public PrerenderStateService(PersistentComponentState? persistentComponentState public async Task GetValue(string key, Func> factory) { - if (AppRenderMode.PrerenderEnabled is false || AppPlatform.IsBlazorHybrid) - return await factory(); + if (noPersistant) return await factory(); if (persistentComponentState!.TryTakeFromJson(key, out T? value)) return value; @@ -46,8 +49,7 @@ public PrerenderStateService(PersistentComponentState? persistentComponentState void Persist(string key, T value) { - if (AppRenderMode.PrerenderEnabled is false || AppPlatform.IsBlazorHybrid) - return; + if (noPersistant) return; values.TryRemove(key, out object? _); values.TryAdd(key, value); @@ -63,8 +65,7 @@ async Task PersistAsJson() public async ValueTask DisposeAsync() { - if (AppRenderMode.PrerenderEnabled is false || AppPlatform.IsBlazorHybrid) - return; + if (noPersistant) return; subscription?.Dispose(); }