diff --git a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js index b0e65ab1dc..72a7022dab 100644 --- a/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js +++ b/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js @@ -347,6 +347,10 @@ async function fetchVersionSwitcherJSON(url) { var result = new URL(url); } catch (err) { if (err instanceof TypeError) { + if (window.location.protocol == "file:") { + // TODO: Fix this to return the version switcher on static builds + return null; + } // assume we got a relative path, and fix accordingly. But first, we need to // use `fetch()` to follow redirects so we get the correct final base URL const origin = await fetch(window.location.origin, { method: "HEAD" }); @@ -556,9 +560,11 @@ if (hasVersionsJSON && (hasSwitcherMenu || wantsWarningBanner)) { const data = await fetchVersionSwitcherJSON( DOCUMENTATION_OPTIONS.theme_switcher_json_url ); - populateVersionSwitcher(data, versionSwitcherBtns); - if (wantsWarningBanner) { - showVersionWarningBanner(data); + if (data) { + populateVersionSwitcher(data, versionSwitcherBtns); + if (wantsWarningBanner) { + showVersionWarningBanner(data); + } } }