dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.49k stars 10.04k forks source link

Detect if the code is executing for the first time when entering the page in blazor server side #44903

Open Alerinos opened 2 years ago

Alerinos commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

Blazor could use the function of detecting the first loading of a component / subpage by the server.

If we use OnInitializedAsync it will work like this:

  1. Execute code on first entry (server side)
  2. Will execute the same code again after loading the page or moving dynamically (e.g. to a subpage)

If we have a subpage where the code takes longer to load (e.g. we wait for the API), a problem arises. The first load is delayed by this component.

In case we don't want to be indexed by bots, there should be a function like don't do it on server side. We can do a Skeleton and wait for the task to be done.

It is possible to do this by PersistentComponentState, but it is not convenient and there are problems with many components (you can call it only once)

I propose to do something like this:

protected override async Task OnInitializedAsync()
  {
  if(AppState.ServerRendering == false){
  // Code that does not require rendering during server rendering
  }
}

or

protected override async Task OnInitializedDynamicAsync(){
// Code that does not require rendering during server rendering
}

I also know about the existence of OnAfterRenderAsync but it doesn't render the code on the server side.

Describe the solution you'd like

Let me know what you think, I think letting the developer decide whether the code is to be rendered server-side or not is a good solution. This will prevent the problem of delaying the entire page by, for example, one component.

Additional context

No response

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

MackinnonBuck commented 11 months ago

@Alerinos I think this might be a dupe of https://github.com/dotnet/aspnetcore/issues/49401. Does that seem right to you?

ghost commented 10 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.