@@ -66,11 +66,9 @@ export const useObserveHeights = (
66
66
67
67
// top header
68
68
useEffect ( ( ) => {
69
- const headerContentResizeObserver = new ResizeObserver ( ( [ header ] ) => {
70
- // Firefox implements `borderBoxSize` as a single content rect, rather than an array
71
- const borderBoxSize = Array . isArray ( header . borderBoxSize ) ? header . borderBoxSize [ 0 ] : header . borderBoxSize ;
72
- // Safari doesn't implement `borderBoxSize`
73
- setTopHeaderHeight ( borderBoxSize ?. blockSize ?? header . target . getBoundingClientRect ( ) . height ) ;
69
+ const headerContentResizeObserver = new ResizeObserver ( ( [ entry ] ) => {
70
+ const { blockSize } = entry . borderBoxSize [ 0 ] ;
71
+ setTopHeaderHeight ( blockSize ) ;
74
72
} ) ;
75
73
if ( topHeaderRef ?. current ) {
76
74
headerContentResizeObserver . observe ( topHeaderRef . current ) ;
@@ -82,14 +80,10 @@ export const useObserveHeights = (
82
80
83
81
// header content
84
82
useEffect ( ( ) => {
85
- const headerContentResizeObserver = new ResizeObserver ( ( [ headerContent ] ) => {
86
- if ( isIntersecting ) {
87
- // Firefox implements `borderBoxSize` as a single content rect, rather than an array
88
- const borderBoxSize = Array . isArray ( headerContent . borderBoxSize )
89
- ? headerContent . borderBoxSize [ 0 ]
90
- : headerContent . borderBoxSize ;
91
- // Safari doesn't implement `borderBoxSize`
92
- setHeaderContentHeight ( borderBoxSize ?. blockSize ?? headerContent . target . getBoundingClientRect ( ) . height ) ;
83
+ const headerContentResizeObserver = new ResizeObserver ( ( [ entry ] ) => {
84
+ if ( isIntersecting || fixedHeader ) {
85
+ const { blockSize } = entry . borderBoxSize [ 0 ] ;
86
+ setHeaderContentHeight ( blockSize ) ;
93
87
}
94
88
} ) ;
95
89
@@ -99,7 +93,7 @@ export const useObserveHeights = (
99
93
return ( ) => {
100
94
headerContentResizeObserver . disconnect ( ) ;
101
95
} ;
102
- } , [ isIntersecting ] ) ;
96
+ } , [ isIntersecting , fixedHeader ] ) ;
103
97
const totalHeaderHeight = noHeader ? 0 : topHeaderHeight + headerContentHeight ;
104
98
105
99
return { topHeaderHeight, headerContentHeight, totalHeaderHeight, headerCollapsed } ;
0 commit comments