1- import { useCallback , useEffect , useRef , useState } from 'react' ;
1+ import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
22import * as ReactDOM from 'react-dom' ;
33import { css } from '@patternfly/react-styles' ;
44import {
@@ -290,7 +290,8 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
290290 const dragOverlay = < DragOverlay > { activeId && getDragOverlay ( ) } </ DragOverlay > ;
291291
292292 // Find the React root element dynamically instead of hardcoding 'root'
293- const getRootElement = ( ) => {
293+ // Memoized to avoid looking up the root element on every render
294+ const rootElement = useMemo ( ( ) => {
294295 // Try common root element IDs
295296 const commonRootIds = [ 'root' , 'app' , 'main' , '__next' ] ;
296297 for ( const id of commonRootIds ) {
@@ -301,7 +302,7 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
301302 }
302303 // Fallback to document.body if no common root is found
303304 return document . body ;
304- } ;
305+ } , [ ] ) ; // Empty deps - root element doesn't change after mount
305306
306307 return (
307308 < DndContext
@@ -314,7 +315,7 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
314315 { ...props }
315316 >
316317 { children }
317- { canUseDOM ? ReactDOM . createPortal ( dragOverlay , getRootElement ( ) ) : dragOverlay }
318+ { canUseDOM ? ReactDOM . createPortal ( dragOverlay , rootElement ) : dragOverlay }
318319 </ DndContext >
319320 ) ;
320321} ;
0 commit comments