File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 11import { useLayoutEffect , useRef , useState } from 'react' ;
2+ import { flushSync } from 'react-dom' ;
23
34export function useGridDimensions ( ) {
45 const gridRef = useRef < HTMLDivElement > ( null ) ;
@@ -27,9 +28,12 @@ export function useGridDimensions() {
2728 const size = entries [ 0 ] . contentBoxSize [ 0 ] ;
2829 const { clientHeight, offsetHeight } = gridRef . current ! ;
2930
30- setInlineSize ( size . inlineSize ) ;
31- setBlockSize ( size . blockSize ) ;
32- setHorizontalScrollbarHeight ( offsetHeight - clientHeight ) ;
31+ // we use flushSync here to avoid flashing scrollbars
32+ flushSync ( ( ) => {
33+ setInlineSize ( size . inlineSize ) ;
34+ setBlockSize ( size . blockSize ) ;
35+ setHorizontalScrollbarHeight ( offsetHeight - clientHeight ) ;
36+ } ) ;
3337 } ) ;
3438 resizeObserver . observe ( gridRef . current ! ) ;
3539
You can’t perform that action at this time.
0 commit comments