mkdocs-material: Version switcher lately never succeeds at staying on the same page

Bug description

(Update: This reproduction no longer works – or rather, there is no bug, everything works as intended – after I downgraded that website to be compiled with the old 9.5.4 version of mkdocs-material. It should be possible to reproduce this with https://github.com/squidfunk/mkdocs-material-example-versioning, but it requires recompiling that website with a recent version of mkdocs-material)

  1. Go to https://martinvonz.github.io/jj/prerelease/config/
  2. Use the version switcher to switch to the “v0.17.0” version

Observed: you end up at https://martinvonz.github.io/jj/v0.17.0/

Desired behavior: you should end up at https://martinvonz.github.io/jj/v0.17.0/config/

Context

I can flesh out this bug report if desired, but I believe I found the likely culprit to be https://github.com/squidfunk/mkdocs-material/commit/a6282931efa2a79665333d41e50bc532367b671a, specifically the changes to the fetchSitemap and extract functions.

After that commit, something clearly wrong is happening in:

https://github.com/squidfunk/mkdocs-material/blob/c1336ae0f598a47828c44073fb6491f622280e0d/src/templates/assets/javascripts/integrations/version/index.ts#L135-L139

As I debug, with the reproduction I describe below, I find that sitemap is a Map object with value (as abbreviated by the Firefox debugger):


Map(31) {
"https://martinvonz.github.io/jj/v0.17.0/" → (1) [...],
"https://martinvonz.github.io/jj/v0.17.0/FAQ/" → (1) [...],
"https://martinvonz.github.io/jj/v0.17.0/branches/" → (1) [...],
... }

​```

Meanwhile, path.split("#")[0] has the value “config/”. So, the operation sitemap.has(path.split("#")[0]) cannot evaluate to true.

Related links

https://squidfunk.github.io/mkdocs-material/setup/setting-up-versioning/?h=version#stay-on-the-same-page-when-switching-versions

Reproduction

See description

Steps to reproduce

See description

Browser

Firefox 125.0.3 on Mac OS Sonoma

Before submitting

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Perhaps you could try checking out my hunch about the URLs that are stored in the sitemap:

However, I see that your site has different URLs in the sitemap, so the hunch is likely incorrect 🤔 It properly stores the current /version/ in the URLs, instead of reusing a static one.

This “shadow” issue has been here for quite some time, good that someone is willing to properly debug it 💪