Skip to content

Commit 3a61bf9

Browse files
committed
fix(AnalyticalTable): prevent stale scrollOffset after filtering
1 parent 0e081b1 commit 3a61bf9

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

packages/main/src/components/AnalyticalTable/AnalyticalTable.cy.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,8 +1610,9 @@ describe('AnalyticalTable', () => {
16101610
});
16111611

16121612
it('first virtual row offset matches scrollTop after loading cycle', () => {
1613-
// Guards the layout-effect in `AnalyticalTable/index.tsx` that re-syncs the virtualizer' cached `scrollOffset` with the DOM after a data swap clamps `scrollTop` (dispatching scroll event).
1613+
// Guards the layout-effect in `AnalyticalTable/index.tsx` that re-syncs the virtualizer's cached `scrollOffset` with the DOM after a data swap clamps `scrollTop` (dispatching a scroll event).
16141614
// Without it, the first row renders at a stale `translateY` and leaves a whitespace gap at the top.
1615+
// `minRows={20}` + a filter result smaller than `minRows` keeps `itemCount = Math.max(minRows, rows.length, ...)` constant across the empty-then-refilled cycle, so the effect can only re-fire via the `rows.length` dep — guarding both deps in one shot.
16151616
const filterData = new Array(500).fill('').map((_, index) => ({ name: `Row-${index}`, age: index }));
16161617
const TestComp = () => {
16171618
const [tableData, setTableData] = useState(filterData);
@@ -1621,7 +1622,7 @@ describe('AnalyticalTable', () => {
16211622
setTableData([]);
16221623
setLoading(true);
16231624
setTimeout(() => {
1624-
setTableData(filterData.filter((item) => item.age >= 100));
1625+
setTableData(filterData.filter((item) => item.age < 5));
16251626
setLoading(false);
16261627
}, 100);
16271628
};
@@ -1636,6 +1637,7 @@ describe('AnalyticalTable', () => {
16361637
loading={loading}
16371638
reactTableOptions={reactTableOptions}
16381639
visibleRows={15}
1640+
minRows={20}
16391641
/>
16401642
</>
16411643
);

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
748748
// Defer to a microtask so the scroll listener's `flushSync(rerender)` doesn't run inside this commit.
749749
queueMicrotask(() => scrollElement.dispatchEvent(new Event('scroll')));
750750
}
751-
}, [itemCount]);
751+
}, [itemCount, rows.length]);
752752

753753
// add range to instance for `useAutoResize` plugin hook
754754
tableInstanceRef.current.virtualRowsRange = rowVirtualizer.range;

0 commit comments

Comments
 (0)