diff --git a/mu-plugins/blocks/sidebar-container/src/view.js b/mu-plugins/blocks/sidebar-container/src/view.js index 7066d83b4..13a68fb2b 100644 --- a/mu-plugins/blocks/sidebar-container/src/view.js +++ b/mu-plugins/blocks/sidebar-container/src/view.js @@ -85,15 +85,6 @@ function isSidebarWithinViewport( container ) { function init() { const container = document.querySelector( '.wp-block-wporg-sidebar-container' ); - - if ( container ) { - if ( isSidebarWithinViewport( container ) ) { - container.classList.add( 'is-fixed-sidebar' ); - onScroll(); // Run once to avoid footer collisions on load (ex, when linked to #reply-title). - window.addEventListener( 'scroll', onScroll ); - } - } - const toggleButton = container?.querySelector( '.wporg-table-of-contents__toggle' ); const list = container?.querySelector( '.wporg-table-of-contents__list' ); @@ -146,6 +137,14 @@ function init() { } ); } + if ( container ) { + if ( isSidebarWithinViewport( container ) ) { + container.classList.add( 'is-fixed-sidebar' ); + onScroll(); // Run once to avoid footer collisions on load (ex, when linked to #reply-title). + window.addEventListener( 'scroll', onScroll ); + } + } + // If there is no table of contents, hide the heading. if ( ! document.querySelector( '.wp-block-wporg-table-of-contents' ) ) { const heading = document.querySelector( '.wp-block-wporg-sidebar-container h2' );