Skip to content

Commit b8c7586

Browse files
committed
fix infinite re renders / unnecessary logic
1 parent 58f13b2 commit b8c7586

File tree

2 files changed

+12
-86
lines changed

2 files changed

+12
-86
lines changed

client/packages/lowcoder/src/comps/comps/tableLiteComp/parts/ResizeableTable.tsx

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ function ResizeableTableComp<RecordType extends object>(
7575

7676
const [resizeData, setResizeData] = useState({ index: -1, width: -1 });
7777
const tableRef = useRef<HTMLDivElement>(null);
78-
const [measuredHeights, setMeasuredHeights] = useState<{
79-
header: number;
80-
summary: number;
81-
bodyContent: number;
82-
}>({ header: 0, summary: 0, bodyContent: 0 });
78+
8379

8480
const handleResize = useCallback((width: number, index: number) => {
8581
setResizeData({ index, width });
@@ -178,30 +174,7 @@ function ResizeableTableComp<RecordType extends object>(
178174
});
179175
}, [columns, resizeData, createCellHandler, createHeaderCellHandler]);
180176

181-
// Measure header, summary & body content heights so we can derive the body viewport height for vertical scrolling
182-
useEffect(() => {
183-
if (!isFixedHeight || !tableRef.current) return;
184-
const tableEl = tableRef.current;
185-
186-
const measure = () => {
187-
const headerH =
188-
(tableEl.querySelector(".ant-table-header") as HTMLElement)
189-
?.clientHeight ?? 0;
190-
const summaryH =
191-
(tableEl.querySelector(".ant-table-summary") as HTMLElement)
192-
?.clientHeight ?? 0;
193-
const bodyContentH =
194-
(tableEl.querySelector(".ant-table-tbody") as HTMLElement)
195-
?.scrollHeight ?? 0;
196-
setMeasuredHeights({ header: headerH, summary: summaryH, bodyContent: bodyContentH });
197-
};
198-
199-
measure();
200-
const resizeObserver = new ResizeObserver(measure);
201-
resizeObserver.observe(tableEl);
202-
203-
return () => resizeObserver.disconnect();
204-
}, [isFixedHeight, dataSource?.length, columns.length]);
177+
205178

206179
// Sum widths (including resized values) to keep horizontal scroll baseline accurate
207180
function getTotalTableWidth(
@@ -222,47 +195,17 @@ function ResizeableTableComp<RecordType extends object>(
222195

223196
const scrollAndVirtualizationSettings = useMemo(() => {
224197
const totalWidth = getTotalTableWidth(memoizedColumns as any, resizeData);
225-
const scrollSettings: { x?: number; y?: number } = { x: totalWidth };
226-
227-
// For fixed height mode, set vertical scroll height (body viewport height)
228-
if (isFixedHeight && containerHeight && containerHeight > 0) {
229-
const availableHeight = Math.max(
230-
containerHeight - measuredHeights.header - measuredHeights.summary,
231-
200
232-
);
233-
234-
// Enable virtualization for fixed height mode with 50+ rows
235-
const shouldUseVirtualization = Boolean(
236-
isFixedHeight &&
237-
containerHeight &&
238-
dataSource?.length &&
239-
dataSource.length >= 50
240-
);
241-
242-
// Only set scroll.y if virtualization is on OR content actually overflows
243-
const contentOverflows = measuredHeights.bodyContent > availableHeight;
244-
if (shouldUseVirtualization || contentOverflows) {
245-
scrollSettings.y = availableHeight;
246-
}
247-
248-
return {
249-
virtual: shouldUseVirtualization,
250-
scroll: scrollSettings,
251-
};
252-
}
253-
198+
const shouldVirtualize = isFixedHeight && (dataSource?.length ?? 0) >= 50;
199+
254200
return {
255-
virtual: false,
256-
scroll: scrollSettings,
201+
virtual: shouldVirtualize,
202+
scroll: {
203+
x: totalWidth,
204+
// FIX: Set y for ANY fixed height mode, not just virtualization
205+
y: isFixedHeight && containerHeight ? containerHeight : undefined
206+
}
257207
};
258-
}, [
259-
isFixedHeight,
260-
containerHeight,
261-
dataSource?.length,
262-
measuredHeights,
263-
memoizedColumns,
264-
resizeData,
265-
]);
208+
}, [isFixedHeight, containerHeight, dataSource?.length, memoizedColumns, resizeData]);
266209

267210
return (
268211
<StyledTableWrapper ref={tableRef}>

client/packages/lowcoder/src/comps/comps/tableLiteComp/tableCompView.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const TableCompView = React.memo((props: {
2121

2222
const compName = useContext(CompNameContext);
2323
const [loading, setLoading] = useState(false);
24-
const tableContainerRef = useRef<HTMLDivElement>(null);
2524
const tableViewportRef = useRef<HTMLDivElement>(null);
2625

2726
const [containerHeight, setContainerHeight] = useState<number>(0);
@@ -53,22 +52,6 @@ export const TableCompView = React.memo((props: {
5352
const isFixedHeight = !compChildren.autoHeight.getView(); // autoHeight: "fixed" when false
5453
const rowAutoHeight = compChildren.rowAutoHeight.getView();
5554

56-
const enableVirtualization = useMemo(() => {
57-
const shouldVirtualize = isFixedHeight && data.length >= 50;
58-
59-
// Debug logging
60-
if (process.env.NODE_ENV === 'development') {
61-
console.log('Table Virtualization Status:', {
62-
shouldVirtualize,
63-
isFixedHeight,
64-
dataLength: data.length,
65-
threshold: 50,
66-
});
67-
}
68-
69-
return shouldVirtualize;
70-
}, [isFixedHeight, data.length]);
71-
7255
// Measure container height for virtualization
7356
useEffect(() => {
7457
if (!isFixedHeight || !tableViewportRef.current) return;
@@ -194,7 +177,7 @@ export const TableCompView = React.memo((props: {
194177
compChildren.loading.getView();
195178

196179
return (
197-
<div ref={tableContainerRef} style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
180+
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
198181
{toolbar.position === "above" && !hideToolbar && toolbarView}
199182
<div ref={tableViewportRef} style={{ flex: 1, minHeight: 0 }}>
200183
<ResizeableTable<any>

0 commit comments

Comments
 (0)