diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 94b537a6f..bff56140b 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -42,11 +42,11 @@ export default class App extends React.Component { private readonly pins: PersistentSet; private readonly sortBy: Persistent>; private readonly connection: Promise; + private cacheTimer: NodeJS.Timeout | null = null; constructor(props: Record) { super(props); - //todo! Check what's important to set to true, false this.settings = new PersistentObject( 'settings', { @@ -84,7 +84,7 @@ export default class App extends React.Component { memory_memcpy_score: true, disk_sequential_write_score: true, disk_random_write_score: true, - is_virtual_machine: false, + is_virtual_machine: false }, (settings) => { const selectedColumns = this.selectedColumns(settings); @@ -138,8 +138,26 @@ export default class App extends React.Component { this.appState, this.appUpdate ); + } + + componentDidMount() { + // Wipe sorted chains cache every 10 seconds + this.cacheTimer = setInterval(() => { + this.chainsCache = []; + }, 10000); + + window.addEventListener('keydown', this.onKeyPress); + window.addEventListener('hashchange', this.onHashChange); + } + + componentWillUnmount() { + if (this.cacheTimer) { + clearInterval(this.cacheTimer); + this.cacheTimer = null; + } - setInterval(() => (this.chainsCache = []), 10000); // Wipe sorted chains cache every 10 seconds + window.removeEventListener('keydown', this.onKeyPress); + window.removeEventListener('hashchange', this.onHashChange); } public render() {