0

I am updating a Blazor web assembly project from .NET 9 to .NET 10, and noticed a change in behavior with the following line of code:

@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))

In .NET 9, when using this mode without prerendering, lifecycle methods such as OnInitialized and OnInitializedAsync were executed normally on the client.

In .NET 10, however, these lifecycle methods are no longer triggered.

Does anyone know how to make them launch the same way as in the previous frameworks?

I've tried every possible option and I don't understand why Microsoft doesn't allow this in .NET 10!

@page "/"

@using System.Security.Claims
@using shared_library.Layout
@using webapp_blazor.Client.Servicios;

@layout LayoutRaiz

@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
 
@inject Servicio_AuthenticationStateProvider_Wasm _Servicio_AuthenticationStateProvider
@inject NavigationManager _NavigationManager

@code {
    protected async override Task OnInitializedAsync()
    {
        var authenticationState = await _Servicio_AuthenticationStateProvider.GetAuthenticationStateAsync();
        ClaimsPrincipal _ClaimsPrincipal = authenticationState.User;

        /*Otra forma de comprobar si esta validado*/
        if (!authenticationState.User.Identity.IsAuthenticated)
        {
            _NavigationManager.NavigateTo("/Autenticar_wasm");
        }
        else
        {
            _NavigationManager.NavigateTo("/Inicio_wasm");
        }
    }

    protected async override void OnAfterRender(bool firstRender)
    {
        var authenticationState = await _Servicio_AuthenticationStateProvider.GetAuthenticationStateAsync();
        ClaimsPrincipal _ClaimsPrincipal = authenticationState.User;

        /*Otra forma de comprobar si esta validado*/
        if (!authenticationState.User.Identity.IsAuthenticated)
        {
            _NavigationManager.NavigateTo("/Autenticar_wasm");
        }
        else
        {
            _NavigationManager.NavigateTo("/Inicio_wasm");
        }
        
    }
}
2
  • Sort-of repro: When I use this rendermode the page won't even show up. There are some errors in the JS Console. Commented Nov 16 at 20:09
  • This could be a good question, it's up to you to post a proper minimal reproducible example: create a new project and be precise about the template and settings used. Commented Nov 16 at 20:27

1 Answer 1

-2

For .NET 10 try using

@rendermode InteractiveWebAssembly(prerender: false)

instead of

InteractiveWebAssemblyRenderMode(prerender: false)

because the rendering pipeline has been changed in .NET 10.

New contributor
Asif Rabbani is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Sign up to request clarification or add additional context in comments.

4 Comments

That won't even compile.
What you're saying is incorrect because .NET 10 doesn't recognize: @rendermode InteractiveWebAssembly(prerender: false)
According to Microsoft documentation: “Interactive render modes (Interactive Server, Interactive WebAssembly, Interactive Auto) support prerendering by default… ”
In .NET 9 you could completely disable prerendering. In .NET 10 this is no longer possible because the initial prerender is part of the unified Blazor architecture. prerender:false still exists for compatibility, but it does NOT prevent the server prerender from happening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.