I have been using
<component type="typeof(HeadOutlet)" render-mode="Server" />
However, the latest version of DevExpress requires:
<Routes @rendermode="@RenderMode.InteractiveServer"/>
Which I assume I can do as:
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
The new .NET 8 code sample appears to have no _Host.cshtml and defines all this a little different. But I can use the old _Host.cshtml + App.razor approach and don't need to conver to the new Routes.razor + App.razor - correct?
This all works fine for me - but asking to confirm that it should, as opposed to somehow I'm lucky and a change will break my code.
And my big question is as follows. When I switch to ServerPrerendered, it then calls OnInitializedAsync() twice. This is a big hit on the database on a lot of my pages. So it will take twice as long for the pages to render.
Is there any way to avoid this? Or are we stuck with slower pages if ServerPrerendered is used?
Prerendering is enabled by default for interactive components now,if you want to disable prerendering for entire Blazor app in .net 8,you may try
<Routes @rendermode="new InteractiveServerRenderMode(prerender: false)/>
Here's the document related.
You could detect if the componnet is frist rendered in OnInitializesAsync() method via HttpContext(it's not null during the frist rendering)
For .Net 8 razor components, you could access it as below:
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
.....
bool firstRender = !(HttpContext is null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With