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

Version switcher displays Choose version instead of actual version #1829

Closed
hcording opened this issue May 23, 2024 · 2 comments
Closed

Version switcher displays Choose version instead of actual version #1829

hcording opened this issue May 23, 2024 · 2 comments
Labels
needs: more information Needs more information from the author before we can move forward

Comments

@hcording
Copy link

Related to: #1681, #1500, #1512

When opening any built page on RTD with this theme, the switcher menu shows "Choose version" instead of the selected version. I largely followed the conf.py for this repo, especially after reading #1512.
From what I can see, my tags and settings are fairly standard, the only difference is that I dynamically load
name, author, copyright, release and version from .pyproject.toml and .bump_my_version.toml. But I added print statements and the build log shows these values are initialized correctly (version == release == 0.0.7 on stable, for example).

My versioning scheme follows semver, and works as follows: x.y.z-alphaN, x.y.z-betaN, x.y.z-rcN, x.y.z

conf.py

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import datetime
import os
import sys
from pathlib import Path

import toml

sys.path.insert(0, os.path.abspath('../'))

# -- Project information -----------------------------------------------------

pyproject_toml_dict: dict = toml.load(
    Path(__file__).parents[1] / "pyproject.toml")
project_dict: dict = pyproject_toml_dict["project"]
project = project_dict["name"]
_authors: list[dict] = project_dict["authors"]
author: str = ", ".join([f"{a['name']} <{a['email']}>" for a in _authors])
copyright: str = f'{datetime.datetime.now().year}, {author}'

bumpversion_toml = toml.load(Path(__file__).parents[1] / ".bumpversion.toml")
release: str = bumpversion_toml["tool"]["bumpversion"]["current_version"] # e.g., this becomes 0.0.7 on stable
version: str = release

print(version)

# -- General configuration ---------------------------------------------------

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
    'sphinx.ext.coverage',
    'sphinx.ext.doctest',
    'sphinx.ext.mathjax',
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- Options for HTML output -------------------------------------------------

version_match = os.environ.get("READTHEDOCS_VERSION")
if not version_match or version_match.isdigit() or version_match == "latest":
    # For local development, infer the version to match from the package.
    if '-' in release:
        version_match = "dev"
        json_url = "_static/switcher.json"
    else:
        version_match = release
elif version_match == "stable":
    version_match = release

html_theme = 'pydata_sphinx_theme'
html_static_path = ['_static']
json_url = "https://impart.readthedocs.io/en/latest/_static/switcher.json"

html_theme_options = {
    "switcher": {
        "version_match": version_match,
        "json_url": json_url,
    },
    "footer_start": [
        "version-switcher"
    ],
    "show_version_warning_banner": True,
}
html_show_sourcelink = False
html_title = f"{project} {release}"

And this is my switcher.json, located in docs/_static/:

[
    {
        "name": "dev",
        "version": "dev",
        "url": "https://impart.readthedocs.io/en/latest/"
    },
    {
        "name": "0.0.7 (stable)",
        "version": "0.0.7",
        "url": "https://impart.readthedocs.io/en/stable/",
        "preferred": true
    },
    {
        "name": "0.0.6",
        "version": "0.0.6",
        "url": "https://impart.readthedocs.io/en/0.0.6/"
    },
    {
        "name": "0.0.5",
        "version": "0.0.5",
        "url": "https://impart.readthedocs.io/en/0.0.5/"
    }
]

I see the following when opening the stable page the first time after building:

image

After reloading the page, or clicking on 0.0.7 (stable), it looks like this (and remains like this for consecutive page visits):

image

Any help is appreciated!

@drammock
Copy link
Collaborator

drammock commented Jun 4, 2024

If I load https://impart.readthedocs.io/en/stable/ and view the browser devtools console, I see

Uncaught (in promise) TypeError: document.querySelector(...) is null
    T pydata-sphinx-theme.js:569
    r mixin.js:11
    937 pydata-sphinx-theme.js:584

I see your site was built with version 0.15.2 of the theme. I think this problem was fixed as a side-effect of #1780

Can you see if it still happens when building the docs with the current version of the theme (0.15.3)?

@drammock drammock added the needs: more information Needs more information from the author before we can move forward label Jun 4, 2024
@hcording
Copy link
Author

hcording commented Jun 7, 2024

I've gone ahead and updated to 0.15.3, which fixed the issue! 🥳
The switcher now shows the correct version in the preview.

As a side note, the vertical cyan bar to indicate the currently selected version when the switcher is expanded seems to work only sometimes. For me, it will often disappear after reloading the page. But that's another issue.

Anyways, thanks for the update!
Closing as resolved.

@hcording hcording closed this as completed Jun 7, 2024
Carreau pushed a commit that referenced this issue Jun 12, 2024
when looking into the cause of #1829 I found a couple cases where
`document.querySelector` might be `null` and we don't handle that very
gracefully.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: more information Needs more information from the author before we can move forward
Projects
None yet
Development

No branches or pull requests

2 participants