Skip to content

Version switcher lately never succeeds at staying on the same page #7160

@ilyagr

Description

@ilyagr

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 a628293, specifically the changes to the fetchSitemap and extract functions.

After that commit, something clearly wrong is happening in:

const location = getLocation()
const path = location.href.replace(config.base, "")
return sitemap.has(path.split("#")[0])
? new URL(`../${version}/${path}`, config.base)
: new URL(url)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions