@@ -316,23 +316,31 @@ const ObjectPage: FC<ObjectPagePropTypes> = forwardRef((props: ObjectPagePropTyp
316316
317317 useEffect ( ( ) => {
318318 const fillerDivObserver = new ResizeObserver ( ( ) => {
319+ let heightDiff = 0 ;
320+
319321 const maxHeight = Math . min ( objectPageRef . current ?. clientHeight , window . innerHeight ) ;
320322 const availableScrollHeight = maxHeight - totalHeaderHeight ;
321323 const lastSectionDomRef = getLastObjectPageSection ( objectPageRef ) ;
322- const subSections = lastSectionDomRef . querySelectorAll ( '[id^="ObjectPageSubSection"]' ) ;
323324
324- let lastSubSectionHeight ;
325- if ( subSections . length > 0 ) {
326- lastSubSectionHeight = ( subSections [ subSections . length - 1 ] as HTMLElement ) . offsetHeight ;
327- } else {
328- lastSubSectionHeight =
329- lastSectionDomRef . offsetHeight -
330- lastSectionDomRef . querySelector < HTMLElement > ( "[role='heading']" ) . offsetHeight ;
331- }
325+ if ( lastSectionDomRef ) {
326+ const subSections = lastSectionDomRef . querySelectorAll ( '[id^="ObjectPageSubSection"]' ) ;
327+
328+ let lastSubSectionHeight ;
329+ if ( subSections . length > 0 ) {
330+ lastSubSectionHeight = ( subSections [ subSections . length - 1 ] as HTMLElement ) . offsetHeight ;
331+ } else {
332+ lastSubSectionHeight =
333+ lastSectionDomRef . offsetHeight -
334+ lastSectionDomRef . querySelector < HTMLElement > ( "[role='heading']" ) . offsetHeight ;
335+ }
336+
337+ heightDiff = Math . max ( 0 , availableScrollHeight - lastSubSectionHeight ) ;
332338
333- let heightDiff = availableScrollHeight - lastSubSectionHeight ;
339+ if ( isNaN ( heightDiff ) ) {
340+ heightDiff = 0 ;
341+ }
342+ }
334343
335- heightDiff = heightDiff > 0 ? heightDiff : 0 ;
336344 objectPageRef . current ?. style . setProperty ( ObjectPageCssVariables . lastSectionMargin , `${ heightDiff } px` ) ;
337345 } ) ;
338346
0 commit comments