dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.51k stars 10.04k forks source link

Default WebAssembly loading progress indicator doesn't apply in Blazor Web template #49056

Open SteveSandersonMS opened 1 year ago

SteveSandersonMS commented 1 year ago

In .NET 7 we added a built-in loading progress indicator for WebAssembly apps.

This continues to work in .NET 8 if you have a WebAssembly standalone project. However if you are using the new Blazor Web template, any WebAssembly components are added via @rendermode, and this will not cause the loading progress indicator to show up, because most of the time you wouldn't want to. You can have any number of small islands of WebAssembly-based UI anywhere, and it will normally be prerendered. And:

This issue is just to track that we probably need to update some docs/guidance to avoid implying that people should or can always have a WebAssembly loading progress indicator. Also we might consider having some special new component that does render a loading progress indicator within the new architecture for people who really don't want to prerender their WebAssembly content.

SteveSandersonMS commented 1 year ago

Out of scope for .NET 8, but one possible design idea for the future is:

However if the "auto" mode becomes really mainstream then maybe this would not be a situation in the first place.

danroth27 commented 1 year ago

Another use case is upgrading an existing ASP.NET Core hosted Blazor WebAssembly app to .NET 8 and switching from the static index.razor to server-side rendered component (Host.razor). Initially I find it's natural to disable prerendering of the App component when upgrading because many Blazor WebAssembly components aren't set up properly for prerendering (like the default FetchData component, which depends on an HttpClient service). But without prerendering you probably still want the loading indicator.

You can disable prerendering as part of specifying the render mode for the App component, but then you don't have a way to render the loading progress indicator and have it later gets replaced. I can sort of work around this by using the old pattern of registering the App component as a root component with a CSS selector in Program.cs. As long as the HeadOutlet is still setup to use the WebAssembly render mode then blazor.web.js will still load the client app and setup the App component. It feels a bit hacky, but it seems to work.

danroth27 commented 1 year ago

Reopening as this can be an issue for users migrating Blazor WebAssembly apps to the Blazor Web App model.