How do I suppress the UI rendering in Blazor?

Override the  ShouldRender  method  to suppress UI rendering. If the implementation returns true, the UI is refreshed. Initial rendering cannot be prevented using this method. [Counter.razor] 

How can I properly dispose a component in Blazor?

Components should be disposed properly to avoid memory leak and allow proper garbage collection.  Managed resources used by the application will be disposed by the Blazor framework itself. If a component implements IDisposable, the Dispose method will be called when the component is removed from the UI. You can use Dispose method to release unmanaged resources, unhook events, dispose DotNetObjectReference instances to avoid memory leak. Refer to the following code sample. More information about component disposal can be found here.

How do you preserve whitespaces in a Blazor application?

From .NET 5 Preview 7, Blazor components trim insignificant whitespaces to achieve better performance. This has been implemented as a result of the finding that 40% of the rendering time is consumed by whitespace nodes. If whitespace nodes removal causes unexpected behavior, you can simply enable it by using the @preservewhitespace directive. View Sample in GitHub 

How do I detect a prerendering app in Blazor?

You can use the IHttpContextAccessor.HttpContext.Response.HasStarted property to check whether the application is pre-rendering or not.  HasStarted specifies that the response header has been sent to the client. If HasStarted is set to false, it means that the application is still pre-rendering and client connection is not yet established. Refer to the following code sample. The HttpContextAccessor service should be registered by calling the AddHttpContextAccessor method in the Startup.cs.

How can I avoid memory leaks when using JSInterop call?

To avoid memory leaks, dispose the DotNetObjectReference instance created by a component properly and allow proper garbage collection. The DotNetObjectReference instance should be disposed either at component side or JavaScript side. Use the following patterns to dispose DotNetObjectReference at the component level. Implement IDisposable interface in the component. Add Dispose method and dispose DotNetObjectReference object inside the Dispose method. When a component doesn’t dispose the DotNetObjectReference instance, it should be disposed at the JavaScript side as follows.