Skip to content

Commit

Permalink
frontend: Make a workaround fix for standing table scrolling issue
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tossy310 committed Dec 19, 2024
1 parent fa74373 commit c8656db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
12 changes: 10 additions & 2 deletions frontend/src/components/common/AnimatingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type AnimatingTableProps = {
type AnimatingTableSnapshot = {
lastKeyOrder: string[];
lastKeyToOffsetTop: Map<string, number>;
// TODO - this is a workaround to fix scrolling position sometimes moves.
scrollPos: number;
};

export default class AnimatingTable extends React.Component<
Expand All @@ -44,7 +46,8 @@ export default class AnimatingTable extends React.Component<
lastKeyOrder.push(row.dataset.key!);
lastKeyToOffsetTop.set(row.dataset.key!, row.offsetTop);
}
return { lastKeyOrder, lastKeyToOffsetTop };
const scrollPos = document.documentElement.scrollTop;
return { lastKeyOrder, lastKeyToOffsetTop, scrollPos };
}

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

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

// TODO - this is a workaround to fix scrolling position sometimes moves.
if (scrollPos) {
document.documentElement.scrollTop = scrollPos;
}

// Cancel all animations.
this.timers.clearTimeouts();
for (const cancel of this.cancels.splice(0)) {
Expand Down
15 changes: 0 additions & 15 deletions frontend/src/components/standings/StandingsRevealPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,11 @@ import React from 'react';
import StandingsRevealTable from './StandingsRevealTable';
import { tr } from '../../i18n';

class ScrollFixer extends React.Component<{}, {}, number> {
getSnapshotBeforeUpdate(): number {
return document.scrollingElement!.scrollTop;
}

componentDidUpdate(prevProps: {}, prevState: {}, snapshot: number) {
document.scrollingElement!.scrollTop = snapshot;
}

render() {
return <></>;
}
}

export default function StandingsRevealPage() {
return (
<div>
<h1 className="my-4">{tr('Standings', '順位表')}</h1>
<StandingsRevealTable />
<ScrollFixer />
</div>
);
}

0 comments on commit c8656db

Please sign in to comment.