Skip to content

Duplicated version menu on navigation for mkdocs #12032

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

Closed
ZedThree opened this issue Feb 28, 2025 · 7 comments · Fixed by #12142
Closed

Duplicated version menu on navigation for mkdocs #12032

ZedThree opened this issue Feb 28, 2025 · 7 comments · Fixed by #12142
Assignees
Labels
Accepted Accepted issue on our roadmap Needed: documentation Documentation is required

Comments

@ZedThree
Copy link

Details

Actual Result

When I click links in the left-hand nav pane, a new version drop-down menu (<div class=md-version>) appears in the top nav bar:

Image

This doesn't happen locally, as this is the RTD inserted menu.

Expected Result

Just one drop-menu version menu stays there.

@humitos
Copy link
Member

humitos commented Feb 28, 2025

Hi. Did you fix this issue already? I can't reproduce it.

@ZedThree
Copy link
Author

ZedThree commented Mar 3, 2025

Nope, still happening for me. I've tried on four separate browsers (Vivaldi, Firefox, Chrome, Edge), on three devices (Linux desktop, Android, Windows 11)

@humitos humitos added Bug A bug Accepted Accepted issue on our roadmap labels Mar 18, 2025
@humitos humitos self-assigned this Mar 18, 2025
@github-project-automation github-project-automation bot moved this to Planned in 📍Roadmap Mar 18, 2025
@humitos
Copy link
Member

humitos commented Mar 18, 2025

Are you using the example from our docs to generate that version selector? This one https://docs.readthedocs.com/platform/latest/intro/mkdocs.html#integrate-the-read-the-docs-version-menu-into-your-site-navigation

@ZedThree
Copy link
Author

Yup, here's the entirety of our javascript/readthedocs.js:

document.addEventListener("DOMContentLoaded", function(event) {
// Trigger Read the Docs' search addon instead of Material MkDocs default
document.querySelector(".md-search__input").addEventListener("focus", (e) => {
        const event = new CustomEvent("readthedocs-search-show");
        document.dispatchEvent(event);
    });
});

// Use CustomEvent to generate the version selector
document.addEventListener(
        "readthedocs-addons-data-ready",
        function (event) {
        const config = event.detail.data();
        const versioning = `
<div class="md-version">
<button class="md-version__current" aria-label="Select version">
    ${config.versions.current.slug}
</button>

<ul class="md-version__list">
${ config.versions.active.map(
    (version) => `
    <li class="md-version__item">
    <a href="${ version.urls.documentation }" class="md-version__link">
        ${ version.slug }
    </a>
            </li>`).join("\n")}
</ul>
</div>`;

    document.querySelector(".md-header__topic").insertAdjacentHTML("beforeend", versioning);
});

@humitos
Copy link
Member

humitos commented Mar 19, 2025

I think this happens because you have "Instant loading" enabled in your project at https://github.com/PlasmaFAIR/fortitude/blob/main/mkdocs.yml#L12C7-L12C25

If you disable that, it should work without issues.

To keep that feature enabled, the JS code has to be modified to avoid re-adding the version selector if it's already added, or -- delete the version selector and re-add it to avoid duplication.

@humitos humitos added Needed: documentation Documentation is required and removed Bug A bug labels Mar 19, 2025
@ZedThree
Copy link
Author

My javascript is pretty poor, I have tried inserting:

document.querySelector(".md-version").remove();

just before the .insertAdjacentHTML call, and this seemed to remove the drop-down menu entirely. I think we'll just make do with disabling one or the other of these features

@humitos
Copy link
Member

humitos commented Apr 29, 2025

@ZedThree I opened a PR that removes the old versions before re-adding them. Can you give it a try?

humitos added a commit that referenced this issue Apr 30, 2025
Closes #12032

<!-- readthedocs-preview docs start -->
---
:books: Documentation previews :books:

- User's documentation (`docs`):
https://docs--12142.org.readthedocs.build/12142/

<!-- readthedocs-preview docs end -->

<!-- readthedocs-preview dev start -->
- Developer's documentation (`dev`):
https://dev--12142.org.readthedocs.build/12142/

<!-- readthedocs-preview dev end -->

---------

Co-authored-by: Anthony <[email protected]>
@github-project-automation github-project-automation bot moved this from Needs review to Done in 📍Roadmap Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Needed: documentation Documentation is required
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants