From d4d1b62cd3389cc060dec9654e574c6a90a204b8 Mon Sep 17 00:00:00 2001 From: tiennm Date: Thu, 16 Apr 2026 14:31:28 +0700 Subject: [PATCH 1/2] fix: avoid rendering scrollbar column when table is empty --- src/FixedHolder/index.tsx | 9 +++---- tests/FixedColumn.spec.tsx | 24 +++++++++++++++++++ tests/__snapshots__/FixedColumn.spec.tsx.snap | 10 +++----- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/FixedHolder/index.tsx b/src/FixedHolder/index.tsx index 419637eaa..8c1de0753 100644 --- a/src/FixedHolder/index.tsx +++ b/src/FixedHolder/index.tsx @@ -131,15 +131,16 @@ const FixedHolder = React.forwardRef>((pro className: `${prefixCls}-cell-scrollbar`, }), }; + const shouldAppendScrollBarColumn = combinationScrollBarSize && !noData; const columnsWithScrollbar = useMemo>( - () => (combinationScrollBarSize ? [...columns, ScrollBarColumn] : columns), - [combinationScrollBarSize, columns], + () => (shouldAppendScrollBarColumn ? [...columns, ScrollBarColumn] : columns), + [shouldAppendScrollBarColumn, columns], ); const flattenColumnsWithScrollbar = useMemo( - () => (combinationScrollBarSize ? [...flattenColumns, ScrollBarColumn] : flattenColumns), - [combinationScrollBarSize, flattenColumns], + () => (shouldAppendScrollBarColumn ? [...flattenColumns, ScrollBarColumn] : flattenColumns), + [shouldAppendScrollBarColumn, flattenColumns], ); // Calculate the sticky offsets diff --git a/tests/FixedColumn.spec.tsx b/tests/FixedColumn.spec.tsx index 3e7a5b493..091fd5579 100644 --- a/tests/FixedColumn.spec.tsx +++ b/tests/FixedColumn.spec.tsx @@ -119,6 +119,30 @@ describe('Table.FixedColumn', () => { expect(container.querySelector('colgroup')?.outerHTML).toMatchSnapshot(); }); + + it('does not render scrollbar header cell when data is empty', async () => { + const { container } = render( + , + ); + + await triggerResize(container.querySelector('.rc-table')); + + act(() => { + const coll = container.querySelector('.rc-table-resize-collection'); + if (coll) { + triggerResize(coll as HTMLElement); + } + }); + + await act(async () => { + vi.runAllTimers(); + await Promise.resolve(); + }); + + expect(container.querySelectorAll('thead .rc-table-cell-scrollbar')).toHaveLength(0); + expect(container.querySelector('.rc-table-placeholder')).toBeTruthy(); + vi.useRealTimers(); + }); }); it('has correct scroll classNames when table resize', async () => { diff --git a/tests/__snapshots__/FixedColumn.spec.tsx.snap b/tests/__snapshots__/FixedColumn.spec.tsx.snap index f56c89857..33e78933c 100644 --- a/tests/__snapshots__/FixedColumn.spec.tsx.snap +++ b/tests/__snapshots__/FixedColumn.spec.tsx.snap @@ -2723,14 +2723,14 @@ exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = ` -
title1 renders correctly > scrollXY - without data 1`] = ` title12
From ca3af2edca66b521b95e7b367abfd3b0f6a944ad Mon Sep 17 00:00:00 2001 From: tiennm Date: Thu, 16 Apr 2026 14:39:19 +0700 Subject: [PATCH 2/2] fix: keep header sticky offsets in sync for empty tables --- src/FixedHolder/index.tsx | 5 +++-- tests/__snapshots__/FixedColumn.spec.tsx.snap | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/FixedHolder/index.tsx b/src/FixedHolder/index.tsx index 8c1de0753..cffb145b4 100644 --- a/src/FixedHolder/index.tsx +++ b/src/FixedHolder/index.tsx @@ -146,6 +146,7 @@ const FixedHolder = React.forwardRef>((pro // Calculate the sticky offsets const headerStickyOffsets = useMemo(() => { const { start, end } = stickyOffsets; + const scrollbarOffset = shouldAppendScrollBarColumn ? combinationScrollBarSize : 0; return { ...stickyOffsets, // left: @@ -153,10 +154,10 @@ const FixedHolder = React.forwardRef>((pro // right: // direction === 'rtl' ? right : [...right.map(width => width + combinationScrollBarSize), 0], start: start, - end: [...end.map(width => width + combinationScrollBarSize), 0], + end: [...end.map(width => width + scrollbarOffset), 0], isSticky, }; - }, [combinationScrollBarSize, stickyOffsets, isSticky]); + }, [shouldAppendScrollBarColumn, combinationScrollBarSize, stickyOffsets, isSticky]); const mergedColumnWidth = useColumnWidth(colWidths, columCount); diff --git a/tests/__snapshots__/FixedColumn.spec.tsx.snap b/tests/__snapshots__/FixedColumn.spec.tsx.snap index 33e78933c..85d62a343 100644 --- a/tests/__snapshots__/FixedColumn.spec.tsx.snap +++ b/tests/__snapshots__/FixedColumn.spec.tsx.snap @@ -2796,7 +2796,7 @@ exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = ` title12