From 0f4810d56da37e01cf03a25cef236bceb3bf7a18 Mon Sep 17 00:00:00 2001 From: cgjgh <160297365+cgjgh@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:11:33 -0600 Subject: [PATCH] Ensure app reloads without using cache --- ui/src/main.mjs | 50 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/ui/src/main.mjs b/ui/src/main.mjs index 9a5b4bf4..df0e00c4 100644 --- a/ui/src/main.mjs +++ b/ui/src/main.mjs @@ -275,31 +275,39 @@ fetch('_setup') location.reload() } + // loads minimal VueJS app to display error message and options to user + function loadFallback (error) { + // pass the error to the Vuex store + store.commit('setup/setError', error) + const app = Vue.createApp(App) + .use(store) + .use(vuetify) + .use(router) + + const head = createHead() + app.use(head) + app.mixin(VueHeadMixin) + + // mount the VueJS app into
in /ui/public/index.html + app.mount('#app') + } + let error = {} if (navigator.onLine) { - error = { error: err, type: 'server unreachable', message: 'There was an error loading the Dashboard.' } - // Add timer to reload the page every 20 seconds - setInterval(() => { - location.reload() - }, 20000) + if (err instanceof TypeError && err.message === 'Failed to fetch') { + forcePageReload(err) + } else { + error = { error: err, type: 'server unreachable', message: 'There was an error loading the Dashboard.' } + loadFallback(error) + // Add timer to reload the page every 20 seconds + setInterval(() => { + location.reload() + }, 20000) + } } else { - error = { error: err, type: 'no internet', message: 'Your device appears to be offline.' } // Add event listener window.addEventListener('online', handleOnline) + error = { error: err, type: 'no internet', message: 'Your device appears to be offline.' } + loadFallback(error) } - - store.commit('setup/setError', error) // pass the error to the Vuex store - - // load minimal VueJS app to display error message and options to user - const app = Vue.createApp(App) - .use(store) - .use(vuetify) - .use(router) - - const head = createHead() - app.use(head) - app.mixin(VueHeadMixin) - - // mount the VueJS app into
in /ui/public/index.html - app.mount('#app') })