diff --git a/ui/src/App.js b/ui/src/App.js index 031153add..5f2791010 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -29,7 +29,7 @@ import { import createAdminStore from './store/createAdminStore' import { i18nProvider } from './i18n' import config from './config' -import { setDispatch, startEventStream } from './eventStream' +import { setDispatch, startEventStream, stopEventStream } from './eventStream' import { keyMap } from './hotkeys' import useChangeThemeColor from './useChangeThemeColor' @@ -70,7 +70,13 @@ const Admin = (props) => { useEffect(() => { if (config.devActivityPanel) { setDispatch(adminStore.dispatch) - authProvider.checkAuth().then(() => startEventStream(adminStore.dispatch)) + authProvider + .checkAuth() + .then(() => startEventStream(adminStore.dispatch)) + .catch(() => {}) + } + return () => { + stopEventStream() } }, []) diff --git a/ui/src/eventStream.js b/ui/src/eventStream.js index 911d5cfbc..43ba7e045 100644 --- a/ui/src/eventStream.js +++ b/ui/src/eventStream.js @@ -31,23 +31,20 @@ const setTimeout = (value) => { window.clearTimeout(timeout) } timeout = window.setTimeout(async () => { - if (es) { - es.close() - } + es?.close() es = null await startEventStream() }, currentIntervalCheck) } const stopEventStream = () => { - if (es) { - es.close() - } + es?.close() es = null if (timeout) { window.clearTimeout(timeout) } timeout = null + console.log('eventSource closed') // TODO For debug purposes. Remove later } const setDispatch = (dispatchFunc) => { @@ -77,6 +74,8 @@ const startEventStream = async () => { newStream.addEventListener('keepAlive', eventHandler) newStream.onerror = (e) => { console.log('EventStream error', e) + es?.close() + es = null setTimeout(reconnectIntervalCheck) dispatch(serverDown()) }