@@ -735,14 +735,15 @@ function loadCss(cssFileName) {
735735 let oldSidebarScrollPosition = null ;
736736
737737 function showSidebar ( ) {
738- if ( window . innerWidth < window . RUSTDOC_MOBILE_BREAKPOINT ) {
738+ const mobile_topbar = document . querySelector ( ".mobile-topbar" ) ;
739+ if ( window . innerWidth < window . RUSTDOC_MOBILE_BREAKPOINT && mobile_topbar ) {
739740 // This is to keep the scroll position on mobile.
740741 oldSidebarScrollPosition = window . scrollY ;
741742 document . body . style . width = `${ document . body . offsetWidth } px` ;
742743 document . body . style . position = "fixed" ;
743744 document . body . style . top = `-${ oldSidebarScrollPosition } px` ;
744- document . querySelector ( ".mobile-topbar" ) . style . top = `${ oldSidebarScrollPosition } px` ;
745- document . querySelector ( ".mobile-topbar" ) . style . position = "relative" ;
745+ mobile_topbar . style . top = `${ oldSidebarScrollPosition } px` ;
746+ mobile_topbar . style . position = "relative" ;
746747 } else {
747748 oldSidebarScrollPosition = null ;
748749 }
@@ -751,13 +752,14 @@ function loadCss(cssFileName) {
751752 }
752753
753754 function hideSidebar ( ) {
754- if ( oldSidebarScrollPosition !== null ) {
755+ const mobile_topbar = document . querySelector ( ".mobile-topbar" ) ;
756+ if ( oldSidebarScrollPosition !== null && mobile_topbar ) {
755757 // This is to keep the scroll position on mobile.
756758 document . body . style . width = "" ;
757759 document . body . style . position = "" ;
758760 document . body . style . top = "" ;
759- document . querySelector ( ".mobile-topbar" ) . style . top = "" ;
760- document . querySelector ( ".mobile-topbar" ) . style . position = "" ;
761+ mobile_topbar . style . top = "" ;
762+ mobile_topbar . style . position = "" ;
761763 // The scroll position is lost when resetting the style, hence why we store it in
762764 // `oldSidebarScrollPosition`.
763765 window . scrollTo ( 0 , oldSidebarScrollPosition ) ;
0 commit comments