Skip to content
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

Stay on page when switching versions broken for default version #4012

Closed
5 tasks done
ofek opened this issue Jun 11, 2022 · 23 comments
Closed
5 tasks done

Stay on page when switching versions broken for default version #4012

ofek opened this issue Jun 11, 2022 · 23 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@ofek
Copy link
Sponsor Collaborator

ofek commented Jun 11, 2022

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

For https://squidfunk.github.io/mkdocs-material/setup/setting-up-versioning/, if I have versions 1.0, 1.1, and 1.2, with latest pointing to 1.2:

  • /latest/page/ -> dropdown 1.0: ok /1.0/page/
  • /latest/page/ -> dropdown 1.1: ok /1.1/page/
  • /latest/page/ -> dropdown 1.2: redirect /1.2/

Expected behaviour

Switching to the permanent link of the current default page should work

Actual behaviour

Redirects to root

Steps to reproduce

Example page https://hatch.pypa.io/latest/config/metadata/

Package versions

  • Python: 3.10.5
  • MkDocs: 1.3.0
  • Material: 8.3.4

Configuration

https://github.com/pypa/hatch/blob/master/mkdocs.yml

System information

  • Operating system: Windows 10
  • Browser: Chrome
@squidfunk
Copy link
Owner

squidfunk commented Jun 11, 2022

Thanks for reporting. If this is related to redirects, this sounds like something to be reported on the mike issue tracker. We're only consuming the versions.json file generated by mike.

Edit: Ah, or do you mean that the URL is not preserved when switching versions? I'm confused as you referenced latest as the source, and latest should always be redirecting to the actual version. In any case, please provide a minimum reproducible case, so I can look into it.

@squidfunk squidfunk added the needs input Issue needs further input by the reporter label Jun 11, 2022
@ofek
Copy link
Sponsor Collaborator Author

ofek commented Jun 11, 2022

Go to https://hatch.pypa.io/latest/config/metadata/ then try the 1.1 dropdown and watch the page you're on remain, then go back and try again with 1.2 (what latest is) and watch the page change to home

@squidfunk squidfunk added bug Issue reports a bug and removed needs input Issue needs further input by the reporter labels Jun 12, 2022
@squidfunk
Copy link
Owner

Thanks for the step-by-step guide, that made reproduction simple. That's odd. It seems that it only happens when you change from latest to 1.2. If you first go to 1.0, and then to 1.2, it works as expected.

@squidfunk
Copy link
Owner

I know where this is coming from. Fixed in 7512441.

You've set latest as an alias for 1.2, and the current solution will filter the current version from interception. The reason for this is that we intercept all inter-version links, not only in the language selector, but also in Markdown, and need to filter out all pages on the current version (which is a dedicated MkDocs build) for the "try to find the same page" algorithm:

.filter(version => version !== current)

Commenting out this line fixes the problem. However, we can't just take out the filter, as then all navigation would be intercepted, which will break instant loading. Inter-version navigation and instant loading need to be separate pipelines as they behave entirely differently. Thus, I moved the current$ observable down the pipeline and added a temporary hack that detects whether we initiated inter-version navigation from inside the dropdown or not, and if not, whether we're on the same version. If so, we will stop at this point to let instant loading do its job, if enabled.

Inter-version navigation and instant loading are both in need of refactoring. I will tackle all this when I will next work on instant previews, which use parts of the same logic, as this is a great opportunity for refactoring this.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Jun 12, 2022
@squidfunk
Copy link
Owner

To add: my initial confusion came from the fact that there is a deployment for latest and 1.2, both of which are the same version. I thought that mike always redirects from latest, at least that's what it did when I implemented the logic in the first place. Are separate deployments for aliases a new thing?

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Jun 12, 2022

Thanks for the fix!!!

Not sure how long but https://github.com/jimporter/mike says:

By default, aliases create a simple HTML redirect to the real version of the docs; to create a copy of the docs for each alias, you can pass --no-redirect.

I do that because I like retaining latest in the URL.

@squidfunk
Copy link
Owner

Released as part of 8.3.5.

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Jun 14, 2022

Thank you!!!

@mastercoms
Copy link

I think this has introduced a weird bug in my case:

latest alias: https://docs.mastercomfig.com/latest/
latest version: https://docs.mastercomfig.com/9.9.1/

it gets into a redirect loop going to the latest URL for some reason, appending latest over and over again

@squidfunk
Copy link
Owner

Hmm, I'm not sure I'm seeing the behavior you're describing. Could you elaborate?

@squidfunk
Copy link
Owner

Could you try the latest master? I just pushed a fix for #4028.

@mastercoms
Copy link

Has the same faulty behavior. Note that it does work for https://docs.mastercomfig.com/9.9.1 but not https://docs.mastercomfig.com/9.9.1/. I am hosting using CloudFlare Pages, which I have noticed has a more strict policy for enforcing trailing slashes vs. GitHub Pages.

@squidfunk
Copy link
Owner

squidfunk commented Jun 16, 2022

How did you configure mike? Does latest do a redirect? Other than that, you could please open a new issue, maybe with a reproducible example and some more information, so I can reproduce the issue. Happy to look into it.

@squidfunk
Copy link
Owner

squidfunk commented Jun 16, 2022

@mastercoms – First of all – you urgently need to redeploy your documentation, either with the latest version of Insiders, or with 14.8.0, because currently, navigation (all links) is not working outside of the version selector. This is a regression introduced in the commit linked here and fixed in #4028.


I've checked your docs and I'm not redirected (see video), regardless of whether I append the slash or not. Could you try the same in an incognito window to avoid the browser cache?

Ohne.Titel.mp4

Furthermore, I tried to create re reproducible example myself, but failed – everything worked when I follow the guidelines laid out in our documentation, see: https://squidfunk.github.io/versioning-test/

@mastercoms
Copy link

mastercoms commented Jun 16, 2022

I did deploy that new version, about 8 minutes after you fixed it. That link problem was happening on my PC, and is no longer happening after that deploy, so the new version did deploy. Not sure why it still happens on your end, maybe an out of date edge cache, will look into fixing. I'll make a new issue after looking into isolating this bug. It's strange, because a user reported this redirect bug to me and multiple others were able to confirm it happening.

@squidfunk
Copy link
Owner

Okay, great. The issue is not happening anymore, might have been a caching issue. Regarding the bug, you can check with your users if it also happens for them on https://squidfunk.github.io/versioning-test/

@mastercoms
Copy link

mastercoms commented Jun 17, 2022

After further investigation, this is entirely a Mike issue, will look into it a bit more and report there. Still not sure why it only recently started happening, but sorry for wasting your time!

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Aug 27, 2022

This broke again, now only when anchors are selected e.g. go to https://hatch.pypa.io/latest/intro/#setup then select any version from the dropdown

@squidfunk
Copy link
Owner

@ofek can you try to narrow it down? Happy to look into it with something I can deploy and debug.

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Aug 27, 2022

https://github.com/pypa/hatch/blob/hatchling-v1.8.1/mkdocs.yml was built with mkdocs-material==8.3.9 but don't know when anchors broke version switching

@squidfunk
Copy link
Owner

Actually, I've just tested and it seems that version switching has never worked with anchors 😅 Could you please create a new issue? It's related, but not the same error as this one.

@ofek
Copy link
Sponsor Collaborator Author

ofek commented Aug 28, 2022

#4291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants