Aspnetcore: [Blazor] Preview9 - MapFallbackToClientSideBlazor unusable with MapBlazorHub()

Created on 6 Sep 2019  路  2Comments  路  Source: dotnet/aspnetcore

Describe the bug

From Preview9, it seem impossible to load a valid application through MapFallbackToClientSideBlazor on a server-side project.

This method expect a filename that can be found in the client-side project, like index.html
But as the new MapBlazorHub does not accept any starting component anymore, like MapBlazorHub() in preview8, the application don't instanciate any App component from the client-side project at startup.

It just keep showing "loading..."

To Reproduce

Steps to reproduce the behavior:

  1. Create a Blazor WASM application, ASP.NET Core Hosted checked
  2. In the server-side project, in ConfigureServices in Startup.cs, add services.AddServerSideBlazor();
  3. In Configure use:
app.UseClientSideBlazorFiles<ClientApp.Startup>();

app.UseEndpoints(endpoints =>
{
    endpoints.MapBlazorHub();
    endpoints.MapFallbackToClientSideBlazor<ClientApp.Startup>("server_index.html");
});
  1. Copy index.html in client-side, and past in the same folder with a name server_index.html, and replace in the file content, the blazor.webassembly.js reference, to blazor.server.js

  2. Launch the server-side app in Debug. It is stuck on "loading..."

Expected behavior

The application should launch normally, as we fallbacked on client-side files.

In my opinion, it is not working because the server-side implementation expect the component declaration in a _Host.cshtml file or similar, to be invoked with the Html helper since the deprecation of MapBlazorHub generic type declaration, but the client-side logic doesn't have any functionnality to cover this behavior at index.html level.

Additional info

I was expecting to use this in order to have a similar startup file when having to switch between client-side and server-side implementations with my BlazorMobile plugin.

This way, being able to use some server-side code for debugging, sharing same html/js/css ressources on each implementations, and also switch easily without thinking between WASM runtime (for iOS, Android, UWP) and .NET Core one (for remote device debugging or Desktop with Electron.NET).

The strategy was only to copy/past the index.html file in server_index.html instead, through a MSBuild task, and replace the blazor.webassembly.js reference to blazor.server.js, and fallback on this file in server-side projects, it was a no brainer.

With this change, the only workaround i found and that i'm working on for the next release for preview9 is:

  • Copy index.html file with MSBuild, to server_index.cshtml, still on client-side project
  • Decorate the file with the "guessed" C# code and component type for startup like expected on a server-side project.
  • Set the file Property action to "None"
  • Add the file as a Link reference on any server-side project in a Pages folder, with Property action to "Included" (Contenu in French)
  • Call MapFallback to this file, like a regular server-side App starting page.

In my opinion it's a lot of overhead, in order to keep HTML/JS/CSS references synced between the two implementation, as i don't have found any alternative at this moment.

area-blazor blazor-wasm question

All 2 comments

Thanks for contacting us, @Daddoon.
We've removed support for using Server-side blazor with static HTML partially because of security reasons.
At the moment client and server startups are somewhat different, which we plan to think about and potentially improve in the future.

Thanks for your quick reply. I will stand with my MSBuild task then.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

snebjorn picture snebjorn  路  3Comments

FourLeafClover picture FourLeafClover  路  3Comments

ipinak picture ipinak  路  3Comments

ermithun picture ermithun  路  3Comments

rbanks54 picture rbanks54  路  3Comments