@@ -347,6 +347,14 @@ async function fetchVersionSwitcherJSON(url) {
347
347
var result = new URL ( url ) ;
348
348
} catch ( err ) {
349
349
if ( err instanceof TypeError ) {
350
+ if ( ! window . location . origin ) {
351
+ // window.location.origin is null for local static sites
352
+ // (ie. window.location.protocol == 'file:')
353
+ //
354
+ // TODO: Fix this to return the static version switcher by working out
355
+ // how to get the correct path to the switcher JSON file on local static builds
356
+ return null ;
357
+ }
350
358
// assume we got a relative path, and fix accordingly. But first, we need to
351
359
// use `fetch()` to follow redirects so we get the correct final base URL
352
360
const origin = await fetch ( window . location . origin , { method : "HEAD" } ) ;
@@ -556,9 +564,13 @@ if (hasVersionsJSON && (hasSwitcherMenu || wantsWarningBanner)) {
556
564
const data = await fetchVersionSwitcherJSON (
557
565
DOCUMENTATION_OPTIONS . theme_switcher_json_url
558
566
) ;
559
- populateVersionSwitcher ( data , versionSwitcherBtns ) ;
560
- if ( wantsWarningBanner ) {
561
- showVersionWarningBanner ( data ) ;
567
+ // TODO: remove the `if(data)` once the `return null` is fixed within fetchVersionSwitcherJSON.
568
+ // We don't really want the switcher and warning bar to silently not work.
569
+ if ( data ) {
570
+ populateVersionSwitcher ( data , versionSwitcherBtns ) ;
571
+ if ( wantsWarningBanner ) {
572
+ showVersionWarningBanner ( data ) ;
573
+ }
562
574
}
563
575
}
564
576
0 commit comments