|
4 | 4 | // SPDX-License-Identifier: Apache-2.0 |
5 | 5 | import SearchIcon from '@mui/icons-material/Search'; |
6 | 6 | import { Resizable } from 're-resizable'; |
7 | | -import { useEffect, useRef, useState } from 'react'; |
| 7 | +import { useEffect, useLayoutEffect, useRef, useState } from 'react'; |
8 | 8 |
|
9 | 9 | import { AllowedFrontendChannels } from '../../../shared/ipc-channels'; |
10 | 10 | import { TRANSITION } from '../../shared-styles'; |
@@ -71,14 +71,20 @@ export const ResizePanels: React.FC<ResizePanelsProps> = ({ |
71 | 71 | const effectiveHeight = height ?? 0; |
72 | 72 | const fraction = FRACTIONS[main]; |
73 | 73 | const [isResizing, setIsResizing] = useState(true); |
| 74 | + const [containerHeight, setContainerHeight] = useState(0); |
74 | 75 | const containerRef = useRef<Resizable>(null); |
75 | 76 | const upperSearchRef = useRef<HTMLInputElement>(null); |
76 | 77 | const lowerSearchRef = useRef<HTMLInputElement>(null); |
77 | 78 |
|
78 | 79 | const isLowerCollapsed = effectiveHeight <= HEADER_HEIGHT; |
79 | 80 | const isUpperCollapsed = |
80 | | - effectiveHeight >= |
81 | | - (containerRef.current?.size.height ?? 0) - HEADER_HEIGHT - 1; |
| 81 | + effectiveHeight >= containerHeight - HEADER_HEIGHT - 1; |
| 82 | + |
| 83 | + useLayoutEffect(() => { |
| 84 | + if (containerRef.current) { |
| 85 | + setContainerHeight(containerRef.current.size.height); |
| 86 | + } |
| 87 | + }, [containerRef.current?.size.height]); |
82 | 88 |
|
83 | 89 | useEffect(() => { |
84 | 90 | const applyGoldenRatio = () => |
@@ -166,9 +172,7 @@ export const ResizePanels: React.FC<ResizePanelsProps> = ({ |
166 | 172 | size={{ height: height || '50%', width: 'auto' }} |
167 | 173 | minHeight={HEADER_HEIGHT} |
168 | 174 | maxHeight={ |
169 | | - containerRef.current |
170 | | - ? containerRef.current.size.height - HEADER_HEIGHT |
171 | | - : undefined |
| 175 | + containerHeight ? containerHeight - HEADER_HEIGHT : undefined |
172 | 176 | } |
173 | 177 | onResizeStart={() => setIsResizing(true)} |
174 | 178 | onResizeStop={(_event, _direction, _ref, delta) => { |
|
0 commit comments