Live Chat Icon For mobile
Live Chat Icon

Why are Blazor lifecycle methods getting executed twice?

Platform: Blazor| Category : General, Lifecycle

In a Blazor Server app, the default RenderMode is ServerPrerendered. When the component is rendering with the ServerPrerendered render mode, the component is initially rendering statically as part of the page.

On executing the first time, it is rendered as an MVC component directly when the page is requested and handled by “_Host” which is specified in “_Host.cshtml”.

@(await Html.RenderComponentAsync<App>(RenderMode.ServerPrerendered))

Then the resources are loaded with the blazor.server.js script and start rendering a second time. Then the Razor pages are loaded as a Blazor component.

Note: If you are changing the RenderMode to Server, the lifecycle method executes only once.

Refer to this link for details.

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.