From 10aae09807570a5f569735c724a45096592c7417 Mon Sep 17 00:00:00 2001 From: Andrew Cherniavskyi Date: Wed, 20 Nov 2024 23:03:12 +0100 Subject: [PATCH 1/2] return early if no scroller --- .../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 86435660917e7..9fb3bad9bd357 100644 --- a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx +++ b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx @@ -216,9 +216,14 @@ export const useGridVirtualScroller = () => { ); const triggerUpdateRenderContext = useEventCallback(() => { + const scroller = scrollerRef.current; + if (!scroller) { + return; + } + const newScroll = { - top: scrollerRef.current!.scrollTop, - left: scrollerRef.current!.scrollLeft, + top: scroller.scrollTop, + left: scroller.scrollLeft, }; const dx = newScroll.left - scrollPosition.current.left; From 805c47cb59b4f778530216c3c818886da5371cd9 Mon Sep 17 00:00:00 2001 From: Andrew Cherniavskyi Date: Thu, 28 Nov 2024 15:00:43 +0100 Subject: [PATCH 2/2] lint --- .../hooks/features/virtualization/useGridVirtualScroller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1dfd7bf38337b..1502dfbf4ec61 100644 --- a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx +++ b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx @@ -269,7 +269,7 @@ export const useGridVirtualScroller = () => { const triggerUpdateRenderContext = useEventCallback(() => { const scroller = scrollerRef.current; if (!scroller) { - return; + return undefined; } const newScroll = {