diff --git a/aspnetcore/blazor/components/rendering.md b/aspnetcore/blazor/components/rendering.md index 6a3fd47e55af..6b31a7d08825 100644 --- a/aspnetcore/blazor/components/rendering.md +++ b/aspnetcore/blazor/components/rendering.md @@ -245,3 +245,10 @@ For approaches to manage state, see the following resources: For the state manager approach, C# events are outside the Blazor rendering pipeline. Call on other components you wish to rerender in response to the state manager's events. The state manager approach is similar to the earlier case with in the [previous section](#receiving-a-call-from-something-external-to-the-blazor-rendering-and-event-handling-system). Since the execution call stack typically remains on the renderer's synchronization context, calling isn't normally required. Calling is only required if the logic escapes the synchronization context, such as calling on a or awaiting a with [`ConfigureAwait(false)`](xref:System.Threading.Tasks.Task.ConfigureAwait%2A). For more information, see the [Receiving a call from something external to the Blazor rendering and event handling system](#receiving-a-call-from-something-external-to-the-blazor-rendering-and-event-handling-system) section. + +## WebAssembly loading progress indicator for Blazor Web Apps + + + +A loading progress indicator isn't present in an app created from the Blazor Web App project template. A new loading progress indicator feature is planned for a future release of .NET. In the meantime, an app can adopt custom code to create a loading progress indicator. For more information, see . diff --git a/aspnetcore/blazor/fundamentals/startup.md b/aspnetcore/blazor/fundamentals/startup.md index ff767c0367ec..21e9b4266693 100644 --- a/aspnetcore/blazor/fundamentals/startup.md +++ b/aspnetcore/blazor/fundamentals/startup.md @@ -520,7 +520,128 @@ For more information on CSPs, see ## Client-side loading progress indicators -*This section only applies to Blazor WebAssembly apps.* +A loading progress indicator shows the loading progress of the app to users, indicating that the app is loading normally and that the user should wait until loading is finished. + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + +### Blazor Web App loading progress + +The loading progress indicator used in Blazor WebAssembly apps isn't present in an app created from the Blazor Web App project template. Usually, a loading progress indicator isn't desirable for interactive WebAssembly components because Blazor Web Apps prerender client-side components on the server for fast initial load times. For mixed-render-mode situations, the framework or developer code must also be careful to avoid the following problems: + +* Showing multiple loading indicators on the same rendered page. +* Inadvertently discarding prerendered content while the WebAssembly runtime is loading. + + + +A future release of .NET might provide a framework-based loading progress indicator. In the meantime, you can add a custom loading progress indicator to a Blazor Web App. + +Create a `LoadingProgress` component in the `.Client` app that calls : + +* When `false`, display a loading progress indicator while the Blazor bundle is downloaded and before the Blazor runtime activates on the client. +* When `true`, render the requested component's content. + +The following demonstration uses the loading progress indicator found in apps created from the Blazor WebAssembly template, including a modification of the styles that the template provides. The styles are loaded into the app's `` content by the component. For more information, see . + +`LoadingProgress.razor`: + +```razor +@if (!OperatingSystem.IsBrowser()) +{ + + + + + + + +
+} +else +{ + @ChildContent +} + +@code { + [Parameter] + public RenderFragment? ChildContent { get; set; } +} +``` + +In a component that adopts Interactive WebAssembly rendering, wrap the component's Razor markup with the `LoadingProgress` component. The following example demonstrates the approach with the `Counter` component of an app created from the Blazor Web App project template. + +`Pages/Counter.razor`: + +```razor +@page "/counter" +@rendermode InteractiveWebAssembly + +Counter + + +

Counter

+ +

Current count: @currentCount

+ + +
+ +@code { + private int currentCount = 0; + + private void IncrementCount() + { + currentCount++; + } +} +``` + +### Blazor WebAssembly app loading progress + +:::moniker-end + +:::moniker range=">= aspnetcore-7.0" The project template contains Scalable Vector Graphics (SVG) and text indicators that show the loading progress of the app.