From 1368c2bd50195faec30c39e5d0d19caef649363c Mon Sep 17 00:00:00 2001 From: jeffvli Date: Sat, 1 Nov 2025 01:28:14 -0700 Subject: [PATCH] debounce grid loader --- .../item-grid-list/item-grid-list.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/renderer/components/item-list/item-grid-list/item-grid-list.tsx b/src/renderer/components/item-list/item-grid-list/item-grid-list.tsx index a53395d6b..2f8794d66 100644 --- a/src/renderer/components/item-list/item-grid-list/item-grid-list.tsx +++ b/src/renderer/components/item-list/item-grid-list/item-grid-list.tsx @@ -130,16 +130,6 @@ const VirtualizedGridList = React.memo( }; }, [enableSelection, enableExpansion, internalState, tableMeta, data, itemType, gap]); - const handleOnRangeChanged = useCallback( - ({ visibleStartIndex, visibleStopIndex }: ListOnItemsRenderedProps) => { - onRangeChanged?.({ - startIndex: visibleStartIndex * (tableMeta?.columnCount || 0), - stopIndex: visibleStopIndex * (tableMeta?.columnCount || 0), - }); - }, - [tableMeta?.columnCount, onRangeChanged], - ); - const debouncedOnScrollEnd = useMemo( () => onScrollEnd @@ -164,6 +154,15 @@ const VirtualizedGridList = React.memo( [onScroll, debouncedOnScrollEnd], ); + const debouncedOnItemsRendered = useMemo(() => { + return debounce((items: ListOnItemsRenderedProps) => { + onRangeChanged?.({ + startIndex: items.visibleStartIndex * (tableMeta?.columnCount || 0), + stopIndex: items.visibleStopIndex * (tableMeta?.columnCount || 0), + }); + }, 50); + }, [onRangeChanged, tableMeta?.columnCount]); + if (!tableMeta) { return null; } @@ -179,7 +178,7 @@ const VirtualizedGridList = React.memo( itemCount={itemData.tableMeta?.rowCount || 0} itemData={itemData} itemSize={itemData.tableMeta?.itemHeight || 0} - onItemsRendered={handleOnRangeChanged} + onItemsRendered={debouncedOnItemsRendered} onScroll={handleOnScroll} outerRef={outerRef} ref={ref}