Skip to content

Commit 118e460

Browse files
authored
Return content loading global WASM example (#35532)
1 parent 97ae452 commit 118e460

File tree

1 file changed

+82
-11
lines changed

1 file changed

+82
-11
lines changed

aspnetcore/blazor/fundamentals/startup.md

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,6 @@ The loading indicator used in Blazor WebAssembly apps isn't present in an app cr
607607
* Showing multiple loading indicators on the same rendered page.
608608
* Inadvertently discarding prerendered content while the .NET WebAssembly runtime is loading.
609609

610-
<!-- UPDATE 10.0 Will be removed for a new feature in this area.
611-
Tracked by: https://github.com/dotnet/aspnetcore/issues/49056 -->
612-
613610
A future release of .NET might provide a framework-based loading indicator. In the meantime, you can add a custom loading indicator to a Blazor Web App.
614611

615612
#### Per-component Interactive WebAssembly rendering with prerendering
@@ -625,6 +622,37 @@ To load CSS styles for the indicator, add the styles to `<head>` content with th
625622

626623
`Layout/ContentLoading.razor`:
627624

625+
:::moniker-end
626+
627+
:::moniker range=">= aspnetcore-9.0"
628+
629+
```razor
630+
@if (!RendererInfo.IsInteractive)
631+
{
632+
<!-- OPTIONAL ...
633+
<HeadContent>
634+
<style>
635+
...
636+
</style>
637+
</HeadContent>
638+
-->
639+
<progress id="loadingIndicator" aria-label="Content loading…"></progress>
640+
}
641+
else
642+
{
643+
@ChildContent
644+
}
645+
646+
@code {
647+
[Parameter]
648+
public RenderFragment? ChildContent { get; set; }
649+
}
650+
```
651+
652+
:::moniker-end
653+
654+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
655+
628656
```razor
629657
@if (!OperatingSystem.IsBrowser())
630658
{
@@ -648,6 +676,16 @@ else
648676
}
649677
```
650678

679+
:::moniker-end
680+
681+
:::moniker range=">= aspnetcore-8.0"
682+
683+
If you didn't already have a `Layout` folder in the `.Client` project, add the namespace for the `Layout` folder to the `_Imports.razor` file. In the following example, the project's namespace is `BlazorSample.Client`:
684+
685+
```razor
686+
@using BlazorSample.Client.Layout
687+
```
688+
651689
In a component that adopts Interactive WebAssembly rendering, wrap the component's Razor markup with the `ContentLoading` component. The following example demonstrates the approach with the `Counter` component of an app created from the Blazor Web App project template.
652690

653691
`Pages/Counter.razor`:
@@ -676,10 +714,6 @@ In a component that adopts Interactive WebAssembly rendering, wrap the component
676714
}
677715
```
678716

679-
:::moniker-end
680-
681-
:::moniker range=">= aspnetcore-9.0"
682-
683717
#### Global Interactive WebAssembly rendering with prerendering
684718

685719
*This scenario applies to global Interactive WebAssembly rendering with prerendering (`@rendermode="InteractiveWebAssembly"` on the `HeadOutlet` and `Routes` components in the `App` component).*
@@ -693,6 +727,10 @@ To load CSS styles for the indicator, add the styles to `<head>` content with th
693727

694728
`Layout/ContentLoading.razor`:
695729

730+
:::moniker-end
731+
732+
:::moniker range=">= aspnetcore-9.0"
733+
696734
```razor
697735
@if (!RendererInfo.IsInteractive)
698736
{
@@ -716,6 +754,43 @@ else
716754
}
717755
```
718756

757+
:::moniker-end
758+
759+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
760+
761+
```razor
762+
@if (!OperatingSystem.IsBrowser())
763+
{
764+
<!-- OPTIONAL ...
765+
<HeadContent>
766+
<style>
767+
...
768+
</style>
769+
</HeadContent>
770+
-->
771+
<progress id="loadingIndicator" aria-label="Content loading…"></progress>
772+
}
773+
else
774+
{
775+
@ChildContent
776+
}
777+
778+
@code {
779+
[Parameter]
780+
public RenderFragment? ChildContent { get; set; }
781+
}
782+
```
783+
784+
:::moniker-end
785+
786+
:::moniker range=">= aspnetcore-8.0"
787+
788+
If you didn't already have a `Layout` folder in the `.Client` project, add the namespace for the `Layout` folder to the `_Imports.razor` file. In the following example, the project's namespace is `BlazorSample.Client`:
789+
790+
```razor
791+
@using BlazorSample.Client.Layout
792+
```
793+
719794
In the `MainLayout` component (`Layout/MainLayout.razor`) of the `.Client` project, wrap the <xref:Microsoft.AspNetCore.Components.LayoutComponentBase.Body%2A> property (`@Body`) with the `ContentLoading` component:
720795

721796
In `Layout/MainLayout.razor`:
@@ -726,10 +801,6 @@ In `Layout/MainLayout.razor`:
726801
+ </ContentLoading>
727802
```
728803

729-
:::moniker-end
730-
731-
:::moniker range=">= aspnetcore-8.0"
732-
733804
#### Global Interactive WebAssembly rendering without prerendering
734805

735806
*This scenario applies to global Interactive WebAssembly rendering without prerendering (`@rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)"` on the `HeadOutlet` and `Routes` components in the `App` component).*

0 commit comments

Comments
 (0)