Aspnetcore: Make it easy to transition from stateful prerendering to -> non-stateful prerendering

Created on 26 Jul 2019  Â·  12Comments  Â·  Source: dotnet/aspnetcore

I think we need to come up with a strategy or some diagnostics to help people migrate from the preview 7 template to the preview 8 one.

Since we're removing stateful prerendering, there are two changes you need to make in your app:

  • In _Host.cshtml use RenderStaticComponentAsync
  • In Startup.cs add a mapping for the component to the <app> element

Before

```C#
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});


**After**

```C#
app.UseEndpoints(endpoints =>
{
    endpoints.MapBlazorHub<App>("app");
    endpoints.MapFallbackToPage("/_Host");
});

The problem is that it's really easy to get the first one of these right - but once you do, the app stops responding. You'll prerender just fine, but no websocket will be opened. There are literally NO diagnostics telling you that you forgot to do the second part of this.

We need to consider whether we have any good ideas to help people understand how to update preview 4->preview 8

Done area-blazor bug

Most helpful comment

You must also consider multiple "entry point" components for existing MVC/Razor pages projects.
For example:

I have a razor page Index.cshtml, and I want to render a component in there, for example

<counter>@(await Html.RenderStaticComponentAsync<Counter>())</counter>

while having a second page called Whatever.cshtml, in which I want to render a different component in there, like:

<whatever-component>@(await Html.RenderStaticComponentAsync<WhateverComponent>())</whatever-component>

Currently in preview 7 everything works fine when using

endpoints.MapBlazorHub();

How will this work after the changes ?

All 12 comments

Isnt that a job for the Obsolete Attribute? I.e. add it to the non-generic MapBlazorHub method.

And what happens if we don't want to map Blazorhub to a specific component like App inside an app html tag?

Like when we build a web site using MVC/Razor Pages and want to embed blazor components inside those projects.

-Preview7 I tried using RenderStaticComponentAsync method and the interactivity inside my razor pages stopped working.

-Preview8 Latest Nightly build: Also failing to render interactive blazor components in my razor pages using RenderStaticComponentAsync

Regards!!

d it to the non-generic MapBlazorHub method.

Yup. That's an option. At this point we'd just remove the no-args method wholesale.

Even better @rynowak. Let the compiler error out is a very clear signal to users something's needs changing 😎

Doesn't this break the embeding of components in existing MVC/RazorPages projects?
How will these be registered in preview-8 ?

You must also consider multiple "entry point" components for existing MVC/Razor pages projects.
For example:

I have a razor page Index.cshtml, and I want to render a component in there, for example

<counter>@(await Html.RenderStaticComponentAsync<Counter>())</counter>

while having a second page called Whatever.cshtml, in which I want to render a different component in there, like:

<whatever-component>@(await Html.RenderStaticComponentAsync<WhateverComponent>())</whatever-component>

Currently in preview 7 everything works fine when using

endpoints.MapBlazorHub();

How will this work after the changes ?

Yes. that will still work.

That is good to hear, because in preview-7 it doesn't work.

If you try to add multiple entry points in an MVC/Razor Pages app, when you navigate to a page that do not contain one of the custom tags (e.g. <counter>), then you get "not found" errors in blazor.server.js and it blows up.

OK, we should fix that then. Is there an existing issue for that?

I didn't find anything searching in the repo's issues. I will create an issue, if you want, tomorrow morning (GMT +3 timezone ) ☺

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fayezmm picture fayezmm  Â·  3Comments

ipinak picture ipinak  Â·  3Comments

guardrex picture guardrex  Â·  3Comments

aurokk picture aurokk  Â·  3Comments

githubgitgit picture githubgitgit  Â·  3Comments