@@ -203,9 +203,10 @@ export function useGridDimensions(apiRef: RefObject<GridPrivateApiCommunity>, pr
203203 // All the floating point dimensions should be rounded to .1 decimal places to avoid subpixel rendering issues
204204 // https://github.com/mui/mui-x/issues/9550#issuecomment-1619020477
205205 // https://github.com/mui/mui-x/issues/15721
206- const rootElement = apiRef . current . rootElementRef . current ;
207-
208- const scrollbarSize = measureScrollbarSize ( rootElement , props . scrollbarSize ) ;
206+ const scrollbarSize = measureScrollbarSize (
207+ apiRef . current . mainElementRef . current ,
208+ props . scrollbarSize ,
209+ ) ;
209210
210211 const rowsMeta = gridRowsMetaSelector ( apiRef . current . state ) ;
211212 const topContainerHeight = headersTotalHeight + rowsMeta . pinnedTopRowsTotalHeight ;
@@ -454,32 +455,32 @@ function getStaticDimensions(
454455}
455456
456457const scrollbarSizeCache = new WeakMap < Element , number > ( ) ;
457- function measureScrollbarSize ( rootElement : Element | null , scrollbarSize : number | undefined ) {
458+ function measureScrollbarSize ( element : Element | null , scrollbarSize : number | undefined ) {
458459 if ( scrollbarSize !== undefined ) {
459460 return scrollbarSize ;
460461 }
461462
462- if ( rootElement === null ) {
463+ if ( element === null ) {
463464 return 0 ;
464465 }
465466
466- const cachedSize = scrollbarSizeCache . get ( rootElement ) ;
467+ const cachedSize = scrollbarSizeCache . get ( element ) ;
467468 if ( cachedSize !== undefined ) {
468469 return cachedSize ;
469470 }
470471
471- const doc = ownerDocument ( rootElement ) ;
472+ const doc = ownerDocument ( element ) ;
472473 const scrollDiv = doc . createElement ( 'div' ) ;
473474 scrollDiv . style . width = '99px' ;
474475 scrollDiv . style . height = '99px' ;
475476 scrollDiv . style . position = 'absolute' ;
476477 scrollDiv . style . overflow = 'scroll' ;
477478 scrollDiv . className = 'scrollDiv' ;
478- rootElement . appendChild ( scrollDiv ) ;
479+ element . appendChild ( scrollDiv ) ;
479480 const size = scrollDiv . offsetWidth - scrollDiv . clientWidth ;
480- rootElement . removeChild ( scrollDiv ) ;
481+ element . removeChild ( scrollDiv ) ;
481482
482- scrollbarSizeCache . set ( rootElement , size ) ;
483+ scrollbarSizeCache . set ( element , size ) ;
483484
484485 return size ;
485486}
0 commit comments