Skip to content

Enhance Blazor.reconnect to state whether failures are due to circuit not existing so we can auto-reload page #44669

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
1 task done
Alerinos opened this issue Oct 21, 2022 · 6 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Priority:1 Work that is critical for the release, but we could probably ship without Status: Resolved

Comments

@Alerinos
Copy link

Alerinos commented Oct 21, 2022

Is there an existing issue for this?

  • I have searched the existing issues

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

I created a connection support. If it is broken, a message pops up and then every 30 seconds the system tries to establish a connection.

        let network = document.getElementById("network");
        let offline = document.getElementById("offline");
        let online = document.getElementById("online");

        let connect = true; @* Connection life status *@
        let reconnectId = null;     @* Clock ID to reconnect *@

        Blazor.start({
            reconnectionHandler: {

                @* Disconnect *@
                onConnectionDown: (options, error) => {
                    connect = false;
                    network.classList.remove("hidden");
                    offline.classList.remove("hidden");

                    @* First connect *@
                    window.Blazor.reconnect();

                    @* trying to establish a connection *@
                    reconnectId = setInterval(() => { 
                        if(connect == true){
                            console.log("Close timer...");
                            clearInterval(reconnectId);
                        }
                        console.log("Reconnect in progress...");
                        window.Blazor.reconnect();
                    }, 1000 * 30);
                },

                @* Connect *@
                onConnectionUp: () => {
                    connect = true;
                    offline.classList.add("hidden");
                    online.classList.remove("hidden");

                    setTimeout(() => {
                        network.classList.add("hidden");
                        online.classList.add("hidden");
                    }, 3000);
                }
            }
        });

Everything works fine until the server loses sessions.
This causes an error that requires the entire page to be reloaded.

I need a function in javascript to check the state if there is a connection to blazor, if it has been broken, if there is any error.
An event like onError:

Example:

onError: () => {
 location.reload()
}

Describe the solution you'd like

    <div id="blazor-error-ui">
        <environment include="Staging,Production">
            An error has occurred. This application may no longer respond until reloaded.
        </environment>
        <environment include="Development">
            An unhandled exception has occurred. See browser dev tools for details.
        </environment>
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>

Currently, the only option is to manually click or call the meta tag refres, it is not a professional solution.

By the way, why are broken connections by the server not handled? This can be done without reloading the page ...

Also, better handling of the call, more automatic than manual, would be useful. People who see the default messages are scared and leave the site, which results in a drop in impressions.

Additional context

No response

@TanayParikh TanayParikh added the area-blazor Includes: Blazor, Razor Components label Oct 21, 2022
@Alerinos
Copy link
Author

I was wondering. We can not store sessions, e.g. for a week? If the client frequently visits the website, why drop him or her? Each entry extends life by 7 days. I understand that for websites with a lot of hits, it can draw a lot of resources, although it seems to me that up to 100k unique users per month it will not be a big problem. I haven't looked in source, what data is stored? They shouldn't weigh much.

@MackinnonBuck MackinnonBuck added enhancement This issue represents an ask for new feature or an enhancement to an existing one Docs This issue tracks updating documentation labels Oct 24, 2022
@MackinnonBuck MackinnonBuck added this to the .NET 8 Planning milestone Oct 24, 2022
@ghost
Copy link

ghost commented Oct 24, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@mkArtakMSFT mkArtakMSFT added triaged and removed Docs This issue tracks updating documentation labels Nov 1, 2022
@SteveSandersonMS SteveSandersonMS changed the title return error status while connected in blazor Enhance Blazor.reconnect to state whether failures are due to circuit not existing so we can auto-reload page Nov 1, 2022
@SteveSandersonMS
Copy link
Member

The team discussed this and we agree with the suggestion. That is, when calling Blazor.reconnect() there should be either a return value or an exception or something to indicate if the server is saying "No, that circuit ID is unknown". That would allow developers to react by reloading the page or even changing the UI to say "Sorry, your session has expired - please click here to reload".

Otherwise the developer can't differentiate between this scenario and something like the internet connection is temporarily down so it's worth retrying the reconnection later.

@camistein
Copy link

The team discussed this and we agree with the suggestion. That is, when calling Blazor.reconnect() there should be either a return value or an exception or something to indicate if the server is saying "No, that circuit ID is unknown". That would allow developers to react by reloading the page or even changing the UI to say "Sorry, your session has expired - please click here to reload".

Otherwise the developer can't differentiate between this scenario and something like the internet connection is temporarily down so it's worth retrying the reconnection later.

Any possibility this could be available in a minor version instead of waiting for next major version ?

@MackinnonBuck
Copy link
Member

@Alerinos, Blazor.reconnect() will return a promise that either:

  • Rejects if the server could not be reached
  • Resolves to false if the circuit ID was invalid
  • Resolves to true if the reconnection was successful

See this example that shows how to define custom reconnection behavior. It can be tweaked to handle the two error cases differently.

I'm going to close this as "answered", but please feel free to reopen if you disagree that the existing functionality addresses this issue. Thanks!

@MackinnonBuck MackinnonBuck added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Nov 28, 2022
@ghost ghost added the Status: Resolved label Nov 28, 2022
@MackinnonBuck MackinnonBuck removed this from the .NET 8 Planning milestone Nov 29, 2022
@Alerinos
Copy link
Author

Alerinos commented Dec 10, 2022

@MackinnonBuck
Thank you for your help.
I see a big problem, if we are going by train, we have lost the internet, the page will reload despite the lack of internet. This prevents us from browsing the site, so we leave it.
In this case, the static site wins.
What do you think about adding such a case to the documentation? Blaozr will wait for the connection to resume, if it detects a connection it will reload the page or perform a total retry (if the session exists).

@ghost ghost locked as resolved and limited conversation to collaborators Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Priority:1 Work that is critical for the release, but we could probably ship without Status: Resolved
Projects
None yet
Development

No branches or pull requests

8 participants