From ca60f2bb0947ae55fc3c37ff2588188a85547d99 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Tue, 31 Aug 2021 17:45:05 +0100 Subject: [PATCH] Store and clear loadConfiguration timeouts - Avoids double loads if switching servers right after a config load has failed --- src/App.vue | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7189e1a..18c6b05 100644 --- a/src/App.vue +++ b/src/App.vue @@ -46,6 +46,8 @@ export default defineComponent({ }, setup() { + let loadingTimeout = 0; + const store = useStore(), title = computed(() => store.getters.pageTitle), currentUrl = computed(() => store.getters.url), @@ -61,6 +63,7 @@ export default defineComponent({ loadConfiguration = async () => { try { + clearTimeout(loadingTimeout); showSplash(); loading.value = true; @@ -95,7 +98,9 @@ export default defineComponent({ const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`; console.error(`${error}:`, e); showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value); - setTimeout(() => loadConfiguration(), 1000); + + clearTimeout(loadingTimeout); + loadingTimeout = setTimeout(() => loadConfiguration(), 1000); } finally { loading.value = false; } @@ -184,7 +189,10 @@ export default defineComponent({ }) onMounted(() => loadConfiguration()); - onBeforeUnmount(() => store.dispatch(ActionTypes.STOP_UPDATES, undefined)); + onBeforeUnmount(() => { + store.dispatch(ActionTypes.STOP_UPDATES, undefined); + clearTimeout(loadingTimeout); + }); handleUrl(); onResize();