44// SPDX-License-Identifier: Apache-2.0
55import SearchIcon from '@mui/icons-material/Search' ;
66import { Resizable } from 're-resizable' ;
7- import { useEffect , useRef , useState } from 'react' ;
7+ import { useEffect , useLayoutEffect , useRef , useState } from 'react' ;
88
99import { AllowedFrontendChannels } from '../../../shared/ipc-channels' ;
1010import { TRANSITION } from '../../shared-styles' ;
@@ -71,27 +71,35 @@ export const ResizePanels: React.FC<ResizePanelsProps> = ({
7171 const effectiveHeight = height ?? 0 ;
7272 const fraction = FRACTIONS [ main ] ;
7373 const [ isResizing , setIsResizing ] = useState ( true ) ;
74+ const [ containerHeight , setContainerHeight ] = useState < number | undefined > (
75+ undefined ,
76+ ) ;
7477 const containerRef = useRef < Resizable > ( null ) ;
7578 const upperSearchRef = useRef < HTMLInputElement > ( null ) ;
7679 const lowerSearchRef = useRef < HTMLInputElement > ( null ) ;
7780
7881 const isLowerCollapsed = effectiveHeight <= HEADER_HEIGHT ;
7982 const isUpperCollapsed =
80- effectiveHeight >=
81- ( containerRef . current ?. size . height ?? 0 ) - HEADER_HEIGHT - 1 ;
83+ containerHeight !== undefined &&
84+ effectiveHeight >= containerHeight - HEADER_HEIGHT - 1 ;
85+
86+ useLayoutEffect ( ( ) => {
87+ if ( containerRef . current ) {
88+ setContainerHeight ( containerRef . current . size . height ) ;
89+ }
90+ } , [ containerRef . current ?. size . height ] ) ;
8291
8392 useEffect ( ( ) => {
8493 const applyGoldenRatio = ( ) =>
85- containerRef . current &&
86- setHeight ( containerRef . current . size . height / fraction ) ;
94+ containerHeight !== undefined && setHeight ( containerHeight / fraction ) ;
8795
8896 heightIsNull && applyGoldenRatio ( ) ;
8997 window . addEventListener ( 'resize' , applyGoldenRatio ) ;
9098
9199 return ( ) => {
92100 window . removeEventListener ( 'resize' , applyGoldenRatio ) ;
93101 } ;
94- } , [ fraction , heightIsNull , setHeight ] ) ;
102+ } , [ fraction , heightIsNull , setHeight , containerHeight ] ) ;
95103
96104 useIpcRenderer (
97105 upperPanel . search . channel ,
@@ -166,9 +174,7 @@ export const ResizePanels: React.FC<ResizePanelsProps> = ({
166174 size = { { height : height || '50%' , width : 'auto' } }
167175 minHeight = { HEADER_HEIGHT }
168176 maxHeight = {
169- containerRef . current
170- ? containerRef . current . size . height - HEADER_HEIGHT
171- : undefined
177+ containerHeight ? containerHeight - HEADER_HEIGHT : undefined
172178 }
173179 onResizeStart = { ( ) => setIsResizing ( true ) }
174180 onResizeStop = { ( _event , _direction , _ref , delta ) => {
@@ -256,10 +262,10 @@ export const ResizePanels: React.FC<ResizePanelsProps> = ({
256262 disabled = { isLowerCollapsed }
257263 onClick = { ( ) => {
258264 setIsResizing ( true ) ;
259- if ( containerRef . current ) {
260- effectiveHeight <= containerRef . current . size . height / fraction
265+ if ( containerHeight !== undefined ) {
266+ effectiveHeight <= containerHeight / fraction
261267 ? setHeight ( HEADER_HEIGHT )
262- : setHeight ( containerRef . current . size . height / fraction ) ;
268+ : setHeight ( containerHeight / fraction ) ;
263269 }
264270 setIsResizing ( false ) ;
265271 } }
@@ -274,10 +280,10 @@ export const ResizePanels: React.FC<ResizePanelsProps> = ({
274280 disabled = { isUpperCollapsed }
275281 onClick = { ( ) => {
276282 setIsResizing ( true ) ;
277- if ( containerRef . current ) {
278- effectiveHeight < containerRef . current . size . height / fraction
279- ? setHeight ( containerRef . current . size . height / fraction )
280- : setHeight ( containerRef . current . size . height - HEADER_HEIGHT ) ;
283+ if ( containerHeight !== undefined ) {
284+ effectiveHeight < containerHeight / fraction
285+ ? setHeight ( containerHeight / fraction )
286+ : setHeight ( containerHeight - HEADER_HEIGHT ) ;
281287 }
282288 setIsResizing ( false ) ;
283289 } }
0 commit comments