Skip to content

fix: table forceScroll setTimeout issue #1259

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function Table<RecordType extends DefaultRecordType>(

const [setScrollTarget, getScrollTarget] = useTimeoutLock(null);

function forceScroll(scrollLeft: number, target: HTMLDivElement | ((left: number) => void)) {
function forceScroll(scrollLeft: number, target: HTMLDivElement & {_scrollTimeout?: number | null} | ((left: number) => void)) {
if (!target) {
return;
}
Expand All @@ -426,11 +426,17 @@ function Table<RecordType extends DefaultRecordType>(
} else if (target.scrollLeft !== scrollLeft) {
target.scrollLeft = scrollLeft;

if (target._scrollTimeout) {
Copy link
Preview

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the target parameter is a function, accessing the _scrollTimeout property may cause issues since functions do not have this property. Consider adding a type guard to ensure that target is an HTMLDivElement instance before checking _scrollTimeout.

Suggested change
if (target._scrollTimeout) {
if (target instanceof HTMLDivElement && target._scrollTimeout) {

Copilot uses AI. Check for mistakes.

window.clearTimeout(target._scrollTimeout);
target._scrollTimeout = null;
}

// Delay to force scroll position if not sync
// ref: https://github.com/ant-design/ant-design/issues/37179
if (target.scrollLeft !== scrollLeft) {
setTimeout(() => {
target._scrollTimeout = setTimeout(() => {
target.scrollLeft = scrollLeft;
target._scrollTimeout = null;
}, 0);
}
}
Expand Down
Loading