diff --git a/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx b/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx index 419171b301..7983fdd32e 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/FileTree.tsx @@ -25,6 +25,10 @@ type Props = WithTranslation & { match: any; }; +type State = { + stoppableUpdateHandler?: number; +} + const FixedWidthTh = styled.th` width: 16px; `; @@ -41,11 +45,26 @@ export function findParent(path: string) { return ""; } -class FileTree extends React.Component { - componentDidUpdate(prevProps: Readonly, prevState: Readonly<{}>, snapshot?: any): void { - const { tree, updateSources } = this.props; - if (tree?._embedded?.children && tree._embedded.children.find(c => c.partialResult)) { - setTimeout(updateSources, 3000); +class FileTree extends React.Component { + + constructor(props: Props) { + super(props); + this.state = {}; + } + + componentDidUpdate(prevProps: Readonly, prevState: Readonly): void { + if (prevState.stoppableUpdateHandler === this.state.stoppableUpdateHandler) { + const {tree, updateSources} = this.props; + if (tree?._embedded?.children && tree._embedded.children.find(c => c.partialResult)) { + const stoppableUpdateHandler = setTimeout(updateSources, 3000); + this.setState({stoppableUpdateHandler: stoppableUpdateHandler}); + } + } + } + + componentWillUnmount(): void { + if (this.state.stoppableUpdateHandler) { + clearTimeout(this.state.stoppableUpdateHandler); } }