Skip to content

Commit a78ae32

Browse files
committed
Updates
1 parent 7fc9d8d commit a78ae32

File tree

1 file changed

+76
-5
lines changed

1 file changed

+76
-5
lines changed

aspnetcore/blazor/fundamentals/startup.md

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,33 @@ For Blazor Web Apps:
127127
> </script>
128128
> ```
129129
130+
:::moniker-end
131+
132+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"
133+
134+
Due to a [framework bug in .NET 8 and 9 (`dotnet/aspnetcore` #54049)](https://github.com/dotnet/aspnetcore/issues/54049), the Blazor script must be manually started when `beforeWebAssemblyStart(options, extensions)` or `afterWebAssemblyStarted(blazor)` are called. If the server app doesn't already start Blazor manually with a WebAssembly (`webAssembly: {...}`) configuration, update the `App` component in the server project with the following.
135+
136+
In `Components/App.razor`, remove the existing Blazor `<script>` tag:
137+
138+
```diff
139+
- <script src="_framework/blazor.web.js"></script>
140+
```
141+
142+
Replace the `<script>` tag with the following markup that starts Blazor manually with a WebAssembly (`webAssembly: {...}`) configuration:
143+
144+
```html
145+
<script src="_framework/blazor.web.js" autostart="false"></script>
146+
<script>
147+
Blazor.start({
148+
webAssembly: {}
149+
});
150+
</script>
151+
```
152+
153+
:::moniker-end
154+
155+
:::moniker range=">= aspnetcore-8.0"
156+
130157
For Blazor Server, Blazor WebAssembly, and Blazor Hybrid apps:
131158

132159
:::moniker-end
@@ -237,6 +264,7 @@ For examples of JS initializers, see the following resources:
237264

238265
:::moniker range=">= aspnetcore-8.0"
239266

267+
* [Blazor Web App loading indicator](#global-interactive-webassembly-rendering-without-prerendering) (*Global Interactive WebAssembly rendering without prerendering example*)
240268
* <xref:blazor/js-interop/ssr>
241269
* <xref:blazor/components/js-spa-frameworks#render-razor-components-from-javascript> (*`quoteContainer2` example*)
242270
* <xref:blazor/components/event-handling#custom-event-arguments> (*Custom clipboard paste event example*)
@@ -700,13 +728,56 @@ In `Layout/MainLayout.razor`:
700728

701729
*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).*
702730

703-
XXXXXXXXXXXXXXXXXXX
731+
Add a [JavaScript initializer](#javascript-initializers) to the app. In the following JavaScript module file name example, the `{ASSEMBLY NAME}` placeholder is the assembly name of the server project (for example, `BlazorSample`). The `wwwroot` folder where the module is placed is the `wwwroot` folder in the server-side project, not the `.Client` project.
732+
733+
The following example uses a [`progress`](https://developer.mozilla.org/docs/Web/HTML/Element/progress) indicator that doesn't indicate specific progress as [client-side boot resources are delivered to the client](#load-client-side-boot-resources), but it serves as a general approach for further development if you want the progress indicator to show the actual progress.
734+
735+
`wwwroot/{ASSEMBLY NAME}.lib.module.js`:
704736

705-
Awaiting further guidance from Javier to confirm that
706-
a JS initiazlier or `Blazor.start()` approach is the
707-
correct pattern for this.
737+
```javascript
738+
export function beforeWebStart(options) {
739+
var progress = document.createElement("progress");
740+
progress.id = 'progressBar';
741+
progress.ariaLabel = 'Blazor loading…';
742+
progress.style = 'position:absolute;top:50%;left:50%;margin-right:-50%;' +
743+
'transform:translate(-50%,-50%);';
744+
document.body.appendChild(progress);
745+
}
708746

709-
XXXXXXXXXXXXXXXXXXX
747+
export function afterWebAssemblyStarted(blazor) {
748+
var progress = document.getElementById('progressBar');
749+
progress.remove();
750+
}
751+
```
752+
753+
:::moniker-end
754+
755+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"
756+
757+
Due to a [framework bug in .NET 8 and 9 (`dotnet/aspnetcore` #54049)](https://github.com/dotnet/aspnetcore/issues/54049), the Blazor script must be manually started. If the server app doesn't already start Blazor manually with a WebAssembly (`webAssembly: {...}`) configuration, update the `App` component in the server project with the following.
758+
759+
In `Components/App.razor`, remove the existing Blazor `<script>` tag:
760+
761+
```diff
762+
- <script src="_framework/blazor.web.js"></script>
763+
```
764+
765+
Replace the `<script>` tag with the following markup that starts Blazor manually with a WebAssembly (`webAssembly: {...}`) configuration:
766+
767+
```html
768+
<script src="_framework/blazor.web.js" autostart="false"></script>
769+
<script>
770+
Blazor.start({
771+
webAssembly: {}
772+
});
773+
</script>
774+
```
775+
776+
If you notice a short delay between the loading indicator removal and the first page render, you can guarantee removal of the indicator after rendering by calling for indicator removal in the `MainLayout` component's [`OnAfterRenderAsync` lifecycle method](xref:blazor/components/lifecycle#after-component-render-onafterrenderasync). For more information and a code example, see [Document an approach for a loading indicator that works with global Interactive WebAssembly without prerendering (`dotnet/AspNetCore.Docs` #35111)](https://github.com/dotnet/AspNetCore.Docs/issues/35111#issuecomment-2778796998).
777+
778+
:::moniker-end
779+
780+
:::moniker range=">= aspnetcore-8.0"
710781

711782
### Blazor WebAssembly app loading progress
712783

0 commit comments

Comments
 (0)