Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8656db

Browse files
committedDec 19, 2024·
frontend: Make a workaround fix for standing table scrolling issue
There's an issue where a standings table sometimes scrolls up unintentionally on animation. This happens when a pending submit that is visible in a screen is moved up to offscreen by getting AC, then the scroll position is moved to the new location of that team's row. The root cause is unknown yet, and this commit makes a stopgap fix.
1 parent fa74373 commit c8656db

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed
 

‎frontend/src/components/common/AnimatingTable.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type AnimatingTableProps = {
2323
type AnimatingTableSnapshot = {
2424
lastKeyOrder: string[];
2525
lastKeyToOffsetTop: Map<string, number>;
26+
// TODO - this is a workaround to fix scrolling position sometimes moves.
27+
scrollPos: number;
2628
};
2729

2830
export default class AnimatingTable extends React.Component<
@@ -44,7 +46,8 @@ export default class AnimatingTable extends React.Component<
4446
lastKeyOrder.push(row.dataset.key!);
4547
lastKeyToOffsetTop.set(row.dataset.key!, row.offsetTop);
4648
}
47-
return { lastKeyOrder, lastKeyToOffsetTop };
49+
const scrollPos = document.documentElement.scrollTop;
50+
return { lastKeyOrder, lastKeyToOffsetTop, scrollPos };
4851
}
4952

5053
componentDidUpdate(
@@ -53,7 +56,7 @@ export default class AnimatingTable extends React.Component<
5356
snapshot: AnimatingTableSnapshot
5457
) {
5558
const { delay = 1000 } = this.props;
56-
const { lastKeyOrder, lastKeyToOffsetTop } = snapshot;
59+
const { lastKeyOrder, lastKeyToOffsetTop, scrollPos } = snapshot;
5760
const rows = Array.from(this.ref.current!.children) as HTMLElement[];
5861

5962
// Check if the order changed.
@@ -70,6 +73,11 @@ export default class AnimatingTable extends React.Component<
7073
}
7174
}
7275

76+
// TODO - this is a workaround to fix scrolling position sometimes moves.
77+
if (scrollPos) {
78+
document.documentElement.scrollTop = scrollPos;
79+
}
80+
7381
// Cancel all animations.
7482
this.timers.clearTimeouts();
7583
for (const cancel of this.cancels.splice(0)) {

‎frontend/src/components/standings/StandingsRevealPage.tsx

-15
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,11 @@ import React from 'react';
1717
import StandingsRevealTable from './StandingsRevealTable';
1818
import { tr } from '../../i18n';
1919

20-
class ScrollFixer extends React.Component<{}, {}, number> {
21-
getSnapshotBeforeUpdate(): number {
22-
return document.scrollingElement!.scrollTop;
23-
}
24-
25-
componentDidUpdate(prevProps: {}, prevState: {}, snapshot: number) {
26-
document.scrollingElement!.scrollTop = snapshot;
27-
}
28-
29-
render() {
30-
return <></>;
31-
}
32-
}
33-
3420
export default function StandingsRevealPage() {
3521
return (
3622
<div>
3723
<h1 className="my-4">{tr('Standings', '順位表')}</h1>
3824
<StandingsRevealTable />
39-
<ScrollFixer />
4025
</div>
4126
);
4227
}

0 commit comments

Comments
 (0)
Please sign in to comment.