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

Stay on page when switching versions broken for default version

ofek opened this issue · comments

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


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



System information

  • Operating system: Windows 10
  • Browser: Chrome

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.

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

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.

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.

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?

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.

Released as part of 8.3.5.

Thank you!!!

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

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

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

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.

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.

@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?


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/

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.

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/

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!

ezoic increase your site revenue