Skip to content

Commit 715ede2

Browse files
committed
fix from Coderabbit QA
1 parent 4c1d363 commit 715ede2

File tree

1 file changed

+12
-7
lines changed
  • src/components/design-library-list

1 file changed

+12
-7
lines changed

src/components/design-library-list/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,21 @@ const DesignLibraryItem = props => {
114114
}
115115

116116
useEffect( () => {
117-
if ( ! itemRef.current ) {
118-
return
119-
}
120-
121117
// Use a timeout to ensure designs have finished rendering before calculating visibility.
122118
const timeoutRef = setTimeout( () => {
123-
const containerRect = document.querySelector( '.ugb-modal-design-library__designs' ).getBoundingClientRect()
124-
const itemRect = itemRef.current.getBoundingClientRect()
119+
const itemEl = itemRef.current
120+
const containerEl = itemEl?.closest( '.ugb-modal-design-library__designs' ) || document.querySelector( '.ugb-modal-design-library__designs' )
121+
122+
if ( ! itemEl || ! containerEl ) {
123+
return
124+
}
125+
126+
const containerRect = containerEl.getBoundingClientRect()
127+
const itemRect = itemEl.getBoundingClientRect()
128+
129+
const BOUNDARY = 250
125130

126-
const render = itemRect.bottom >= containerRect.top - 250 && itemRect.top <= containerRect.bottom + 250
131+
const render = itemRect.bottom >= containerRect.top - BOUNDARY && itemRect.top <= containerRect.bottom + BOUNDARY
127132

128133
setShouldRender( render )
129134
}, 250 )

0 commit comments

Comments
 (0)