blazor server running initialization code twice in spite of render-mode="Server"-- does Telerik force server side prerender?

2 Answers 1514 Views
Miscellaneous
Lawrence
Top achievements
Rank 1
Iron
Lawrence asked on 22 Aug 2022, 05:40 PM

blazor server running initialization code twice in spite of render-mode="Server"-- does Telerik force server side prerender?  I have done everything i can think of and have engaged microsoft directly to try to figure out what is going on.  Is there something in Telerik UI for Blazor that is forcing server prerender?  The bottom line is that the initial instances of my services have values set and subsequent instances, after initialization code is re-run no longer have the same values and context that my menuing and layouts are relying on for context.  Has anyone run into this problem and is it at all related to Telerik components?  I'm at a complete loss and have been trying to get this to work for nearly a month now.

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 24 Aug 2022, 10:13 AM | edited on 24 Aug 2022, 10:15 AM

Hi Lawrence,

No, we are not forcing two renders and I am not sure we even can.

I also just tested a simple Blazor server app with the following in Index.razor (plus some of our components in Index.razor as well):

    protected override void OnInitialized()
    {
        base.OnInitialized();
    }

The method executed once in Server mode and twice in ServerPrerendered mode.

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Lawrence
Top achievements
Rank 1
Iron
commented on 24 Aug 2022, 03:26 PM

Hello Dimo,

Thank you for looking into this issue.  Late yesterday this mystery was solved and it turned out that the problem was navigationmanager.navigateTo("page", true)-- it turns out this completely wipes out the context of EVERYTHING-- so no, it isn't/wasn't anything to do with Telerik UI-- i never did believe that it was but in working with Microsoft we were simply out of options and it turns out that if you use navigateTo without the second parameter the page/services retain their context and values.  The default for the second parameter is false if you don't specify it as true.  In any case, there didn't seem to be anything in the documentation from MS to inform anyone of that fact so if you are having issues with scoped and even singleton services retaining their context after a navigation that may very well be the issue.  I lost over two weeks worth of time on this issue and MS couldn't figure it out either.  FYI, i used the "true" parameter so the menu would properly update and show some of the values that had been set by the page's initialization but the proper thing to do is "statehaschanged" on the menu and that will redraw without losing values/context in the associated services.  Thank you once again for looking into this also.

0
Christopher
Top achievements
Rank 1
answered on 29 Mar 2023, 12:17 PM
If you're experiencing issues with Blazor server running initialization code twice , it could be attributed to various reasons. Some possible solutions that you could try out are:

Ensure that you are rendering the components on the server by setting the RenderMode of the component to Server or Auto.

Check to see if there are any multiple calls being made to the components or the initialization code. You can use the Blazor debugger to check for this.

If the initialization code is making any kinds of HTTP requests to the server, ensure that they have been implemented using proper async await patterns.

Ensure that the components and their initialization codes are written in a way that does not have any conflicts or errors.

Try using the latest version of .NET and Blazor (if possible).

If none of these solutions work, consider reaching out to Blazor's support team for further assistance.
Tags
Miscellaneous
Asked by
Lawrence
Top achievements
Rank 1
Iron
Answers by
Dimo
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or