From ca82e6e1bad888ac026f742ca8794dbeb4621ee8 Mon Sep 17 00:00:00 2001 From: Andrew Cherniavskii Date: Thu, 28 Nov 2024 15:51:16 +0100 Subject: [PATCH] [DataGrid] Fix scroll error (#15521) --- .../features/virtualization/useGridVirtualScroller.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx index 499c21a66c40b..1502dfbf4ec61 100644 --- a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx +++ b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx @@ -267,9 +267,14 @@ export const useGridVirtualScroller = () => { ); const triggerUpdateRenderContext = useEventCallback(() => { + const scroller = scrollerRef.current; + if (!scroller) { + return undefined; + } + const newScroll = { - top: scrollerRef.current!.scrollTop, - left: scrollerRef.current!.scrollLeft, + top: scroller.scrollTop, + left: scroller.scrollLeft, }; const dx = newScroll.left - scrollPosition.current.left;