Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions packages/main/src/internal/useObserveHeights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ export const useObserveHeights = (

// top header
useEffect(() => {
const headerContentResizeObserver = new ResizeObserver(([header]) => {
// Firefox implements `borderBoxSize` as a single content rect, rather than an array
const borderBoxSize = Array.isArray(header.borderBoxSize) ? header.borderBoxSize[0] : header.borderBoxSize;
// Safari doesn't implement `borderBoxSize`
setTopHeaderHeight(borderBoxSize?.blockSize ?? header.target.getBoundingClientRect().height);
const headerContentResizeObserver = new ResizeObserver(([entry]) => {
const { blockSize } = entry.borderBoxSize[0];
setTopHeaderHeight(blockSize);
});
if (topHeaderRef?.current) {
headerContentResizeObserver.observe(topHeaderRef.current);
Expand All @@ -82,14 +80,10 @@ export const useObserveHeights = (

// header content
useEffect(() => {
const headerContentResizeObserver = new ResizeObserver(([headerContent]) => {
if (isIntersecting) {
// Firefox implements `borderBoxSize` as a single content rect, rather than an array
const borderBoxSize = Array.isArray(headerContent.borderBoxSize)
? headerContent.borderBoxSize[0]
: headerContent.borderBoxSize;
// Safari doesn't implement `borderBoxSize`
setHeaderContentHeight(borderBoxSize?.blockSize ?? headerContent.target.getBoundingClientRect().height);
const headerContentResizeObserver = new ResizeObserver(([entry]) => {
if (isIntersecting || fixedHeader) {
const { blockSize } = entry.borderBoxSize[0];
setHeaderContentHeight(blockSize);
}
});

Expand All @@ -99,7 +93,7 @@ export const useObserveHeights = (
return () => {
headerContentResizeObserver.disconnect();
};
}, [isIntersecting]);
}, [isIntersecting, fixedHeader]);
const totalHeaderHeight = noHeader ? 0 : topHeaderHeight + headerContentHeight;

return { topHeaderHeight, headerContentHeight, totalHeaderHeight, headerCollapsed };
Expand Down
Loading