0

I'm developing a custom SPFx web part for our Sharepoint Online intranet. A couple of our test users have reported loading the page containing the web part, the page is either reloaded and/or they're automatically being redirected to http://acme.sharepoint.com/default.aspx. Since I can't reproduce the error, I can't be 100% sure it's my webpart that's causing the redirect, but as this page is the only one causing such a redirect I think it's fairly safe to assume it's my web part that's causing the redirect.

As I'm not able to reproduce it, it's hard debugging the issue. So I though I'd reach out to the SPO community for advice. Have other SPO devs experienced the same type of issue, and could shed some light as to what's causing this?

I've wrapped the entire business logic inside a try/catch in an attempt to try to prevent any errors to crash the web part, like this.

public async componentDidMount() {
    try {
    await this.loadStuff()
    }
    catch (error) {
        this.setState({errorMessage: JSON.stringify(error)}); // Displays an error message to the user

I don't believe the this.setState would cause the webpart to crash, so I don't believe it's this feature that's causing the page reload and/or automatic redirect.

Update #1: I looks like the redirect is caused by the login action performed by the webpart, in which the user is temporarily redirected to a spfx login page, and then back. Don't have the exact details at hand at the moment, but if this is the case I need to find a way to avoid this redirect. This may explain what's been experienced as a page reload, though I doesn't explain why users sometimes are redirected to http://acme.sharepoint.com/default.aspx

Update #2: Moving the discussion over to Spfx with PnP.js / Graph: How to prevent redirect to spfxsinglesignon.aspx

2

Another method worth looking at.

  • Run Fiddler to find whether the redirection comes from a specific javascript code or anything else.
  • Run gulp serve --nobrowser then take your SharePoint site address (where it shows your web part), add /_layouts/workbench.aspx, and then add your web part. If nothing goes wrong (not redirecting) then likely other web parts are the bad ones.

Hope it helps.

4
  • Thanks for your input. I just added "Update #1" to my original post. Please feel free to take a look at it.
    – kenneho
    Jan 24 '21 at 17:38
  • 1
    are you doing some calls to graph API or any other APIs which require you to authenticate? If yes, you need to check what is the "callback" URL to it, maybe it's set to that address. Can you also share what is your loadStuff() method is doing? Jan 25 '21 at 4:02
  • I took the liberty to fork this issue of to a new post: sharepoint.stackexchange.com/questions/289174/…
    – kenneho
    Jan 25 '21 at 8:03
  • 1
    Replied to that too. Jan 25 '21 at 8:56
1

In that page are your webpart the only custom webpart embedded in the page?

I mean, possibilities of your webpart that causes the redirect but if there is another custom webpart in the page it is also another possibilities that we need to consider.

And, assuming its only your webpart that is custom in the page, what is your loadstuff function doing? it might be some part of the code that causes it.

:)

1
  • Thanks for your input. I just added "Update #1" to my original post. Please feel free to take a look at it.
    – kenneho
    Jan 24 '21 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.