Skip to content

Question: When using Blazor RenderMode.Server, is there a way to add a loader or spinner #13933

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

Closed
coreyjthompson opened this issue Sep 12, 2019 · 12 comments
Labels
affected-most This issue impacts most of the customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server Pillar: Complete Blazor Web reevaluate We need to reevaluate the issue and make a decision about it severity-nice-to-have This label is used by an internal tool

Comments

@coreyjthompson
Copy link

Hey guys. Long time listener, first time caller. I hope this is the correct place to ask this...

I'm using Blazor components in my existing Razor Pages app and calling them with
@(await Html.RenderComponentAsync<ComponentName>(RenderMode.Server))

I'm wondering if there is some way to know when the request is returned or ends so I could run a spinner or loader of some sort?

@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Sep 13, 2019
@DamianEdwards
Copy link
Member

Disclaimer: I know very little about what I'm about to say.

I took a quick look at this from the "outside" (in a Blazor app itself, not the source) and it seems to enable this we'd need to expose some new API/callback on the window.Blazor object in the browser, such that one could register to be called back when a given component is loaded. Today, a unique marker is embedded in the HTML as a comment element, which contains a JSON payload that describes the component that will then be rendered over the circuit from the server once the page has loaded. The code to find these markers appears to all be internal and inaccessible, so doing anything today from inside the app would be pretty hacky. A new browser API would enable something low-level like this:

let marker = window.Blazor.getComponentMarker('someComponentMarkerField');
window.Blazor.onComponentLoading(marker, () => {
    // Go ahead and do whatever to indicate the component is loading
    let spinner = document.getElementById('myLoadingSpinner');
    spinner...
});
window.Blazor.onComponentLoaded(marker, () => {
    // Go ahead and do whatever to indicate the component is loaded
    let spinner = document.getElementById('myLoadingSpinner');
    spinner...
});

I think ideally we'd enable this scenario in a really nice way along with #13726 (Tag Helper for component rendering) such that you could just do something like this:

<component type="typeof(Counter)" render-mode="Server" id="myCounter" />
<component-loading for="myCounter">
   loading...
</component-loading>

Alternate approach that simply augments the component Tag Helper itself:

<component type="typeof(Counter)" render-mode="Server" load-indicator="counterSpinner" />

<div id="counterSpinner">
    This will be automatically hidden (display:none;) when the associated component finishes loading.
</div>

I think you'd want a separate element so that you have the flexibility to put the loading indicator anywhere on the page you like. You'd likely want to be able to support the following use-cases:

  • a separate loader per component
  • a shared loader used by multiple components
  • a single loader for the entire page no matter which component is loading

Which use-cases we support will obviously impact which approach we take.

This is very similar functionality to the UpdateProgress control in Web forms and I agree it would be useful.

@pranavkm
Copy link
Contributor

pranavkm commented Sep 13, 2019

You could change your app element to show a spinner:

<app><img src="img/spinner.gif" /></app>

@DamianEdwards
Copy link
Member

@pranavkm one doesn't always have an <app> element though right? If you're just rendering components in a Razor View, you don't need it.

@julienGrd
Copy link

Not works for me

<app>
                @(await Html.RenderComponentAsync<App>(RenderMode.Server))
                <div class="my-loader">
                    </div>
            </app>

the div with class my-loader not disappear after the app is rendering, so my loader never disappear

@pranavkm pranavkm reopened this Sep 14, 2019
@pranavkm
Copy link
Contributor

Yup, I think @DamianEdwards is right. We'll have another look at this.

@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Sep 16, 2019
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Sep 16, 2019
@mkArtakMSFT
Copy link
Member

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@StefH
Copy link

StefH commented Jun 20, 2020

As a workaround, you can modify the blazor.webassembly.js, see this article on how to do this:
https://medium.com/@stef.heyenrath/show-a-loading-progress-indicator-for-a-blazor-webassembly-application-ea28595ff8c1

@colschewski
Copy link

As a workaround, you can modify the blazor.webassembly.js, see this article on how to do this:
https://medium.com/@stef.heyenrath/show-a-loading-progress-indicator-for-a-blazor-webassembly-application-ea28595ff8c1

I dont know if webassembly is similar to server side blazor.

@ghost
Copy link

ghost commented Jul 23, 2020

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.

@SteveSandersonMS SteveSandersonMS added affected-most This issue impacts most of the customers severity-nice-to-have This label is used by an internal tool labels Oct 9, 2020 — with ASP.NET Core Issue Ranking
@CuteLeon
Copy link

CuteLeon commented Feb 8, 2021

I have realised this function via the link which @StefH attached. But what badly is that I have to modify blazor.webassembly.js file Manually after each time I build my WASM application, even writing a script to do this duplicated step is still a trouble.
What if to offer a native event or hook in blazor.webassembly.js file? As you see, it's not hard at all.
Many Thanks.

@javiercn javiercn added feature-blazor-server feature-templates reevaluate We need to reevaluate the issue and make a decision about it labels Apr 19, 2021
@michaelmoneypenny
Copy link

just adding to the "this would be a nice feature" wagon :)

@mkArtakMSFT
Copy link
Member

Streaming rendering in Blazor Web should cover this.

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-most This issue impacts most of the customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server Pillar: Complete Blazor Web reevaluate We need to reevaluate the issue and make a decision about it severity-nice-to-have This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests