From f84d616d6685365a2010e6f5c67cd7ecb68ca515 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:10:18 +1300 Subject: [PATCH] Sidebar container: Only observe main sidebar height when floating This avoids setting a min-height on main on smaller devices, leading to longer than necessary page lengths. See https://github.com/WordPress/wporg-mu-plugins/issues/611 --- mu-plugins/blocks/sidebar-container/src/view.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mu-plugins/blocks/sidebar-container/src/view.js b/mu-plugins/blocks/sidebar-container/src/view.js index 7b797b8e..6f5455f0 100644 --- a/mu-plugins/blocks/sidebar-container/src/view.js +++ b/mu-plugins/blocks/sidebar-container/src/view.js @@ -106,13 +106,16 @@ function init() { // When the sidebar container adjacent to the main element (usually the chapter list) // is taller than the main element, a glitch occurs when scrolling past the point where // the sidebar becomes fixed, because the main element height depends on the sidebar container - // height. To avoid this, we observe the height of this container when it is not fixed, and - // set the min-height of the main element to match the container height. + // height. To avoid this, we observe the height of this container when it is floating and + // not fixed, and set the min-height of the main element to match the container height. const isSibling = container.previousElementSibling === main || container.nextElementSibling === main; if ( 'ResizeObserver' in window && isSibling ) { const resizeObserver = new ResizeObserver( ( entries ) => { for ( const entry of entries ) { - if ( ! container.classList.contains( 'is-fixed-sidebar' ) ) { + if ( + container.classList.contains( 'is-floating-sidebar' ) && + ! container.classList.contains( 'is-fixed-sidebar' ) + ) { const containerHeight = entry.contentRect.height; if ( containerHeight ) {