squidfunk / mkdocs-material

Documentation that simply works

Home Page:https://squidfunk.github.io/mkdocs-material/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Instant loading should default to `window.location` on 4xx status code

dmccaffery opened this issue · comments

Contribution guidelines

I want to suggest an idea and checked that ...

  • ... to my best knowledge, my idea wouldn't break something for other users
  • ... the documentation does not mention anything about my idea
  • ... there are no open or closed issues that are related to my idea

Description

Our organisation protects our static sites behind authentication based on a token stored as a cookie. This is implemented via lambda@edge on cloudfront, but equally applies to any other proxy that supports authentication. When the cookie / token expires, the XHR requests used by the instant integration silently fails and navigation breaks. I would expect this to be a fairly common use case, such as those used by backstage.io and private GitHub pages deployments in GHE.

The recommendation is to have the instant integration fallback to setting the window location, which would allow any proxies to correctly handle the redirects required to refresh the tokens, or to at least fail with an unauthorised error so the user knows what is going on, instead of silently failing.

Use Cases

  1. Enable authenticated (private) sites to correctly handle oidc flows or other auth flows that cannot be handled via XHR (such as browser redirects)
  2. Enable the user to react to the error condition if the server renders error pages. As of right now, there is no notification / toast, etc, that would alert the user as to why navigation is not functioning.

Screenshots / Mockups

No response

Thanks for suggesting, that definitely sounds like a valid use case and a good idea.

This behavior is actually implemented, but it does not trigger because failing requests are currently just filtered:

switchMap(url => request(url.href)
.pipe(
catchError(() => {
setLocation(url)
return NEVER
})
)
),

export function request(
url: URL | string, options: RequestInit = { credentials: "same-origin" }
): Observable<Response> {
return from(fetch(`${url}`, options))
.pipe(
filter(res => res.status === 200),
catchError(() => EMPTY)
)
}

Instant loading is definitely in need of refactoring as already noted in #3797 since it kind of outgrew its initial architecture/design. I'm going to tackle this problem as well as part of the refactoring when I can allocate enough time.

Fixed in 8beda2b. This is more of a mitigation than a proper fix, because as I noted – instant loading needs refactoring. However, it should fix the issue at hand, hopefully without introducing new problems, as I just moved the suboptimal error handling behavior downstream.

This is amazing, thank you. If I can help in any way, let me know. Happy to put hands behind keyboards. :)

Released as part of 8.2.14.