fix memory leak on table autoscroll

This commit is contained in:
jeffvli
2026-01-21 00:32:48 -08:00
parent c3c18e22ea
commit b7cbb3055a
@@ -104,8 +104,9 @@ export const useTablePaneSync = ({
target: root, target: root,
}); });
let autoScrollCleanup: (() => void) | null = null;
if (enableDrag) { if (enableDrag) {
autoScrollForElements({ autoScrollCleanup = autoScrollForElements({
canScroll: () => true, canScroll: () => true,
element: viewport, element: viewport,
getAllowedAxis: () => 'vertical', getAllowedAxis: () => 'vertical',
@@ -114,6 +115,10 @@ export const useTablePaneSync = ({
} }
return () => { return () => {
if (autoScrollCleanup) {
autoScrollCleanup();
}
try { try {
const instance = osInstance(); const instance = osInstance();
const { current: root } = scrollContainerRef; const { current: root } = scrollContainerRef;
@@ -147,14 +152,21 @@ export const useTablePaneSync = ({
const viewport = root.firstElementChild as HTMLElement; const viewport = root.firstElementChild as HTMLElement;
let autoScrollCleanup: (() => void) | null = null;
if (enableDrag) { if (enableDrag) {
autoScrollForElements({ autoScrollCleanup = autoScrollForElements({
canScroll: () => true, canScroll: () => true,
element: viewport, element: viewport,
getAllowedAxis: () => 'vertical', getAllowedAxis: () => 'vertical',
getConfiguration: () => ({ maxScrollSpeed: 'fast' }), getConfiguration: () => ({ maxScrollSpeed: 'fast' }),
}); });
} }
return () => {
if (autoScrollCleanup) {
autoScrollCleanup();
}
};
}, [enableDrag, pinnedLeftColumnCount, pinnedLeftColumnRef]); }, [enableDrag, pinnedLeftColumnCount, pinnedLeftColumnRef]);
// Initialize overlayscrollbars for right pinned columns // Initialize overlayscrollbars for right pinned columns
@@ -176,8 +188,9 @@ export const useTablePaneSync = ({
target: root, target: root,
}); });
let autoScrollCleanup: (() => void) | null = null;
if (enableDrag) { if (enableDrag) {
autoScrollForElements({ autoScrollCleanup = autoScrollForElements({
canScroll: () => true, canScroll: () => true,
element: viewport, element: viewport,
getAllowedAxis: () => 'vertical', getAllowedAxis: () => 'vertical',
@@ -186,6 +199,10 @@ export const useTablePaneSync = ({
} }
return () => { return () => {
if (autoScrollCleanup) {
autoScrollCleanup();
}
try { try {
const instance = osInstanceRightPinned(); const instance = osInstanceRightPinned();
const { current: root } = pinnedRightColumnRef; const { current: root } = pinnedRightColumnRef;