Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I work on blazor server side . I face Issue page reload after open and reload automatically

so page loaded two times Why flicker happen on loaded page

and How to solve this issue

this not happen on one page this is happen on all application pages

sample code for page Dashboard happen this issue on it

What I have tried:

protected override async Task OnInitializedAsync()
    {
        
            await getcountServers();
            await getcountDatabases();
            await RefreshDropDownListFilter();
          
            await RefreshDropDownListOwnerFilter();
            await RefreshDropDownListDatabaseFilter();
            await SearchFilter();
            await GetFirstCharachter();
           
    }


protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            
            if (firstRender)
            {
                
            }

        }
on _Host file

@page "/"

<head>
   
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>UC.AppRepository.UI</title>
    <base href="~/" />
    <link rel="stylesheet" href="_content/Radzen.Blazor/css/default-base.css">
    <link rel="stylesheet" href="_content/Radzen.Blazor/css/default.css">
    <link rel="stylesheet" href="~/assets/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link href="css/site.css" rel="stylesheet" />
    <link href="BlazorUI.styles.css" rel="stylesheet" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">

    <script src="~/js/jquery-3.6.3.js"></script>
   
</head>
<body>
   
   
    
    
    
    <component type="typeof(App)" render-mode="ServerPrerendered" />

       
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous"></script>
   @* <script src="_content/BlazorInputFile/inputfile.js"></script>*@
@*    <script src="~/assets/js/insertdata.js"></script>*@
    
    <script src="_framework/blazor.server.js"></script>
Posted
Updated 5-May-23 20:58pm

1 solution

Because you use
ServerPrerendered


the page is load twice.


Explained at ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 9:




Static Statically render the component with the specified parameters.

Server Render a marker where the component should be rendered interactively by the Blazor Server app.

ServerPrerendered Statically prerender the component along with a marker to indicate the component should later be rendered interactively by the Blazor Server app.






The main problem with ServerPrerendered is that it loads twice ,so your data layer code is also executed twice. Server mode is just ok, may be a bit slower.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900