Skip to content

fix: optimize and fix the implementation of emptyNode shake #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Body/ExpandedRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ function ExpandedRow(props: ExpandedRowProps) {
className={className}
style={{
display: expanded ? null : 'none',
// fix https://github.com/ant-design/ant-design/issues/49279
visibility: isEmpty && horizonScroll && !componentWidth ? 'hidden' : null,
}}
>
<Cell component={cellComponent} prefixCls={prefixCls} colSpan={colSpan}>
Expand Down
17 changes: 14 additions & 3 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ function Table<RecordType extends DefaultRecordType>(
}
};

const onFullTableResize = ({ width }) => {
const onFullTableResize = (offsetWidth?: number) => {
stickyRef.current?.checkScrollBarVisible();
let mergedWidth = fullTableRef.current ? fullTableRef.current.offsetWidth : width;
let mergedWidth = offsetWidth ?? fullTableRef.current?.offsetWidth ?? 0;
if (useInternalHooks && getContainerWidth && fullTableRef.current) {
mergedWidth = getContainerWidth(fullTableRef.current, mergedWidth) || mergedWidth;
}
Expand All @@ -508,6 +508,13 @@ function Table<RecordType extends DefaultRecordType>(
}
};

// fix https://github.com/ant-design/ant-design/issues/49279
useLayoutEffect(() => {
if (horizonScroll) {
onFullTableResize();
}
}, [horizonScroll]);

// Sync scroll bar when init or `horizonScroll`, `data` and `columns.length` changed
const mounted = React.useRef(false);
React.useEffect(() => {
Expand Down Expand Up @@ -799,7 +806,11 @@ function Table<RecordType extends DefaultRecordType>(
);

if (horizonScroll) {
fullTable = <ResizeObserver onResize={onFullTableResize}>{fullTable}</ResizeObserver>;
fullTable = (
<ResizeObserver onResize={({ offsetWidth }) => onFullTableResize(offsetWidth)}>
{fullTable}
</ResizeObserver>
);
}

const fixedInfoList = useFixedInfo(flattenColumns, stickyOffsets);
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/ExpandRow.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = `
>
<div
class="rc-table-expanded-row-fixed"
style="width: 0px; position: sticky; left: 0px; overflow: hidden;"
style="width: 1128px; position: sticky; left: 0px; overflow: hidden;"
>
<p>
extra data
Expand Down Expand Up @@ -616,7 +616,7 @@ exports[`Table.Expand > renders fixed column correctly > work 1`] = `
>
<div
class="rc-table-expanded-row-fixed"
style="width: 0px; position: sticky; left: 0px; overflow: hidden;"
style="width: 1128px; position: sticky; left: 0px; overflow: hidden;"
>
<p>
extra data
Expand Down
2 changes: 0 additions & 2 deletions tests/__snapshots__/FixedColumn.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,6 @@ exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = `
</tr>
<tr
class="rc-table-placeholder"
style=""
>
<td
class="rc-table-cell"
Expand Down Expand Up @@ -2976,7 +2975,6 @@ exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = `
</tr>
<tr
class="rc-table-placeholder"
style=""
>
<td
class="rc-table-cell"
Expand Down