Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor p8] OnInitializedAsync is executed for twice on pre-render #13607

Closed
ctrl-alt-d opened this issue Sep 1, 2019 · 3 comments
Closed

[Blazor p8] OnInitializedAsync is executed for twice on pre-render #13607

ctrl-alt-d opened this issue Sep 1, 2019 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design.

Comments

@ctrl-alt-d
Copy link

Issue

OnInitializedAsync is executed for twice when page has been served as "pre-render".

Version

[dani@localhost tw]$ dotnet --version
3.0.100-preview8-013656

Steps to reproduce and screen shots:

@page "/"
@inject IUriHelper UriHelper

<h1>Hello, world!</h1>

Welcome to your new app.

@code{

    protected async override Task OnInitializedAsync()
    {
        System.Console.WriteLine("_*   ");
        System.Console.WriteLine("_**************************");
        System.Console.WriteLine("_***** Pre render ******");
        System.Console.WriteLine("_**************************");
        System.Console.WriteLine("_   ");
        return;
    }
}

And I see is executed for twice only on pre-render:

63875371-9fe68080-c9c3-11e9-9537-41924ef83401

Has it some explanation?

The question on stackoverfow: Blazor UriHelper.NavigateTo is calling the page twice

@ctrl-alt-d
Copy link
Author

Related: #13172

@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Sep 3, 2019

Thanks for contacting us, @ctrl-alt-d.
The behavior you're seeing is by-design. We you see the OnInitializedAsync called once during pre-rendering and once during the rendering.

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. label Sep 3, 2019
@gitskab
Copy link

gitskab commented Nov 18, 2019

Hi,

I'm having the same issue but only as I publish my app to Azure App Services. If I switch RenderMode to Server then it gets called only once but then contextAccessor.HttpContext is null when injected into my service class.

On my localhost it works fine in both cases..

Am I doing something wrong here?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design.
Projects
None yet
Development

No branches or pull requests

4 participants